From 776712e1288138f546d105ab621523a2c632638a Mon Sep 17 00:00:00 2001 From: luxagraf Date: Fri, 15 Jan 2021 16:36:00 -0500 Subject: proj: updated several views to use utils.LuxDetailView This allows for a single breadcrumbs template, consolidating code --- app/locations/views.py | 1 - app/lttr/views.py | 4 ++++ app/posts/views/guide_views.py | 7 +++++-- app/posts/views/src_views.py | 4 ++-- app/sightings/views.py | 7 ++++--- app/utils/views.py | 25 ++++++++++++++++++------- 6 files changed, 33 insertions(+), 15 deletions(-) (limited to 'app') diff --git a/app/locations/views.py b/app/locations/views.py index e5d580b..9638b96 100644 --- a/app/locations/views.py +++ b/app/locations/views.py @@ -86,7 +86,6 @@ def map_data(request): class LocationDetail(DetailView): model = Location - template_name = "details/location.html" def get_context_data(self, **kwargs): context = super(LocationDetail, self).get_context_data(**kwargs) diff --git a/app/lttr/views.py b/app/lttr/views.py index 58bfb65..6b8c60a 100644 --- a/app/lttr/views.py +++ b/app/lttr/views.py @@ -50,6 +50,10 @@ class NewsletterListView(ListView): queryset = super(NewsletterListView, self).get_queryset() return queryset.filter(newsletter__slug=self.kwargs['slug']) + def get_context_data(self, **kwargs): + context = super(NewsletterListView, self).get_context_data(**kwargs) + context['breadcrumbs'] = [self.kwargs['slug'],] + return context class NewsletterOptionsView(ListView): model = Newsletter diff --git a/app/posts/views/guide_views.py b/app/posts/views/guide_views.py index d9503db..5b15af1 100644 --- a/app/posts/views/guide_views.py +++ b/app/posts/views/guide_views.py @@ -21,22 +21,25 @@ class GuideListView(PaginatedListView): queryset = super(GuideListView, self).get_queryset() return queryset.filter(status__exact=1).filter(post_type__in=[PostType.REVIEW,PostType.FIELD_TEST]).order_by('-pub_date').prefetch_related('location').prefetch_related('featured_image') -class GuideTopicListView(GuideListView): + +class GuideTopicListView(PaginatedListView): """ Return a list of Posts by topic in reverse chronological order """ + model = Post template_name = "posts/guide_by_topic.html" def get_queryset(self): queryset = super(GuideTopicListView, self).get_queryset() topic = Category.objects.get(slug=self.kwargs['topic']) - return queryset.filter(status__exact=1).filter(topics__slug=topic).order_by('-pub_date').prefetch_related('featured_image') + return queryset.filter(status__exact=1).filter(topics__slug=topic.slug).order_by('-pub_date').prefetch_related('featured_image') def get_context_data(self, **kwargs): context = super(GuideTopicListView, self).get_context_data(**kwargs) context['topic'] = Category.objects.get(slug=self.kwargs['topic']) return context + class ReviewsListView(GuideListView): template_name = "posts/post.html" diff --git a/app/posts/views/src_views.py b/app/posts/views/src_views.py index 90c672c..c56b723 100644 --- a/app/posts/views/src_views.py +++ b/app/posts/views/src_views.py @@ -6,7 +6,7 @@ from django.urls import reverse from django.conf import settings #from paypal.standard.forms import PayPalPaymentsForm -from utils.views import PaginatedListView +from utils.views import PaginatedListView, LuxDetailView from ..models import Post, PostType from taxonomy.models import Category @@ -27,7 +27,7 @@ class SrcListView(PaginatedListView): return context -class SrcDetailView(DetailView): +class SrcDetailView(LuxDetailView): model = Post slug_field = "slug" template_name="posts/src_detail.html" diff --git a/app/sightings/views.py b/app/sightings/views.py index 3170b77..0c1f296 100644 --- a/app/sightings/views.py +++ b/app/sightings/views.py @@ -1,16 +1,17 @@ from django.views.generic.detail import DetailView from django.views.generic import ListView from django.contrib.auth.models import User -from utils.views import PaginatedListView +from utils.views import PaginatedListView,LuxDetailView from .models import AP, Sighting, FieldNote class SightingListView(PaginatedListView): + model = Sighting def get_queryset(self): qs_ids = Sighting.objects.order_by('ap__id', '-pub_date').distinct('ap').values_list('id', flat=True) return Sighting.objects.filter(id__in=qs_ids).order_by('-pub_date').prefetch_related('ap') - + class LifeListView(ListView): template_name = 'archives/life-list.html' @@ -34,7 +35,7 @@ class SightingListUserView(PaginatedListView): return context -class SightingDetailView(DetailView): +class SightingDetailView(LuxDetailView): model = AP def get_context_data(self, **kwargs): diff --git a/app/utils/views.py b/app/utils/views.py index 71163ce..f1e947a 100644 --- a/app/utils/views.py +++ b/app/utils/views.py @@ -13,10 +13,12 @@ from recordings.models import Audio BREADCRUMBS = { 'SrcPost':'SRC', + 'AP':'dialogue', 'Book':'Book Notes', 'Entry':'Jrnl', 'NewsletterMailing':'lttr', - 'LuxImage':'lttr' + 'LuxImage':'lttr', + 'Sighting':'dialogue' } class PaginatedListView(ListView): @@ -62,10 +64,13 @@ class LuxDetailView(DetailView): context = super(LuxDetailView, self).get_context_data(**kwargs) print(self.object._meta.verbose_name_plural) try: - context['breadcrumbs'] = (BREADCRUMBS[self.object._meta.model],) + context['breadcrumbs'] = (BREADCRUMBS[self.object._meta.label.split(".")[1]],) except KeyError: if self.object._meta.verbose_name_plural == 'posts': - context['breadcrumbs'] = (self.object.get_post_type_display()+"s",) + if self.object.get_post_type_display() != 'src': + context['breadcrumbs'] = (self.object.get_post_type_display()+"s",) + else: + context['breadcrumbs'] = (self.object.get_post_type_display(),) context['crumb_url'] = "/%ss/" % self.object.get_post_type_display() else: context['breadcrumbs'] = (self.object._meta.verbose_name_plural,) @@ -73,11 +78,17 @@ class LuxDetailView(DetailView): context['crumb_url'] except KeyError: try: - context['crumb_url'] = reverse('%s:list' % self.object._meta.verbose_name_plural.slugify()) + context['crumb_url'] = reverse('%s:list' % slugify(self.object._meta.verbose_name_plural)) except: - # special case for pages: - context['breadcrumbs'] = (self.object.title,) - context['crumb_url'] = None + # special case for books: + if self.object._meta.verbose_name_plural == 'books': + context['crumb_url'] = reverse('books:list') + elif self.object._meta.verbose_name_plural == 'Animal/Plant': + context['crumb_url'] = reverse('sightings:list') + else: + # special case for pages: + context['breadcrumbs'] = (self.object.title,) + context['crumb_url'] = None return context -- cgit v1.2.3-70-g09d2