From 39b1cc75e3708b2590d266f6210c8a834842fc5e Mon Sep 17 00:00:00 2001 From: Daoud Clarke Date: Mon, 13 Nov 2023 16:03:26 +0000 Subject: [PATCH] WIP add a history page --- mwmbl/templates/base.html | 105 +++++++++++++++++++++++++++++------ mwmbl/templates/history.html | 11 ++++ mwmbl/templates/home.html | 1 + mwmbl/templates/index.html | 101 ++------------------------------- mwmbl/urls.py | 5 +- mwmbl/views.py | 12 ++++ 6 files changed, 121 insertions(+), 114 deletions(-) create mode 100644 mwmbl/templates/history.html diff --git a/mwmbl/templates/base.html b/mwmbl/templates/base.html index b397195..ff08539 100644 --- a/mwmbl/templates/base.html +++ b/mwmbl/templates/base.html @@ -1,22 +1,95 @@ +{% load django_vite %} - - - {% block title %}Simple is Better Than Complex{% endblock %} - - -
-

My Site

- {% if user.is_authenticated %} - logout + + + + + + + + {% include "title.html" %} + + + + + + + + + + + + + + + + + + + + + + + + + + + {% vite_hmr_client %} + + + + +
+ + mwmbl logo + Mwmbl + + +
+ {% if user.is_authenticated %} + + Log out {% else %} - login / signup + Login + Sign up {% endif %} -
-
- {% block content %} - {% endblock %} -
- + {% block content %} + {% endblock %} + +{% vite_asset 'index.js' %} +{% vite_legacy_polyfills %} +{% vite_legacy_asset 'index-legacy.js' %} + + diff --git a/mwmbl/templates/history.html b/mwmbl/templates/history.html new file mode 100644 index 0000000..6754a9b --- /dev/null +++ b/mwmbl/templates/history.html @@ -0,0 +1,11 @@ +{% extends "base.html" %} +{% load humanize %} + +{% block content %} +
+

Curations for {{ query }}

+ {% for user_curation in curations %} +

{{ user_curation.user.username }} {{ user_curation.curation_type }} {{ user_curation.timestamp | naturaltime}}

+ {% endfor %} +
+{% endblock %} diff --git a/mwmbl/templates/home.html b/mwmbl/templates/home.html index 3620c94..42719c8 100644 --- a/mwmbl/templates/home.html +++ b/mwmbl/templates/home.html @@ -3,6 +3,7 @@
{% if query %} +{# View history#} {% if results %}
    {% for result in results %} diff --git a/mwmbl/templates/index.html b/mwmbl/templates/index.html index c2da955..dd4d011 100644 --- a/mwmbl/templates/index.html +++ b/mwmbl/templates/index.html @@ -1,97 +1,6 @@ -{% load django_vite %} - - +{% extends "base.html" %} - - - - - - - {% include "title.html" %} - - - - - - - - - - - - - - - - - - - - - - - - - - - {% vite_hmr_client %} - - - - -
    - - mwmbl logo - Mwmbl - - -
    - {% if user.is_authenticated %} - - Log out - {% else %} - Login - Sign up - {% endif %} -
    -
    - {% include "home.html" %} -
    -
    - -{% vite_asset 'index.js' %} -{% vite_legacy_polyfills %} -{% vite_legacy_asset 'index-legacy.js' %} - - - \ No newline at end of file +{% block content %} + {% include "home.html" %} +
    +{% endblock %} diff --git a/mwmbl/urls.py b/mwmbl/urls.py index 776361a..8e61be2 100644 --- a/mwmbl/urls.py +++ b/mwmbl/urls.py @@ -18,7 +18,7 @@ from django.contrib import admin from django.urls import path, include from mwmbl.api import api_v1 -from mwmbl.views import home_fragment, fetch_url, index +from mwmbl.views import home_fragment, fetch_url, index, page_history urlpatterns = [ path('admin/', admin.site.urls), @@ -27,5 +27,6 @@ urlpatterns = [ path('', index, name="home"), path('app/home/', home_fragment, name="home"), - path('app/fetch/', fetch_url, name="fetch_url") + path('app/fetch/', fetch_url, name="fetch_url"), + path('app/history/', page_history, name="history"), ] diff --git a/mwmbl/views.py b/mwmbl/views.py index 3d59498..2b6893d 100644 --- a/mwmbl/views.py +++ b/mwmbl/views.py @@ -127,3 +127,15 @@ def fetch_url(request): return render(request, "result.html", { "result": format_result(result, query), }) + + +def page_history(request): + url = request.GET["url"] + parsed_url_query = parse_qs(urlparse(url).query) + query = parsed_url_query.get("q", [""])[0] + curations = UserCuration.objects.filter(url=url).order_by("-timestamp") + return render(request, "history.html", { + "curations": curations, + "url": url, + "query": query, + })