From ca8b9d1ced330fbb4505deb008066b63a3b3d412 Mon Sep 17 00:00:00 2001 From: Pavel 'LEdoian' Turinsky Date: Tue, 16 Feb 2021 04:56:14 +0100 Subject: [PATCH] Add (some) missing context for the templates Also, one mistake --- wishlist/views.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/wishlist/views.py b/wishlist/views.py index c82c833..861ba1e 100644 --- a/wishlist/views.py +++ b/wishlist/views.py @@ -1,4 +1,4 @@ -from django.shortcuts import render +from django.shortcuts import render, get_object_or_404 import wishlist.models as m import django.views.generic as dv @@ -6,6 +6,11 @@ class WishedItemView(dv.DetailView): model = m.WishedItem template_name = 'wishlist/item.html' + def get_context_data(self, **kwargs): + ctx = super().get_context_data(**kwargs) + ctx['page_title'] = f"Item: {ctx['object']}" + return ctx + class UserWishLists(dv.ListView): model = m.WishList template_name = 'wishlist/userwishlists.html' @@ -14,10 +19,21 @@ class UserWishLists(dv.ListView): qs = super().get_queryset() return qs.filter(owner__login=self.loginname) + def get_context_data(self, **kwargs): + ctx = super().get_context_data(**kwargs) + ctx['page_title'] = f"{ctx['object']}'s wishlists" + return ctx + class WishListView(dv.ListView): model = m.WishedItem template_name = 'wishlist/wishlist.html' def get_queryset(self): qs = super().get_queryset() - return qs.filter(wishlists__slug__in=[self.slug]) + return qs.filter(wishlists__slug__in=[self.kwargs["slug"]]) + + def get_context_data(self, **kwargs): + ctx = super().get_context_data(**kwargs) + ctx['page_title'] = f"Wishlist: {ctx['object']}" + ctx['wishlist'] = get_object_or_404(m.Wishlist, slug=self.kwargs['slug']) + return ctx