From 9306248902d3423b0f5ab1727eebe25addf0669c Mon Sep 17 00:00:00 2001 From: Matthias Portzel Date: Mon, 16 May 2022 11:28:47 -0700 Subject: [PATCH] Search CSS tweaks * A couple of other minor things --- thoughts/static/thoughts/main.css | 16 +++- thoughts/templates/thoughts/post.html | 1 - .../templates/thoughts/search/search.html | 74 +++++++------------ thoughts/views.py | 21 ++++-- 4 files changed, 56 insertions(+), 56 deletions(-) diff --git a/thoughts/static/thoughts/main.css b/thoughts/static/thoughts/main.css index 4798dd0..40eb4b2 100644 --- a/thoughts/static/thoughts/main.css +++ b/thoughts/static/thoughts/main.css @@ -52,6 +52,9 @@ button, input[type="button"], input[type="submit"], .button { outline: none; font-size: 13px; } +form input[type="submit"] { + font-size: 15px; +} button:hover, button:focus, input[type="button"]:hover, input[type="button"]:focus, input[type="submit"]:hover, input[type="submit"]:focus, @@ -61,8 +64,8 @@ input[type="submit"]:hover, input[type="submit"]:focus, } /* Textbox/textarea styles */ -textarea, input[type="text"], input[type="password"] { - padding: 0 5px; +textarea, input[type="text"], input[type="search"], input[type="password"] { + padding: 0 2px; outline: none; resize: none; background: none; @@ -73,13 +76,20 @@ textarea, input[type="text"], input[type="password"] { border-bottom: 1px solid var(--accent-color); border-radius: 0; overflow-x: hidden; - display: block; + display: inline-block; line-height: 1.5; } textarea::placeholder, input[type="text"]::placeholder { color: var(--text-color); opacity: 50%; } +textarea { + display: block; +} + +form { + margin-bottom: 4em; +} .text, .thought-end { max-width: 100%; diff --git a/thoughts/templates/thoughts/post.html b/thoughts/templates/thoughts/post.html index 2b18754..ed4fb5c 100644 --- a/thoughts/templates/thoughts/post.html +++ b/thoughts/templates/thoughts/post.html @@ -29,7 +29,6 @@ - {{ form.submit }} {% endblock %} diff --git a/thoughts/templates/thoughts/search/search.html b/thoughts/templates/thoughts/search/search.html index aa8d156..2cbe5b1 100644 --- a/thoughts/templates/thoughts/search/search.html +++ b/thoughts/templates/thoughts/search/search.html @@ -10,57 +10,39 @@ {% endblock %} {% block main %} -
- - {{ form.as_table }} - - - - -
  - -
+ + {{ form.q }} - {% if query %} - {% load tz %} + +
-

Results

+ {% if query %} + {% load tz %} - {% for thought in page.object_list %} -
-
- {{ thought.object.text|urlize }} + {% for thought in page.object_list %} +
+
+ {{ thought.object.text|urlize }} - Show -
- -
- - {% timezone thought.object.get_timezone %} - {{ thought.object.posted|time:"g:i a" }} - {{ thought.object.posted|date:"M d, Y" }}, - - UTC{{ thought.object.get_offset_hours }} - {{ thought.object.get_season }} - {% endtimezone %} - -
- -
+ Show
- {% empty %} -

No results found.

- {% endfor %} - - {% else %} - {# Show some example queries to run, maybe query syntax, something else? #} - {% endif %} - + +
+
+ {% empty %} +

No results found.

+ {% endfor %} + {% endif %} {% endblock %} diff --git a/thoughts/views.py b/thoughts/views.py index f5821cf..bdaaf39 100644 --- a/thoughts/views.py +++ b/thoughts/views.py @@ -5,18 +5,18 @@ import base64 import magic +from django import forms from django.shortcuts import render, redirect from django.utils.crypto import constant_time_compare -from whispermaphone import settings -from .models import Thought, ThoughtForm, ALLOWED_MEDIA_TYPES - -from .pagination import get_all_pages, get_page_slug - from haystack.views import SearchView, search_view_factory from haystack.query import SearchQuerySet from haystack.forms import SearchForm +from whispermaphone import settings +from .models import Thought, ThoughtForm, ALLOWED_MEDIA_TYPES +from .pagination import get_all_pages, get_page_slug + def check_authenticated(request): authenticated = False try: @@ -175,9 +175,18 @@ def about(request): "authenticated": check_authenticated(request) }) +class ThoughtsSearchForm(SearchForm): + q = forms.CharField( + required=False, + widget=forms.TextInput(attrs={"type": "search", "placeholder": "Search query"}), + ) + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + search = search_view_factory( template="thoughts/search/search.html", view_class=SearchView, - form_class=SearchForm, + form_class=ThoughtsSearchForm, searchqueryset=SearchQuerySet().order_by("-posted") )