Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #1229 -- Added allow_empty argument to archive_year and archive…

…_month date-based generic views

git-svn-id: http://code.djangoproject.com/svn/django/trunk@2337 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 73ddfd8bd2b0703573072809aa977d5ca335d101 1 parent e029c9f
Adrian Holovaty authored February 18, 2006
9  django/views/generic/date_based.py
@@ -51,7 +51,7 @@ def archive_index(request, app_label, module_name, date_field, num_latest=15,
51 51
 
52 52
 def archive_year(request, year, app_label, module_name, date_field,
53 53
         template_name=None, template_loader=loader, extra_lookup_kwargs={},
54  
-        extra_context={}, context_processors=None):
  54
+        extra_context={}, allow_empty=False, context_processors=None):
55 55
     """
56 56
     Generic yearly archive view.
57 57
 
@@ -70,7 +70,7 @@ def archive_year(request, year, app_label, module_name, date_field,
70 70
         lookup_kwargs['%s__lte' % date_field] = now
71 71
     lookup_kwargs.update(extra_lookup_kwargs)
72 72
     date_list = getattr(mod, "get_%s_list" % date_field)('month', **lookup_kwargs)
73  
-    if not date_list:
  73
+    if not date_list and not allow_empty:
74 74
         raise Http404
75 75
     if not template_name:
76 76
         template_name = "%s/%s_archive_year" % (app_label, module_name)
@@ -88,7 +88,8 @@ def archive_year(request, year, app_label, module_name, date_field,
88 88
 
89 89
 def archive_month(request, year, month, app_label, module_name, date_field,
90 90
         month_format='%b', template_name=None, template_loader=loader,
91  
-        extra_lookup_kwargs={}, extra_context={}, context_processors=None):
  91
+        extra_lookup_kwargs={}, extra_context={}, allow_empty=False,
  92
+        context_processors=None):
92 93
     """
93 94
     Generic monthly archive view.
94 95
 
@@ -122,7 +123,7 @@ def archive_month(request, year, month, app_label, module_name, date_field,
122 123
         lookup_kwargs['%s__lte' % date_field] = now
123 124
     lookup_kwargs.update(extra_lookup_kwargs)
124 125
     object_list = mod.get_list(**lookup_kwargs)
125  
-    if not object_list:
  126
+    if not object_list and not allow_empty:
126 127
         raise Http404
127 128
     if not template_name:
128 129
         template_name = "%s/%s_archive_month" % (app_label, module_name)
6  docs/generic_views.txt
@@ -168,6 +168,9 @@ The date-based generic functions are:
168 168
     Yearly archive. Requires that the ``year`` argument be present in the URL
169 169
     pattern.
170 170
 
  171
+    **New in Django development version:** Takes an optional ``allow_empty``
  172
+    parameter, as ``archive_index``.
  173
+
171 174
     Uses the template ``app_label/module_name_archive_year`` by default.
172 175
 
173 176
     Has the following template context:
@@ -187,6 +190,9 @@ The date-based generic functions are:
187 190
     default, which is a three-letter month abbreviation. To change it to use
188 191
     numbers, use ``"%m"``.
189 192
 
  193
+    **New in Django development version:** Takes an optional ``allow_empty``
  194
+    parameter, as ``archive_index``.
  195
+
190 196
     Uses the template ``app_label/module_name_archive_month`` by default.
191 197
 
192 198
     Has the following template context:

0 notes on commit 73ddfd8

Please sign in to comment.
Something went wrong with that request. Please try again.