Ticket #1071: patch-django-views-generic_login-required_#1071

File patch-django-views-generic_login-required_#1071, 7.0 KB (added by trbs, 18 years ago)
Line 
1Index: django/views/generic/date_based.py
2===================================================================
3--- django/views/generic/date_based.py (revision 3354)
4+++ django/views/generic/date_based.py (working copy)
5@@ -1,11 +1,12 @@
6 from django.template import loader, RequestContext
7+from django.contrib.auth.views import redirect_to_login
8 from django.core.exceptions import ObjectDoesNotExist
9 from django.core.xheaders import populate_xheaders
10 from django.http import Http404, HttpResponse
11 import datetime, time
12
13 def archive_index(request, queryset, date_field, num_latest=15,
14- template_name=None, template_loader=loader,
15+ template_name=None, template_loader=loader, login_required=False,
16 extra_context=None, allow_empty=False, context_processors=None,
17 mimetype=None):
18 """
19@@ -19,6 +20,9 @@
20 Latest N (defaults to 15) objects by date
21 """
22 if extra_context is None: extra_context = {}
23+ if login_required and request.user.is_anonymous():
24+ return redirect_to_login(request)
25+
26 model = queryset.model
27 queryset = queryset.filter(**{'%s__lte' % date_field: datetime.datetime.now()})
28 date_list = queryset.dates(date_field, 'year')[::-1]
29@@ -46,8 +50,8 @@
30
31 def archive_year(request, year, queryset, date_field, template_name=None,
32 template_loader=loader, extra_context=None, allow_empty=False,
33- context_processors=None, template_object_name='object', mimetype=None,
34- make_object_list=False):
35+ login_required=False, context_processors=None, template_object_name='object',
36+ mimetype=None, make_object_list=False):
37 """
38 Generic yearly archive view.
39
40@@ -62,6 +66,9 @@
41 (Only available if make_object_list argument is True)
42 """
43 if extra_context is None: extra_context = {}
44+ if login_required and request.user.is_anonymous():
45+ return redirect_to_login(request)
46+
47 model = queryset.model
48 now = datetime.datetime.now()
49
50@@ -94,8 +101,8 @@
51
52 def archive_month(request, year, month, queryset, date_field,
53 month_format='%b', template_name=None, template_loader=loader,
54- extra_context=None, allow_empty=False, context_processors=None,
55- template_object_name='object', mimetype=None):
56+ extra_context=None, allow_empty=False, login_required=False,
57+ context_processors=None, template_object_name='object', mimetype=None):
58 """
59 Generic monthly archive view.
60
61@@ -111,6 +118,9 @@
62 list of objects published in the given month
63 """
64 if extra_context is None: extra_context = {}
65+ if login_required and request.user.is_anonymous():
66+ return redirect_to_login(request)
67+
68 try:
69 date = datetime.date(*time.strptime(year+month, '%Y'+month_format)[:3])
70 except ValueError:
71@@ -151,8 +161,8 @@
72
73 def archive_week(request, year, week, queryset, date_field,
74 template_name=None, template_loader=loader,
75- extra_context=None, allow_empty=True, context_processors=None,
76- template_object_name='object', mimetype=None):
77+ extra_context=None, allow_empty=True, login_required=False,
78+ context_processors=None, template_object_name='object', mimetype=None):
79 """
80 Generic weekly archive view.
81
82@@ -164,6 +174,9 @@
83 list of objects published in the given week
84 """
85 if extra_context is None: extra_context = {}
86+ if login_required and request.user.is_anonymous():
87+ return redirect_to_login(request)
88+
89 try:
90 date = datetime.date(*time.strptime(year+'-0-'+week, '%Y-%w-%U')[:3])
91 except ValueError:
92@@ -200,8 +213,8 @@
93 def archive_day(request, year, month, day, queryset, date_field,
94 month_format='%b', day_format='%d', template_name=None,
95 template_loader=loader, extra_context=None, allow_empty=False,
96- context_processors=None, template_object_name='object',
97- mimetype=None):
98+ login_required=False, context_processors=None,
99+ template_object_name='object', mimetype=None):
100 """
101 Generic daily archive view.
102
103@@ -217,6 +230,9 @@
104 (datetime) the next day, or None if the current day is today
105 """
106 if extra_context is None: extra_context = {}
107+ if login_required and request.user.is_anonymous():
108+ return redirect_to_login(request)
109+
110 try:
111 date = datetime.date(*time.strptime(year+month+day, '%Y'+month_format+day_format)[:3])
112 except ValueError:
113@@ -267,7 +283,7 @@
114 month_format='%b', day_format='%d', object_id=None, slug=None,
115 slug_field=None, template_name=None, template_name_field=None,
116 template_loader=loader, extra_context=None, context_processors=None,
117- template_object_name='object', mimetype=None):
118+ login_required=False, template_object_name='object', mimetype=None):
119 """
120 Generic detail view from year/month/day/slug or year/month/day/id structure.
121
122@@ -277,6 +293,9 @@
123 the object to be detailed
124 """
125 if extra_context is None: extra_context = {}
126+ if login_required and request.user.is_anonymous():
127+ return redirect_to_login(request)
128+
129 try:
130 date = datetime.date(*time.strptime(year+month+day, '%Y'+month_format+day_format)[:3])
131 except ValueError:
132Index: django/views/generic/list_detail.py
133===================================================================
134--- django/views/generic/list_detail.py (revision 3354)
135+++ django/views/generic/list_detail.py (working copy)
136@@ -1,13 +1,14 @@
137 from django.template import loader, RequestContext
138 from django.http import Http404, HttpResponse
139+from django.contrib.auth.views import redirect_to_login
140 from django.core.xheaders import populate_xheaders
141 from django.core.paginator import ObjectPaginator, InvalidPage
142 from django.core.exceptions import ObjectDoesNotExist
143
144 def object_list(request, queryset, paginate_by=None, page=None,
145 allow_empty=False, template_name=None, template_loader=loader,
146- extra_context=None, context_processors=None, template_object_name='object',
147- mimetype=None):
148+ extra_context=None, login_required=False, context_processors=None,
149+ template_object_name='object', mimetype=None):
150 """
151 Generic list of objects.
152
153@@ -35,6 +36,9 @@
154 number of objects, total
155 """
156 if extra_context is None: extra_context = {}
157+ if login_required and request.user.is_anonymous():
158+ return redirect_to_login(request)
159+
160 queryset = queryset._clone()
161 if paginate_by:
162 paginator = ObjectPaginator(queryset, paginate_by)
163@@ -80,7 +84,7 @@
164
165 def object_detail(request, queryset, object_id=None, slug=None,
166 slug_field=None, template_name=None, template_name_field=None,
167- template_loader=loader, extra_context=None,
168+ template_loader=loader, extra_context=None, login_required=False,
169 context_processors=None, template_object_name='object',
170 mimetype=None):
171 """
172@@ -92,6 +96,9 @@
173 the object
174 """
175 if extra_context is None: extra_context = {}
176+ if login_required and request.user.is_anonymous():
177+ return redirect_to_login(request)
178+
179 model = queryset.model
180 if object_id:
181 queryset = queryset.filter(pk=object_id)
Back to Top