Ticket #1399: django_template_model_name.diff

File django_template_model_name.diff, 2.1 KB (added by ChaosKCW, 10 years ago)

A Patch to add 'template_model_name' to generic views

  • H:/Programming/Python/Python24/Lib/site-packages/django/views/generic/list_detail.py

     
    66
    77def object_list(request, queryset, paginate_by=None, allow_empty=False,
    88        template_name=None, template_loader=loader,
    9         extra_context={}, context_processors=None):
     9        extra_context={}, context_processors=None, template_model_name='object'):
    1010    """
    1111    Generic list of objects.
    1212
     
    4747                raise Http404
    4848        page = int(page)
    4949        c = RequestContext(request, {
    50             'object_list': object_list,
     50            '%(template_model_name)s_list' % {'template_model_name': template_model_name}: object_list,
    5151            'is_paginated': paginator.pages > 1,
    5252            'results_per_page': paginate_by,
    5353            'has_next': paginator.has_next_page(page),
     
    6060        }, context_processors)
    6161    else:
    6262        c = RequestContext(request, {
    63             'object_list': queryset,
     63            '%(template_model_name)s_list' % {'template_model_name': template_model_name}: queryset,
    6464            'is_paginated': False
    6565        }, context_processors)
    6666        if not allow_empty and len(queryset) == 0:
     
    7878def object_detail(request, queryset, object_id=None, slug=None,
    7979        slug_field=None, template_name=None, template_name_field=None,
    8080        template_loader=loader, extra_context={},
    81         context_processors=None):
     81        context_processors=None, template_model_name='object'):
    8282    """
    8383    Generic list of objects.
    8484
     
    106106    else:
    107107        t = template_loader.get_template(template_name)
    108108    c = RequestContext(request, {
    109         'object': object,
     109        template_model_name: object,
    110110    }, context_processors)
    111111    for key, value in extra_context.items():
    112112        if callable(value):
Back to Top