An open source, non-profit web search engine
Show activity list when there are no queries
Daoud Clarkedc2bd082cf51
diff --git a/mwmbl/settings_common.py b/mwmbl/settings_common.pyindex 38a890e..223330e 100644--- a/mwmbl/settings_common.py+++ b/mwmbl/settings_common.py@@ -29,6 +29,7 @@ INSTALLED_APPS = ['django.contrib.sessions','django.contrib.messages','django.contrib.staticfiles',+ 'django.contrib.humanize','mwmbl','django_htmx','django_vite',diff --git a/mwmbl/templates/home.html b/mwmbl/templates/home.htmlindex c78d05b..b15e047 100644--- a/mwmbl/templates/home.html+++ b/mwmbl/templates/home.html@@ -1,4 +1,5 @@{% load result_filters %}+{% load humanize %}{% include "title.html" %}{% if query %}{% if results %}@@ -28,9 +29,11 @@</li>{% endif %}{% else %}- <li class="home">- <h1>- Welcome to Mwmbl, the free, open-source and non-profit search engine.- </h1>- </li>+ {% for item in activity %}+ <li class="activity">+ <h1>+ {{ item.user }} made {{ item.num_curations | apnumber }} changes to <a href="{{ item.url }}">{{ item.query }}</a> {{ item.timestamp | naturaltime }}.+ </h1>+ </li>+ {% endfor %}{% endif %}diff --git a/mwmbl/views.py b/mwmbl/views.pyindex 6139441..f555b95 100644--- a/mwmbl/views.py+++ b/mwmbl/views.py@@ -1,3 +1,8 @@+from dataclasses import dataclass+from datetime import datetime+from itertools import groupby+from urllib.parse import urlparse, parse_qs+import justextimport requestsfrom django.contrib.auth.decorators import login_required@@ -5,6 +10,7 @@ from django.shortcuts import renderfrom django_htmx.http import push_urlfrom mwmbl.format import format_result+from mwmbl.models import UserCuration, MwmblUserfrom mwmbl.search_setup import rankerfrom justext.core import html_to_dom, ParagraphMaker, classify_paragraphs, revise_paragraph_classification, \@@ -42,19 +48,22 @@ def justext_with_dom(html_text, stoplist, length_low=LENGTH_LOW_DEFAULT,def index(request):- query = request.GET.get("q")- results = ranker.search(query) if query else None+ activity, query, results = _get_results_and_activity(request)return render(request, "index.html", {"results": results,"query": query,"user": request.user,+ "activity": activity,})def home_fragment(request):- query = request.GET["q"]- results = ranker.search(query)- response = render(request, "home.html", {"results": results, "query": query})+ activity, query, results = _get_results_and_activity(request)+ response = render(request, "home.html", {+ "results": results,+ "query": query,+ "activity": activity,+ })current_url = request.htmx.current_url# Replace query string with new querystripped_url = current_url[:current_url.index("?")] if "?" in current_url else current_url@@ -65,6 +74,42 @@ def home_fragment(request):return response+@dataclass+class Activity:+ user: MwmblUser+ num_curations: int+ timestamp: datetime+ query: str+ url: str+++def _get_results_and_activity(request):+ query = request.GET.get("q")+ if query:+ results = ranker.search(query)+ activity = None+ else:+ results = None+ curations = UserCuration.objects.order_by("-timestamp")[:100]+ sorted_curations = sorted(curations, key=lambda x: x.user.username)+ groups = groupby(sorted_curations, key=lambda x: (x.user.username, x.url))+ activity = []+ for (user, url), group in groups:+ parsed_url_query = parse_qs(urlparse(url).query)+ activity_query = parsed_url_query.get("q", [""])[0]+ group = list(group)+ activity.append(Activity(+ user=user,+ num_curations=len(group),+ timestamp=max([i.timestamp for i in group]),+ query=activity_query,+ url=url,+ ))++ print("Activity", activity)+ return activity, query, results++def fetch_url(request):url = request.GET["url"]query = request.GET["query"]