add ugly search form in base template

This commit is contained in:
MassiveAtoms 2020-07-15 10:42:49 -03:00
parent dc1571bcfb
commit d57f677bd3
6 changed files with 24 additions and 2 deletions

View File

@ -7,6 +7,7 @@ class SearchForm(forms.Form):
title = forms.CharField(label="Title", max_length=200)
author = forms.CharField(label='Author', max_length=100)
identifier = forms.CharField(label='Identifier(ISBN, Google-id, amazon id)', max_length=20)
generic = forms.CharField(label='All', max_length=100, required=False)

View File

@ -58,7 +58,6 @@
</ul>
<ul class="left">
<li><a href="{% url 'search' %}">Search</a></li>
<li><a href="{% url 'books' %}">Books</a></li>
<li><a class="dropdown-trigger" href="#!" data-target="dropdown-authors">Authors<i
class="material-icons right">arrow_drop_down</i></a></li>
@ -66,6 +65,18 @@
class="material-icons right">arrow_drop_down</i></a></li>
<li><a class="dropdown-trigger" href="#!" data-target="dropdown-tags">Tags<i
class="material-icons right">arrow_drop_down</i></a></li>
<li><a href="{% url 'search' %}">Advanced search</a></li>
<li>
<!-- stefan, this div. can we have this int the navbar? -->
<div class="container">
<form action="{% url 'results' %}" method="get" style="padding-top:2em">
<label for="generic"></label>
<input id="generic" type="text" name="generic" value="">
<button class="waves-effect waves-light btn green accent-4" type="submit">search</button>
</form>
</div>
<!-- this is the end of the div, stefan -->
</li>
</ul>
<ul id="dropdown-authors" class="dropdown-content">
{% for author in unique_authors %}
@ -89,6 +100,8 @@
</ul>
{% endif %}
</div>
</nav>
</div>
<script>

View File

@ -41,13 +41,20 @@ class ResultsView(generic.ListView): # no clue if this is secure.
title = self.request.GET.get('title')
author = self.request.GET.get('author')
identifier = self.request.GET.get("identifier")
generic = self.request.GET.get("generic")
books = Book.objects.prefetch_related("tags", "ratings")
if title:
books =books.filter(sort__icontains=title)
books = books.filter(sort__icontains=title)
if author:
books = books.filter(author_sort__icontains=author)
if identifier:
books = books.filter(identifier__val=identifier)
if generic:
books = books.filter(
Q(sort__icontains=generic) |
Q(author_sort__icontains=generic) |
Q(identifier__val=generic)
)
return books
@ -57,6 +64,7 @@ class AuthorListView(generic.ListView):
class BookListView(generic.ListView):
model = Book
def get_queryset(self):
# Annotate the books with ratings, tags, etc
# books = Book.objects.annotate(