fixes
authorRadek Czajka <rczajka@rczajka.pl>
Mon, 12 Jun 2023 08:45:45 +0000 (10:45 +0200)
committerRadek Czajka <rczajka@rczajka.pl>
Mon, 12 Jun 2023 08:45:45 +0000 (10:45 +0200)
src/catalogue/views.py
src/references/urls.py
src/references/views.py
src/search/views.py

index bb5d43f..d563b68 100644 (file)
@@ -269,7 +269,12 @@ class TaggedObjectList(BookList):
         self.ctx['fragment_tags'] = [t for t in self.ctx['tags'] if t.category in ('theme', 'object')]
         self.ctx['work_tags'] = [t for t in self.ctx['tags'] if t not in self.ctx['fragment_tags']]
         self.is_themed = self.ctx['has_theme'] = bool(self.ctx['fragment_tags'])
-        self.ctx['main_tag'] = self.ctx['fragment_tags'][0] if self.is_themed else self.ctx['tags'][0]
+        if self.is_themed:
+            self.ctx['main_tag'] = self.ctx['fragment_tags'][0]
+        elif self.ctx['tags']:
+            self.ctx['main_tag'] = self.ctx['tags'][0]
+        else:
+            self.ctx['main_tag'] = None
         self.ctx['filtering_tags'] = [
             t for t in self.ctx['tags']
             if t is not self.ctx['main_tag']
@@ -439,6 +444,8 @@ def analyse_tags(request, tag_str):
         raise ResponseInstead(HttpResponsePermanentRedirect(
             reverse('tagged_object_list', args=['/'.join(tag.url_chunk for tag in e.tags)])))
 
+    if not tags:
+        raise Http404
     try:
         if len(tags) > settings.MAX_TAG_LIST:
             raise Http404
index bc6c104..1c0e46c 100644 (file)
@@ -1,8 +1,9 @@
-from django.urls import path
+from django.urls import path, re_path
 from . import views
 
 
 urlpatterns = [
-    path('mapa/', views.map),
+    path('mapa/', views.pin_map),
+    re_path(r'^mapa/(?P<tags>[a-zA-Z0-9-/]*)/$', views.pin_map_tagged),
     path('popup/<int:pk>', views.popup),
 ]
index 773a37d..a098c1a 100644 (file)
@@ -1,14 +1,32 @@
-from django.views.decorators.cache import never_cache
+from django.http import Http404
 from django.shortcuts import render, get_object_or_404
+from django.views.decorators.cache import never_cache
+from catalogue.models import Book
+from catalogue.views import analyse_tags
 from . import models
 
 
-def map(request):
+def pin_map(request):
     return render(request, 'references/map.html', {
         'entities': models.Entity.objects.exclude(lat=None).exclude(lon=None),
         'funding_no_show_current': True,
     })
 
+def pin_map_tagged(request, tags):
+    try:
+        tags = analyse_tags(request, tags)
+    except:
+        raise #Http404()
+
+    books = Book.tagged.with_all(tags)
+
+    return render(request, 'references/map.html', {
+        'entities': models.Entity.objects.exclude(lat=None).exclude(lon=None).filter(reference__book__in=books).distinct(),
+        'funding_no_show_current': True,
+    })
+
+
+
 @never_cache
 def popup(request, pk):
     e = get_object_or_404(models.Entity, pk=pk)
index 9e36458..b5cc0ba 100644 (file)
@@ -123,7 +123,7 @@ def search(request):
     filters = SearchFilters(request.GET)
     ctx = {
         'title': 'Wynik wyszukiwania',
-        'query': filters.data['q'],
+        'query': request.GET.get('q', ''),
         'filters': filters,
     }
     if filters.is_valid():