Add (some) missing context for the templates

Also, one mistake
newer-dal
LEdoian 4 years ago
parent 5612f788da
commit ca8b9d1ced

@ -1,4 +1,4 @@
from django.shortcuts import render from django.shortcuts import render, get_object_or_404
import wishlist.models as m import wishlist.models as m
import django.views.generic as dv import django.views.generic as dv
@ -6,6 +6,11 @@ class WishedItemView(dv.DetailView):
model = m.WishedItem model = m.WishedItem
template_name = 'wishlist/item.html' 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): class UserWishLists(dv.ListView):
model = m.WishList model = m.WishList
template_name = 'wishlist/userwishlists.html' template_name = 'wishlist/userwishlists.html'
@ -14,10 +19,21 @@ class UserWishLists(dv.ListView):
qs = super().get_queryset() qs = super().get_queryset()
return qs.filter(owner__login=self.loginname) 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): class WishListView(dv.ListView):
model = m.WishedItem model = m.WishedItem
template_name = 'wishlist/wishlist.html' template_name = 'wishlist/wishlist.html'
def get_queryset(self): def get_queryset(self):
qs = super().get_queryset() 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

Loading…
Cancel
Save