-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
active search from 3 january #90
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,9 +71,33 @@ | |
|
||
<form class="form-inline" action="/search/" method="post" itemprop="potentialAction" itemscope itemtype="https://schema.org/SearchAction"> | ||
{% csrf_token %} | ||
<div role="search" class="mr-2"> | ||
<div id="search" role="search" class="mr-2"> | ||
<meta itemprop="target" content="{% site_url %}/search/?text={search_term}"/> | ||
<input class="form-control" autofocus type="search" aria-label="Search" name="text" placeholder="Поиск по справочнику" value="{{ search_term }}" required itemprop="query-input"> | ||
<label for="tags"> | ||
<input | ||
id='tags' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tags здесь точно ни при чем, лучше search. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. В атрибутах используй везде двойные кавычки, чтобы не было разнобоя. |
||
class="form-control" | ||
autofocus type="search" | ||
aria-label="Search" | ||
name="text" | ||
placeholder="Поиск по справочнику" | ||
value="{{ search_term }}" | ||
required itemprop="query-input" | ||
hx-post="search/" | ||
hx-trigger="keyup changed delay:500ms" | ||
hx-target="#active_search_results" | ||
hx-indicator=".htmx-indicator"> | ||
</label> | ||
</div> | ||
<div id="active_search_results" class="mr-2" style="position: absolute; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Стили лучше не зашивать в элементы, а прописать в css-файл. Раз у нас уже используется css-каркас Bootstrap, то можно использовать инструменты оттуда — это чаще проще и красивее, чем изобретение своих. В частности сейчас элемент с результатами выглядит малопривлекательно. |
||
width: auto; | ||
height: auto; | ||
top: 40px; | ||
z-index:999999; | ||
background-color: whitesmoke; | ||
display: block; | ||
"> | ||
|
||
</div> | ||
</form> | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{% for item in results %} | ||
<div> | ||
<a href="{{ item.get_absolute_url }}">{{ item.title }}</a> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Название может быть на столько длинное, что раздвинет блок с вариантами за края страницы. |
||
</div> | ||
{% endfor %} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,12 +4,28 @@ | |
from django.http import HttpResponse | ||
from django.shortcuts import redirect | ||
from django.shortcuts import render | ||
from siteajax.decorators import ajax_dispatch | ||
from siteajax.utils import AjaxResponse | ||
|
||
from ..generics.views import HttpRequest | ||
from ..models import Reference, ReferenceMissing, Category, Person, App | ||
from ..utils import message_warning, search_models | ||
|
||
def suggest(request): | ||
search_term, results = search_models( | ||
request.POST.get('text', ''), search_in=( | ||
Category, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Если будет много результатов, то это будет выглядеть так себе. |
||
Person, | ||
Reference, | ||
App, | ||
)) | ||
if len(results) > 5: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Сначала выбрать из БД все результаты, а потом их усечь — не очень удачное идея. Лучше вовсе не выбирать из БД лишнее. |
||
results = results[:5] | ||
return render(request, 'static/suggest_results.html', {'results': results}) | ||
|
||
@ajax_dispatch({ | ||
'tags': suggest | ||
}) | ||
def search(request: HttpRequest) -> HttpResponse: | ||
"""Страница с результатами поиска по справочнику. | ||
Если найден один результат, перенаправляет на страницу результата. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
|
||
from .apps.realms import bootstrap_realms | ||
from .apps.views import page_not_found, permission_denied, server_error, index, search, login, telebot, user_settings | ||
from .apps.views.search import suggest | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Этот импорт не используется и здесь не нужен. |
||
|
||
urls_password_reset = [ | ||
path('password_reset/', PasswordResetView.as_view(), name='password_reset'), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
А для чего тут id? Он где-то используется?