From 6263e65bb97f46c5ed4ef3a9179a08568632f6a8 Mon Sep 17 00:00:00 2001 From: Daoud Clarke Date: Wed, 8 Nov 2023 08:56:58 +0000 Subject: [PATCH] Fix title on deleting query --- mwmbl/templates/home.html | 33 ++++++++++++++++++++++++++++----- mwmbl/templates/index.html | 11 +++-------- mwmbl/templates/results.html | 28 ---------------------------- mwmbl/templates/title.html | 6 ++++++ mwmbl/urls.py | 6 +++--- mwmbl/views.py | 8 ++++---- 6 files changed, 44 insertions(+), 48 deletions(-) delete mode 100644 mwmbl/templates/results.html create mode 100644 mwmbl/templates/title.html diff --git a/mwmbl/templates/home.html b/mwmbl/templates/home.html index ed59579..a11b249 100644 --- a/mwmbl/templates/home.html +++ b/mwmbl/templates/home.html @@ -1,5 +1,28 @@ -{% extends 'base.html' %} - -{% block content %} -

Welcome, {{ user.username }}!

-{% endblock %} +{% load result_filters %} +{% include "title.html" %} +{% if results %} + {% for result in results %} +
  • + +
  • + {% endfor %} +{% else %} +
  • +

    + Welcome to Mwmbl, the free, open-source and non-profit search engine. +

    +
  • +{% endif %} diff --git a/mwmbl/templates/index.html b/mwmbl/templates/index.html index c7b35e8..9aa3b57 100644 --- a/mwmbl/templates/index.html +++ b/mwmbl/templates/index.html @@ -8,12 +8,7 @@ - - {% if query %} - Mwmbl - {{ query }} - {% else %} - Mwmbl - Search - {% endif %} + {% include "title.html" %} @@ -69,7 +64,7 @@ placeholder='Search on Mwmbl...' title='Use "CTRL+K" or "/" to focus.' autocomplete='off' - hx-get="/app/search/" + hx-get="/app/home/" hx-trigger="keyup changed delay:100ms" hx-target=".results" > @@ -86,7 +81,7 @@
      - {% include "results.html" %} + {% include "home.html" %}
    diff --git a/mwmbl/templates/results.html b/mwmbl/templates/results.html deleted file mode 100644 index 9150247..0000000 --- a/mwmbl/templates/results.html +++ /dev/null @@ -1,28 +0,0 @@ -{% load result_filters %} -Mwmbl - {{ query }} -{% if results %} - {% for result in results %} -
  • - -
  • - {% endfor %} -{% else %} -
  • -

    - Welcome to Mwmbl, the free, open-source and non-profit search engine. -

    -
  • -{% endif %} diff --git a/mwmbl/templates/title.html b/mwmbl/templates/title.html new file mode 100644 index 0000000..f02b0e5 --- /dev/null +++ b/mwmbl/templates/title.html @@ -0,0 +1,6 @@ + + {% if query %} + Mwmbl - {{ query }} + {% else %} + Mwmbl - Search + {% endif %} diff --git a/mwmbl/urls.py b/mwmbl/urls.py index 2d3de15..776361a 100644 --- a/mwmbl/urls.py +++ b/mwmbl/urls.py @@ -18,14 +18,14 @@ from django.contrib import admin from django.urls import path, include from mwmbl.api import api_v1 -from mwmbl.views import search_results, fetch_url, home +from mwmbl.views import home_fragment, fetch_url, index urlpatterns = [ path('admin/', admin.site.urls), path('api/v1/', api_v1.urls), path('accounts/', include('allauth.urls')), - path('', home, name="home"), - path('app/search/', search_results, name="search_results"), + path('', index, name="home"), + path('app/home/', home_fragment, name="home"), path('app/fetch/', fetch_url, name="fetch_url") ] diff --git a/mwmbl/views.py b/mwmbl/views.py index 97ff64a..6139441 100644 --- a/mwmbl/views.py +++ b/mwmbl/views.py @@ -41,7 +41,7 @@ def justext_with_dom(html_text, stoplist, length_low=LENGTH_LOW_DEFAULT, return paragraphs, title -def home(request): +def index(request): query = request.GET.get("q") results = ranker.search(query) if query else None return render(request, "index.html", { @@ -51,10 +51,10 @@ def home(request): }) -def search_results(request): +def home_fragment(request): query = request.GET["q"] results = ranker.search(query) - response = render(request, "results.html", {"results": results, "query": query}) + response = render(request, "home.html", {"results": results, "query": query}) current_url = request.htmx.current_url # Replace query string with new query stripped_url = current_url[:current_url.index("?")] if "?" in current_url else current_url @@ -77,7 +77,7 @@ def fetch_url(request): extract = extract[:NUM_EXTRACT_CHARS - 1] + '…' result = Document(title=title, url=url, extract=extract, score=0.0) - return render(request, "results.html", { + return render(request, "home.html", { "results": [format_result(result, query)], "query": query, })