Ticket #3168: object_list_accept_list.diff

File object_list_accept_list.diff, 2.7 KB (added by Grimboy, 18 years ago)

Using documentation conventions.

  • django/views/generic/list_detail.py

     
    11from django.template import loader, RequestContext
    22from django.http import Http404, HttpResponse
     3from django.db.models.query import QuerySet
    34from django.core.xheaders import populate_xheaders
    45from django.core.paginator import ObjectPaginator, InvalidPage
    56from django.core.exceptions import ObjectDoesNotExist
     
    1112    """
    1213    Generic list of objects.
    1314
    14     Templates: ``<app_label>/<model_name>_list.html``
     15    Templates: ``<app_label>/<model_name>_list.html`` if queryset is a QuerySet
    1516    Context:
    1617        object_list
    1718            list of objects
     
    3435        hits
    3536            number of objects, total
    3637    """
    37     if extra_context is None: extra_context = {}
    38     queryset = queryset._clone()
     38    if extra_context is None:
     39        extra_context = {}
     40    if type(queryset) == QuerySet:
     41        queryset = queryset._clone()
    3942    if paginate_by:
    4043        paginator = ObjectPaginator(queryset, paginate_by)
    4144        if not page:
     
    7376        else:
    7477            c[key] = value
    7578    if not template_name:
    76         model = queryset.model
    77         template_name = "%s/%s_list.html" % (model._meta.app_label, model._meta.object_name.lower())
     79        if type(queryset) == QuerySet:
     80            model = queryset.model
     81            template_name = "%s/%s_list.html" % (model._meta.app_label, model._meta.object_name.lower())
     82        else:
     83            raise AttributeError, "Generic list view must be called with either a template_name or a queryset (rather than a list)."
    7884    t = template_loader.get_template(template_name)
    7985    return HttpResponse(t.render(c), mimetype=mimetype)
    8086
  • docs/generic_views.txt

     
    679679
    680680**Required arguments:**
    681681
    682     * ``queryset``: A ``QuerySet`` that represents the objects.
     682    * ``queryset``: A ``QuerySet`` that represents the objects. **New in Django
     683      development version**: ``queryset`` may be any sequence such as a list or
     684      tuple that represents the objects.
    683685
    684686**Optional arguments:**
    685687
     
    720722**Template name:**
    721723
    722724If ``template_name`` isn't specified, this view will use the template
    723 ``<app_label>/<model_name>_list.html`` by default.
     725``<app_label>/<model_name>_list.html`` by default. **New in Django development
     726version**: In the development version this only applies if ``queryset`` is a
     727``QuerySet``.
    724728
    725729**Template context:**
    726730
Back to Top