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

File patch-django-views-generic_login-required_#1071_2, 7.2 KB (added by root.lastnode@…, 18 years ago)

update to revision 3490

Line 
1Index: django/views/generic/date_based.py
2===================================================================
3--- django/views/generic/date_based.py (revision 3490)
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, allow_future=False):
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 if not allow_future:
28 queryset = queryset.filter(**{'%s__lte' % date_field: datetime.datetime.now()})
29@@ -47,6 +51,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+ login_required=False, context_processors=None, template_object_name='object',
34+ mimetype=None, make_object_list=False, allow_future=False):
35 context_processors=None, template_object_name='object', mimetype=None,
36 make_object_list=False, allow_future=False):
37 """
38@@ -63,6 +69,9 @@
39 (Only available if make_object_list argument is True)
40 """
41 if extra_context is None: extra_context = {}
42+ if login_required and request.user.is_anonymous():
43+ return redirect_to_login(request)
44+
45 model = queryset.model
46 now = datetime.datetime.now()
47
48@@ -95,8 +104,9 @@
49
50 def archive_month(request, year, month, queryset, date_field,
51 month_format='%b', template_name=None, template_loader=loader,
52- extra_context=None, allow_empty=False, context_processors=None,
53- template_object_name='object', mimetype=None, allow_future=False):
54+ extra_context=None, allow_empty=False, login_required=False,
55+ context_processors=None, template_object_name='object', mimetype=None,
56+ allow_future=False):
57 """
58 Generic monthly archive view.
59
60@@ -112,6 +122,9 @@
61 list of objects published in the given month
62 """
63 if extra_context is None: extra_context = {}
64+ if login_required and request.user.is_anonymous():
65+ return redirect_to_login(request)
66+
67 try:
68 date = datetime.date(*time.strptime(year+month, '%Y'+month_format)[:3])
69 except ValueError:
70@@ -161,8 +174,9 @@
71
72 def archive_week(request, year, week, queryset, date_field,
73 template_name=None, template_loader=loader,
74- extra_context=None, allow_empty=True, context_processors=None,
75- template_object_name='object', mimetype=None, allow_future=False):
76+ extra_context=None, allow_empty=True, login_required=False,
77+ context_processors=None, template_object_name='object', mimetype=None,
78+ allow_future=False):
79 """
80 Generic weekly archive view.
81
82@@ -174,6 +188,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@@ -210,8 +227,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, allow_future=False):
98+ login_required=False, context_processors=None,
99+ template_object_name='object', mimetype=None, allow_future=False):
100 """
101 Generic daily archive view.
102
103@@ -227,6 +244,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@@ -286,7 +306,8 @@
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, allow_future=False):
118+ login_required=False, template_object_name='object', mimetype=None,
119+ allow_future=False):
120 """
121 Generic detail view from year/month/day/slug or year/month/day/id structure.
122
123@@ -296,6 +317,9 @@
124 the object to be detailed
125 """
126 if extra_context is None: extra_context = {}
127+ if login_required and request.user.is_anonymous():
128+ return redirect_to_login(request)
129+
130 try:
131 date = datetime.date(*time.strptime(year+month+day, '%Y'+month_format+day_format)[:3])
132 except ValueError:
133Index: django/views/generic/list_detail.py
134===================================================================
135--- django/views/generic/list_detail.py (revision 3490)
136+++ django/views/generic/list_detail.py (working copy)
137@@ -1,13 +1,14 @@
138 from django.template import loader, RequestContext
139 from django.http import Http404, HttpResponse
140+from django.contrib.auth.views import redirect_to_login
141 from django.core.xheaders import populate_xheaders
142 from django.core.paginator import ObjectPaginator, InvalidPage
143 from django.core.exceptions import ObjectDoesNotExist
144
145 def object_list(request, queryset, paginate_by=None, page=None,
146 allow_empty=False, template_name=None, template_loader=loader,
147- extra_context=None, context_processors=None, template_object_name='object',
148- mimetype=None):
149+ extra_context=None, login_required=False, context_processors=None,
150+ template_object_name='object', mimetype=None):
151 """
152 Generic list of objects.
153
154@@ -35,6 +36,9 @@
155 number of objects, total
156 """
157 if extra_context is None: extra_context = {}
158+ if login_required and request.user.is_anonymous():
159+ return redirect_to_login(request)
160+
161 queryset = queryset._clone()
162 if paginate_by:
163 paginator = ObjectPaginator(queryset, paginate_by)
164@@ -80,7 +84,7 @@
165
166 def object_detail(request, queryset, object_id=None, slug=None,
167 slug_field=None, template_name=None, template_name_field=None,
168- template_loader=loader, extra_context=None,
169+ template_loader=loader, extra_context=None, login_required=False,
170 context_processors=None, template_object_name='object',
171 mimetype=None):
172 """
173@@ -92,6 +96,9 @@
174 the object
175 """
176 if extra_context is None: extra_context = {}
177+ if login_required and request.user.is_anonymous():
178+ return redirect_to_login(request)
179+
180 model = queryset.model
181 if object_id:
182 queryset = queryset.filter(pk=object_id)
Back to Top