From d3345dc67f87d23cff48068f41102f20db10fbf0 Mon Sep 17 00:00:00 2001 From: Matthias Portzel Date: Tue, 3 May 2022 13:31:01 -0400 Subject: [PATCH] Move search templates --- thoughts/search_indexes.py | 2 +- .../templates/thoughts}/search/search.html | 0 .../templates/thoughts/search}/thought_text.txt | 0 thoughts/views.py | 11 +++++++++++ whispermaphone/urls.py | 10 +--------- 5 files changed, 13 insertions(+), 10 deletions(-) rename {templates => thoughts/templates/thoughts}/search/search.html (100%) rename {templates/search/indexes/thoughts => thoughts/templates/thoughts/search}/thought_text.txt (100%) diff --git a/thoughts/search_indexes.py b/thoughts/search_indexes.py index 0ebc932..e9f8516 100644 --- a/thoughts/search_indexes.py +++ b/thoughts/search_indexes.py @@ -2,7 +2,7 @@ from haystack import indexes from .models import Thought class ThoughtIndex(indexes.SearchIndex, indexes.Indexable): - text = indexes.CharField(document=True, use_template=True, template_name="search/indexes/thoughts/thought_text.txt") + text = indexes.CharField(document=True, use_template=True, template_name="thoughts/search/thought_text.txt") posted = indexes.DateTimeField(model_attr="posted") def get_model(self): diff --git a/templates/search/search.html b/thoughts/templates/thoughts/search/search.html similarity index 100% rename from templates/search/search.html rename to thoughts/templates/thoughts/search/search.html diff --git a/templates/search/indexes/thoughts/thought_text.txt b/thoughts/templates/thoughts/search/thought_text.txt similarity index 100% rename from templates/search/indexes/thoughts/thought_text.txt rename to thoughts/templates/thoughts/search/thought_text.txt diff --git a/thoughts/views.py b/thoughts/views.py index fd70361..5f1de0f 100644 --- a/thoughts/views.py +++ b/thoughts/views.py @@ -13,6 +13,10 @@ 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 + def check_authenticated(request): authenticated = False try: @@ -166,3 +170,10 @@ def about(request): return render(request, "thoughts/about.html", { "authenticated": check_authenticated(request) }) + +search = search_view_factory( + template="thoughts/search/search.html", + view_class=SearchView, + form_class=SearchForm, + searchqueryset=SearchQuerySet().order_by("-posted") +) diff --git a/whispermaphone/urls.py b/whispermaphone/urls.py index abb1a6c..515c843 100644 --- a/whispermaphone/urls.py +++ b/whispermaphone/urls.py @@ -5,19 +5,11 @@ from thoughts import views from thoughts.feed import MainFeed from whispermaphone import settings -from haystack.views import SearchView, search_view_factory -from haystack.query import SearchQuerySet -from haystack.forms import SearchForm - urlpatterns = [ path("", views.index, name="index"), path("about", views.about, name="about"), path("login", views.login, name="login"), path("post", views.post, name="post"), path("feed", MainFeed()), - path("search", search_view_factory( - view_class=SearchView, - form_class=SearchForm, - searchqueryset=SearchQuerySet().order_by("-posted") - ), name="thoughts_search") + path("search", views.search, name="thoughts_search") ] + (static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) if settings.DEBUG else [])