-
-
Notifications
You must be signed in to change notification settings - Fork 992
/
Copy pathviews.py
57 lines (37 loc) · 1.27 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from django.views.generic.dates import (
ArchiveIndexView,
DateDetailView,
DayArchiveView,
MonthArchiveView,
YearArchiveView,
)
from .models import Entry, Event
class BlogViewMixin:
date_field = "pub_date"
paginate_by = 10
def get_allow_future(self):
return self.request.user.is_staff
def get_queryset(self):
return Entry.objects.published()
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
events_queryset = Event.objects.future().published()
context["events"] = events_queryset[:3]
return context
class BlogArchiveIndexView(BlogViewMixin, ArchiveIndexView):
pass
class BlogYearArchiveView(BlogViewMixin, YearArchiveView):
make_object_list = True
class BlogMonthArchiveView(BlogViewMixin, MonthArchiveView):
pass
class BlogDayArchiveView(BlogViewMixin, DayArchiveView):
pass
class BlogDateDetailView(BlogViewMixin, DateDetailView):
def get_queryset(self):
"""Allows staff users to view unpublished entries"""
if self.request.user.is_staff:
print("\n\nSTAFF USER\n\n")
return Entry.objects.all()
else:
print("\n\nNORMAL USER\n\n")
return Entry.objects.published()