Django

Code

Changeset 3950

Show
Ignore:
Timestamp:
10/30/06 08:30:43 (2 years ago)
Author:
russellm
Message:

Fixes #2966 -- Added extra_context parameter to direct_to_template generic view to keep it aligned with capabilities of other generic views. Thanks, wam-djangobug@wamber.net.

Files:

Legend:

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

    r3941 r3950  
    161161    Geert Vanderkelen 
    162162    Milton Waddams 
     163    wam-djangobug@wamber.net 
    163164    Dan Watson <http://theidioteque.net/> 
    164165    Rachel Willmer <http://www.willmer.com/kb/> 
  • django/trunk/django/views/generic/simple.py

    r3948 r3950  
    33from django.http import HttpResponse, HttpResponsePermanentRedirect, HttpResponseGone 
    44 
    5 def direct_to_template(request, template, **kwargs): 
     5def direct_to_template(request, template, extra_context={}, **kwargs): 
    66    """ 
    77    Render a given template with any extra URL parameters in the context as 
    88    ``{{ params }}``. 
    99    """ 
    10     return render_to_response(template, {'params' : kwargs}, context_instance=RequestContext(request)) 
     10    dictionary = {'params': kwargs} 
     11    for key, value in extra_context.items(): 
     12        if callable(value): 
     13            dictionary[key] = value() 
     14        else: 
     15            dictionary[key] = value 
     16    return render_to_response(template, dictionary, context_instance=RequestContext(request)) 
    1117 
    1218def redirect_to(request, url, **kwargs): 
  • django/trunk/docs/generic_views.txt

    r3913 r3950  
    9393    * ``template``: The full name of a template to use. 
    9494 
     95**Optional arguments:** 
     96 
     97    * ``extra_context``: A dictionary of values to add to the template 
     98      context. By default, this is an empty dictionary. If a value in the 
     99      dictionary is callable, the generic view will call it 
     100      just before rendering the template. 
     101       
    95102**Example:** 
    96103 
     
    172179 
    173180    * ``extra_context``: A dictionary of values to add to the template 
    174       context. By default, this is an empty dictionary. 
     181      context. By default, this is an empty dictionary. If a value in the 
    175182      dictionary is callable, the generic view will call it 
    176183      just before rendering the template.