Django

Code

Changeset 2453

Show
Ignore:
Timestamp:
02/28/06 21:37:57 (3 years ago)
Author:
adrian
Message:

Fixed #1399 -- Added template_object_name hook to generic views. Thanks, ChaosKCW

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/AUTHORS

    r2346 r2453  
    4646    C8E 
    4747    Amit Chakradeo <http://amit.chakradeo.net/> 
     48    ChaosKCW 
    4849    Matt Croydon <http://www.postneo.com/> 
    4950    Jonathan Daugherty (cygnus) <http://www.cprogrammer.org/> 
  • django/trunk/django/views/generic/create_update.py

    r1773 r2453  
    7474        slug_field=None, template_name=None, template_loader=loader, 
    7575        extra_lookup_kwargs={}, extra_context={}, post_save_redirect=None, 
    76         login_required=False, follow=None, context_processors=None): 
     76        login_required=False, follow=None, context_processors=None, 
     77        template_object_name='object'): 
    7778    """ 
    7879    Generic object-update function. 
     
    134135    c = DjangoContext(request, { 
    135136        'form': form, 
    136         'object': object, 
     137        template_object_name: object, 
    137138    }, context_processors) 
    138139    for key, value in extra_context.items(): 
     
    148149        object_id=None, slug=None, slug_field=None, template_name=None, 
    149150        template_loader=loader, extra_lookup_kwargs={}, extra_context={}, 
    150         login_required=False, context_processors=None): 
     151        login_required=False, context_processors=None, template_object_name='object'): 
    151152    """ 
    152153    Generic object-delete function. 
     
    190191        t = template_loader.get_template(template_name) 
    191192        c = DjangoContext(request, { 
    192             'object': object, 
     193            template_object_name: object, 
    193194        }, context_processors) 
    194195        for key, value in extra_context.items(): 
  • django/trunk/django/views/generic/date_based.py

    r2337 r2453  
    9090        month_format='%b', template_name=None, template_loader=loader, 
    9191        extra_lookup_kwargs={}, extra_context={}, allow_empty=False, 
    92         context_processors=None): 
     92        context_processors=None, template_object_name='object'): 
    9393    """ 
    9494    Generic monthly archive view. 
     
    130130    t = template_loader.get_template(template_name) 
    131131    c = DjangoContext(request, { 
    132         'object_list': object_list, 
     132        '%s_list' % template_object_name: object_list, 
    133133        'month': date, 
    134134        'next_month': (last_day < datetime.date.today()) and (last_day + datetime.timedelta(days=1)) or None, 
     
    145145        month_format='%b', day_format='%d', template_name=None, 
    146146        template_loader=loader, extra_lookup_kwargs={}, extra_context={}, 
    147         allow_empty=False, context_processors=None): 
     147        allow_empty=False, context_processors=None, template_object_name='object'): 
    148148    """ 
    149149    Generic daily archive view. 
     
    181181    t = template_loader.get_template(template_name) 
    182182    c = DjangoContext(request, { 
    183         'object_list': object_list, 
     183        '%s_list' % template_object_name: object_list, 
    184184        'day': date, 
    185185        'previous_day': date - datetime.timedelta(days=1), 
     
    209209        slug_field=None, template_name=None, template_name_field=None, 
    210210        template_loader=loader, extra_lookup_kwargs={}, extra_context={}, 
    211         context_processors=None): 
     211        context_processors=None, template_object_name='object'): 
    212212    """ 
    213213    Generic detail view from year/month/day/slug or year/month/day/id structure. 
     
    250250        t = template_loader.get_template(template_name) 
    251251    c = DjangoContext(request, { 
    252         'object': object, 
     252        template_object_name: object, 
    253253    }, context_processors) 
    254254    for key, value in extra_context.items(): 
  • django/trunk/django/views/generic/list_detail.py

    r2426 r2453  
    99def object_list(request, app_label, module_name, paginate_by=None, allow_empty=False, 
    1010        template_name=None, template_loader=loader, extra_lookup_kwargs={}, 
    11         extra_context={}, context_processors=None): 
     11        extra_context={}, context_processors=None, template_object_name='object'): 
    1212    """ 
    1313    Generic list of objects. 
     
    5050                raise Http404 
    5151        c = DjangoContext(request, { 
    52             'object_list': object_list, 
     52            '%s_list' % template_object_name: object_list, 
    5353            'is_paginated': paginator.pages > 1, 
    5454            'results_per_page': paginate_by, 
     
    6464        object_list = mod.get_list(**lookup_kwargs) 
    6565        c = DjangoContext(request, { 
    66             'object_list': object_list, 
     66            '%s_list' % template_object_name: object_list, 
    6767            'is_paginated': False 
    6868        }, context_processors) 
     
    8282        slug_field=None, template_name=None, template_name_field=None, 
    8383        template_loader=loader, extra_lookup_kwargs={}, extra_context={}, 
    84         context_processors=None): 
     84        context_processors=None, template_object_name='object'): 
    8585    """ 
    8686    Generic list of objects. 
     
    112112        t = template_loader.get_template(template_name) 
    113113    c = DjangoContext(request, { 
    114         'object': object, 
     114        template_object_name: object, 
    115115    }, context_processors) 
    116116    for key, value in extra_context.items(): 
  • django/trunk/docs/generic_views.txt

    r2337 r2453  
    193193    **New in Django development version:** Takes an optional ``allow_empty`` 
    194194    parameter, as ``archive_index``. 
     195 
     196    **New in Django development version:** Takes an optional 
     197    ``template_object_name`` parameter, which designates the name of the 
     198    template variable to use. Default is ``'object'``. 
    195199 
    196200    Uses the template ``app_label/module_name_archive_month`` by default. 
     
    208212            previous month (a datetime.date object) 
    209213        ``object_list`` 
    210             List of objects published in the given month 
     214            List of objects published in the given month. 
     215            In the Django development version, you can change this variable 
     216            name from ``object_list`` by using the ``template_object_name`` 
     217            parameter. (See above.) For example, if ``template_object_name`` is 
     218            ``foo``, the variable will be ``foo_list``. 
    211219 
    212220``archive_day`` 
     
    218226    decimal number, 1-31). 
    219227 
     228    **New in Django development version:** Takes an optional 
     229    ``template_object_name`` parameter, which designates the name of the 
     230    template variable to use. Default is ``'object'``. 
     231 
    220232    Uses the template ``app_label/module_name_archive_day`` by default. 
    221233 
     
    223235 
    224236        ``object_list`` 
    225             List of objects published this day 
     237            List of objects published on the given day. 
     238            In the Django development version, you can change this variable 
     239            name from ``object_list`` by using the ``template_object_name`` 
     240            parameter. (See above.) For example, if ``template_object_name`` is 
     241            ``foo``, the variable will be ``foo_list``. 
    226242        ``day`` 
    227243            The given day (a datetime.datetime object) 
     
    255271    and ``day_format`` parameters. 
    256272 
     273    **New in Django development version:** Takes an optional 
     274    ``template_object_name`` parameter, which designates the name of the 
     275    template variable to use. Default is ``'object'``. 
     276 
    257277.. _strftime docs: http://www.python.org/doc/current/lib/module-time.html#l2h-1941 
    258278 
     
    286306                                 the view will raise a 404 instead of displaying 
    287307                                 an empty index page. ``False`` is default. 
     308        ``template_object_name`` **New in Django development version.** Designates 
     309                                 the name of the object template variable. Default 
     310                                 is ``'object'``. 
    288311        =======================  ================================================= 
    289312 
     
    293316 
    294317        ``object_list`` 
    295             List of objects 
     318            List of objects. In the Django development version, you can change 
     319            this variable name from ``object_list`` by using the 
     320            ``template_object_name`` parameter. (See above.) For example, if 
     321            ``template_object_name`` is ``foo``, the variable will be 
     322            ``foo_list``. 
    296323        ``is_paginated`` 
    297324            Are the results paginated? Either True or False 
     
    363390    ``post_save_redirect`` as ``create_object`` does. 
    364391 
     392    **New in Django development version:** Takes an optional 
     393    ``template_object_name`` parameter, which designates the name of the 
     394    template variable to use. Default is ``'object'``. 
     395 
    365396    Uses the template ``app_label/module_name_form`` by default. 
    366397 
     
    370401            The form wrapper for the object 
    371402        object 
    372             The original object being edited 
     403            The original object being edited. 
     404            In the Django development version, you can change this variable 
     405            name from ``object`` by using the ``template_object_name`` 
     406            parameter. (See above.) For example, if ``template_object_name`` is 
     407            ``foo``, the variable will be ``foo`` instead of ``object``. 
    373408 
    374409``delete_object`` 
     
    385420    if POSTed -- it simply deletes the object and redirects. 
    386421 
     422    **New in Django development version:** Takes an optional 
     423    ``template_object_name`` parameter, which designates the name of the 
     424    template variable to use. Default is ``'object'``. 
     425 
    387426    Has the following template context: 
    388427 
    389428        object 
    390429            The object about to be deleted 
     430            In the Django development version, you can change this variable 
     431            name from ``object`` by using the ``template_object_name`` 
     432            parameter. (See above.) For example, if ``template_object_name`` is 
     433            ``foo``, the variable will be ``foo`` instead of ``object``.