From: Radek Czajka Date: Mon, 12 Jun 2023 08:45:45 +0000 (+0200) Subject: fixes X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/eaba19e725b49fdf4efc858604a7b9d70d27f59f?ds=inline fixes --- diff --git a/src/catalogue/views.py b/src/catalogue/views.py index bb5d43ff0..d563b68a6 100644 --- a/src/catalogue/views.py +++ b/src/catalogue/views.py @@ -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 diff --git a/src/references/urls.py b/src/references/urls.py index bc6c10499..1c0e46c48 100644 --- a/src/references/urls.py +++ b/src/references/urls.py @@ -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[a-zA-Z0-9-/]*)/$', views.pin_map_tagged), path('popup/', views.popup), ] diff --git a/src/references/views.py b/src/references/views.py index 773a37d1c..a098c1abf 100644 --- a/src/references/views.py +++ b/src/references/views.py @@ -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) diff --git a/src/search/views.py b/src/search/views.py index 9e3645858..b5cc0baa3 100644 --- a/src/search/views.py +++ b/src/search/views.py @@ -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():