Ticket #1229: date_based.diff
File date_based.diff, 2.4 KB (added by , 19 years ago) |
---|
-
date_based.py
48 48 49 49 def archive_year(request, year, model, date_field, 50 50 template_name=None, template_loader=loader, extra_lookup_kwargs={}, 51 extra_context={}, context_processors=None):51 extra_context={}, allow_empty=False, context_processors=None): 52 52 """ 53 53 Generic yearly archive view. 54 54 … … 66 66 lookup_kwargs['%s__lte' % date_field] = now 67 67 lookup_kwargs.update(extra_lookup_kwargs) 68 68 date_list = getattr(model._default_manager, "get_%s_list" % date_field)('month', **lookup_kwargs) 69 if not date_list :70 raise Http404 69 if not date_list and not allow_empty: 70 raise Http404, "No %s available" % model._meta.verbose_name 71 71 if not template_name: 72 72 template_name = "%s/%s_archive_year" % (model._meta.app_label, model._meta.object_name.lower()) 73 73 t = template_loader.get_template(template_name) … … 84 84 85 85 def archive_month(request, year, month, model, date_field, 86 86 month_format='%b', template_name=None, template_loader=loader, 87 extra_lookup_kwargs={}, extra_context={}, context_processors=None): 87 extra_lookup_kwargs={}, extra_context={}, allow_empty=False, 88 context_processors=None): 88 89 """ 89 90 Generic monthly archive view. 90 91 … … 113 114 lookup_kwargs['%s__lte' % date_field] = now 114 115 lookup_kwargs.update(extra_lookup_kwargs) 115 116 object_list = model._default_manager.get_list(**lookup_kwargs) 116 if not object_list :117 raise Http404 117 if not object_list and not allow_empty: 118 raise Http404, "No %s available" % model._meta.verbose_name 118 119 if not template_name: 119 120 template_name = "%s/%s_archive_month" % (model._meta.app_label, model._meta.object_name.lower()) 120 121 t = template_loader.get_template(template_name) … … 162 163 lookup_kwargs.update(extra_lookup_kwargs) 163 164 object_list = model._default_manager.get_list(**lookup_kwargs) 164 165 if not allow_empty and not object_list: 165 raise Http404 166 raise Http404, "No %s available" % model._meta.verbose_name 166 167 if not template_name: 167 168 template_name = "%s/%s_archive_day" % (model._meta.app_label, model._meta.object_name.lower()) 168 169 t = template_loader.get_template(template_name)