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']
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
-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),
]
-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)
filters = SearchFilters(request.GET)
ctx = {
'title': 'Wynik wyszukiwania',
- 'query': filters.data['q'],
+ 'query': request.GET.get('q', ''),
'filters': filters,
}
if filters.is_valid():