Ticket #1071: patch-django-views-generic_login-required_#1071_2.diff
File patch-django-views-generic_login-required_#1071_2.diff, 7.2 KB (added by , 18 years ago) |
---|
-
django/views/generic/date_based.py
1 1 from django.template import loader, RequestContext 2 from django.contrib.auth.views import redirect_to_login 2 3 from django.core.exceptions import ObjectDoesNotExist 3 4 from django.core.xheaders import populate_xheaders 4 5 from django.http import Http404, HttpResponse 5 6 import datetime, time 6 7 7 8 def archive_index(request, queryset, date_field, num_latest=15, 8 template_name=None, template_loader=loader, 9 template_name=None, template_loader=loader, login_required=False, 9 10 extra_context=None, allow_empty=False, context_processors=None, 10 11 mimetype=None, allow_future=False): 11 12 """ … … 19 20 Latest N (defaults to 15) objects by date 20 21 """ 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 22 26 model = queryset.model 23 27 if not allow_future: 24 28 queryset = queryset.filter(**{'%s__lte' % date_field: datetime.datetime.now()}) … … 47 51 48 52 def archive_year(request, year, queryset, date_field, template_name=None, 49 53 template_loader=loader, extra_context=None, allow_empty=False, 54 login_required=False, context_processors=None, template_object_name='object', 55 mimetype=None, make_object_list=False, allow_future=False): 50 56 context_processors=None, template_object_name='object', mimetype=None, 51 57 make_object_list=False, allow_future=False): 52 58 """ … … 63 69 (Only available if make_object_list argument is True) 64 70 """ 65 71 if extra_context is None: extra_context = {} 72 if login_required and request.user.is_anonymous(): 73 return redirect_to_login(request) 74 66 75 model = queryset.model 67 76 now = datetime.datetime.now() 68 77 … … 95 104 96 105 def archive_month(request, year, month, queryset, date_field, 97 106 month_format='%b', template_name=None, template_loader=loader, 98 extra_context=None, allow_empty=False, context_processors=None, 99 template_object_name='object', mimetype=None, allow_future=False): 107 extra_context=None, allow_empty=False, login_required=False, 108 context_processors=None, template_object_name='object', mimetype=None, 109 allow_future=False): 100 110 """ 101 111 Generic monthly archive view. 102 112 … … 112 122 list of objects published in the given month 113 123 """ 114 124 if extra_context is None: extra_context = {} 125 if login_required and request.user.is_anonymous(): 126 return redirect_to_login(request) 127 115 128 try: 116 129 date = datetime.date(*time.strptime(year+month, '%Y'+month_format)[:3]) 117 130 except ValueError: … … 161 174 162 175 def archive_week(request, year, week, queryset, date_field, 163 176 template_name=None, template_loader=loader, 164 extra_context=None, allow_empty=True, context_processors=None, 165 template_object_name='object', mimetype=None, allow_future=False): 177 extra_context=None, allow_empty=True, login_required=False, 178 context_processors=None, template_object_name='object', mimetype=None, 179 allow_future=False): 166 180 """ 167 181 Generic weekly archive view. 168 182 … … 174 188 list of objects published in the given week 175 189 """ 176 190 if extra_context is None: extra_context = {} 191 if login_required and request.user.is_anonymous(): 192 return redirect_to_login(request) 193 177 194 try: 178 195 date = datetime.date(*time.strptime(year+'-0-'+week, '%Y-%w-%U')[:3]) 179 196 except ValueError: … … 210 227 def archive_day(request, year, month, day, queryset, date_field, 211 228 month_format='%b', day_format='%d', template_name=None, 212 229 template_loader=loader, extra_context=None, allow_empty=False, 213 context_processors=None, template_object_name='object',214 230 login_required=False, context_processors=None, 231 template_object_name='object', mimetype=None, allow_future=False): 215 232 """ 216 233 Generic daily archive view. 217 234 … … 227 244 (datetime) the next day, or None if the current day is today 228 245 """ 229 246 if extra_context is None: extra_context = {} 247 if login_required and request.user.is_anonymous(): 248 return redirect_to_login(request) 249 230 250 try: 231 251 date = datetime.date(*time.strptime(year+month+day, '%Y'+month_format+day_format)[:3]) 232 252 except ValueError: … … 286 306 month_format='%b', day_format='%d', object_id=None, slug=None, 287 307 slug_field=None, template_name=None, template_name_field=None, 288 308 template_loader=loader, extra_context=None, context_processors=None, 289 template_object_name='object', mimetype=None, allow_future=False): 309 login_required=False, template_object_name='object', mimetype=None, 310 allow_future=False): 290 311 """ 291 312 Generic detail view from year/month/day/slug or year/month/day/id structure. 292 313 … … 296 317 the object to be detailed 297 318 """ 298 319 if extra_context is None: extra_context = {} 320 if login_required and request.user.is_anonymous(): 321 return redirect_to_login(request) 322 299 323 try: 300 324 date = datetime.date(*time.strptime(year+month+day, '%Y'+month_format+day_format)[:3]) 301 325 except ValueError: -
django/views/generic/list_detail.py
1 1 from django.template import loader, RequestContext 2 2 from django.http import Http404, HttpResponse 3 from django.contrib.auth.views import redirect_to_login 3 4 from django.core.xheaders import populate_xheaders 4 5 from django.core.paginator import ObjectPaginator, InvalidPage 5 6 from django.core.exceptions import ObjectDoesNotExist 6 7 7 8 def object_list(request, queryset, paginate_by=None, page=None, 8 9 allow_empty=False, template_name=None, template_loader=loader, 9 extra_context=None, context_processors=None, template_object_name='object',10 10 extra_context=None, login_required=False, context_processors=None, 11 template_object_name='object', mimetype=None): 11 12 """ 12 13 Generic list of objects. 13 14 … … 35 36 number of objects, total 36 37 """ 37 38 if extra_context is None: extra_context = {} 39 if login_required and request.user.is_anonymous(): 40 return redirect_to_login(request) 41 38 42 queryset = queryset._clone() 39 43 if paginate_by: 40 44 paginator = ObjectPaginator(queryset, paginate_by) … … 80 84 81 85 def object_detail(request, queryset, object_id=None, slug=None, 82 86 slug_field=None, template_name=None, template_name_field=None, 83 template_loader=loader, extra_context=None, 87 template_loader=loader, extra_context=None, login_required=False, 84 88 context_processors=None, template_object_name='object', 85 89 mimetype=None): 86 90 """ … … 92 96 the object 93 97 """ 94 98 if extra_context is None: extra_context = {} 99 if login_required and request.user.is_anonymous(): 100 return redirect_to_login(request) 101 95 102 model = queryset.model 96 103 if object_id: 97 104 queryset = queryset.filter(pk=object_id)