Django

Code

Changeset 1510

Show
Ignore:
Timestamp:
11/30/05 16:03:50 (3 years ago)
Author:
adrian
Message:

Added allow_empty hook to archive_index date-based generic view.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/views/generic/date_based.py

    r734 r1510  
    99def archive_index(request, app_label, module_name, date_field, num_latest=15, 
    1010                  template_name=None, template_loader=template_loader, 
    11                   extra_lookup_kwargs={}, extra_context={}): 
     11                  extra_lookup_kwargs={}, extra_context={}, allow_empty=False): 
    1212    """ 
    1313    Generic top-level archive of date-based objects. 
     
    2424    lookup_kwargs.update(extra_lookup_kwargs) 
    2525    date_list = getattr(mod, "get_%s_list" % date_field)('year', **lookup_kwargs)[::-1] 
    26     if not date_list
     26    if not date_list and not allow_empty
    2727        raise Http404("No %s.%s available" % (app_label, module_name)) 
    2828 
    29     if num_latest: 
     29    if date_list and num_latest: 
    3030        lookup_kwargs.update({ 
    3131            'limit': num_latest, 
     
    141141def archive_day(request, year, month, day, app_label, module_name, date_field, 
    142142                month_format='%b', day_format='%d', template_name=None, 
    143                 template_loader=template_loader, extra_lookup_kwargs={},  
     143                template_loader=template_loader, extra_lookup_kwargs={}, 
    144144                extra_context={}, allow_empty=False): 
    145145    """ 
     
    205205                  month_format='%b', day_format='%d', object_id=None, slug=None, 
    206206                  slug_field=None, template_name=None, template_name_field=None, 
    207                   template_loader=template_loader, extra_lookup_kwargs={},  
     207                  template_loader=template_loader, extra_lookup_kwargs={}, 
    208208                  extra_context={}): 
    209209    """ 
  • django/trunk/docs/generic_views.txt

    r1256 r1510  
    136136 
    137137``archive_index`` 
    138     A top-level index page showing the "latest" objects. Has an optional 
    139     argument, ``num_latest``, which is the number of items to display on the 
    140     page (defaults to 15). 
     138    A top-level index page showing the "latest" objects. 
     139 
     140    Takes the following optional arguments: 
     141 
     142        =======================  ================================================= 
     143        Argument                 Description 
     144        =======================  ================================================= 
     145        ``num_latest``           The number of items to display on the page. 
     146                                 Defaults to 15. 
     147 
     148        ``allow_empty``          **New in Django development version.** 
     149                                 If ``False`` and there are no objects to display, 
     150                                 the view will raise a 404 instead of displaying 
     151                                 an empty index page. ``False`` is default. 
     152        =======================  ================================================= 
    141153 
    142154    Uses the template ``app_label/module_name_archive`` by default.