diff options
| author | Adrian Holovaty <adrian@holovaty.com> | 2005-09-02 22:54:12 +0000 |
|---|---|---|
| committer | Adrian Holovaty <adrian@holovaty.com> | 2005-09-02 22:54:12 +0000 |
| commit | 66d4db7b098e157bb1c9ecc82000c90f9d2571a8 (patch) | |
| tree | d8b5d07032941ee3d355fe470606b3d71216d35e | |
| parent | 5c22b8b4b78a9d99505495aa0abe7ffa91f6d108 (diff) | |
Fixed #351 -- views.generic.list_detail.object_list now respects allow_empty when paginating. Thanks, kmh
git-svn-id: http://code.djangoproject.com/svn/django/trunk@618 bcc190cf-cafb-0310-a4f2-bffc1f526a37
| -rw-r--r-- | django/views/generic/list_detail.py | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/django/views/generic/list_detail.py b/django/views/generic/list_detail.py index 7a780d3b1e..373aef3e18 100644 --- a/django/views/generic/list_detail.py +++ b/django/views/generic/list_detail.py @@ -40,12 +40,15 @@ def object_list(request, app_label, module_name, paginate_by=None, allow_empty=F try: object_list = paginator.get_page(page) except InvalidPage: - raise Http404 + if page == 0 and allow_empty: + object_list = [] + else: + raise Http404 page = int(page) c = Context(request, { 'object_list': object_list, - 'is_paginated' : True, - 'results_per_page' : paginate_by, + 'is_paginated': True, + 'results_per_page': paginate_by, 'has_next': paginator.has_next_page(page), 'has_previous': paginator.has_previous_page(page), 'page': page + 1, @@ -56,11 +59,11 @@ def object_list(request, app_label, module_name, paginate_by=None, allow_empty=F else: object_list = mod.get_list(**lookup_kwargs) c = Context(request, { - 'object_list' : object_list, - 'is_paginated' : False + 'object_list': object_list, + 'is_paginated': False }) - if len(object_list) == 0 and not allow_empty: - raise Http404 + if len(object_list) == 0 and not allow_empty: + raise Http404 for key, value in extra_context.items(): if callable(value): c[key] = value() @@ -103,7 +106,7 @@ def object_detail(request, app_label, module_name, object_id=None, slug=None, else: t = template_loader.get_template(template_name) c = Context(request, { - 'object' : object, + 'object': object, }) for key, value in extra_context.items(): if callable(value): |
