Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #1963: buffet_patch.diff

File buffet_patch.diff, 4.9 KB (added by chrisz, 2 years ago)

Support for options in render method.

  • turbogears/controllers.py

     
    3434 
    3535 
    3636def _process_output(output, template, format, content_type, 
    37         mapping, fragment=False): 
     37        fragment=False, **options): 
    3838    """Produce final output form from data returned from a controller method. 
    3939 
    4040    See the expose() arguments for more info since they are the same. 
     
    9292 
    9393        headers = {'Content-Type': content_type} 
    9494        output = view.render(output, template=template, format=format, 
    95                     mapping=mapping, headers=headers, 
    96                     fragment=fragment) 
     95                headers=headers, fragment=fragment, **options) 
    9796        content_type = headers['Content-Type'] 
    9897 
    9998    if content_type: 
     
    260259 
    261260def expose(template=None, allow_json=None, 
    262261           format=None, content_type=None, fragment=False, 
    263            as_format="default", mapping=None, accept_format=None): 
     262           as_format="default", accept_format=None, **options): 
    264263    """Exposes a method to the web. 
    265264 
    266265    By putting the expose decorator on a method, you tell TurboGears that 
     
    314313            just generate the immediate template fragment. Use this 
    315314            if you're building up a page from multiple templates or 
    316315            going to put something onto a page with .innerHTML. 
    317     @keyparam mapping mapping with options that are sent to the template 
    318             engine 
    319316    @keyparam as_format designates which value of tg_format will choose 
    320317            this expose. 
    321318    @keyparam accept_format which value of an Accept: header will 
    322319            choose this expose. 
    323320 
     321    All additional options are passed as keyword parameters 
     322    to the render method of the template engine. 
     323 
    324324    """ 
    325325    if not template: 
    326326        template = format 
     
    384384            accept_format=accept_format, template=template, 
    385385            rulefunc=lambda _func, accept, allow_json, *args, **kw: 
    386386                _execute_func(_func, template, format, content_type, 
    387                     mapping, fragment, args, kw))) 
     387                    fragment, options, args, kw))) 
    388388 
    389389        if allow_json: 
    390390            func._allow_json = True 
     
    393393    return weak_signature_decorator(entangle) 
    394394 
    395395 
    396 def _execute_func(func, template, format, content_type, mapping, fragment, args, kw): 
     396def _execute_func(func, template, format, content_type, fragment, 
     397        options, args, kw): 
    397398    """Call controller method and process it's output.""" 
    398399 
    399400    if config.get("tg.strict_parameters", False): 
     
    440441            format = output.pop("tg_format", format) 
    441442 
    442443        if template and template.startswith("."): 
    443             template = func.__module__[:func.__module__.rfind('.')]+template 
     444            template = func.__module__[:func.__module__.rfind('.')] + template 
    444445 
    445         return _process_output(output, template, format, content_type, mapping, 
    446                                fragment) 
     446        return _process_output(output, template, format, 
     447            content_type, fragment, **options) 
    447448 
    448449 
    449450def flash(message): 
  • turbogears/view/base.py

     
    106106    return engine, template, enginename 
    107107 
    108108 
    109 def render(info, template=None, format=None, headers=None, mapping=None, 
    110         fragment=False): 
     109def render(info, template=None, format=None, 
     110        headers=None, fragment=False, **options): 
    111111    """Renders data in the desired format. 
    112112 
    113113    @param info: the data itself 
     
    122122    @param headers: for response headers, primarily the content type 
    123123    @type headers: dict 
    124124 
    125     @param mapping: keyword arguments passed to the underlying engine 
    126     @type mapping: ? 
    127  
    128125    @param fragment: passed through to tell the template if only a 
    129126                     fragment of a page is desired. This is a way to allow 
    130127                     xml template engines to generate non valid html/xml 
    131128                     because you warn them to not bother about it. 
    132129    @type fragment: bool 
     130 
     131    All additional options are passed as keyword parameters 
     132    to the render method of the template engine. 
     133 
    133134    """ 
    134135    environ = getattr(cherrypy.request, 'wsgi_environ', {}) 
    135136    if environ.get('paste.testing', False): 
     
    191192 
    192193        headers['Content-Type'] = content_type 
    193194 
    194     args, kw = adapt_call(engine.render, args=[], 
    195         kw = dict(info=info, format=format, fragment=fragment, 
    196         template=template, mapping=mapping), start=1) 
     195    kw = dict(info=info, format=format, fragment=fragment, template=template) 
     196    kw.update(options) 
     197    args, kw = adapt_call(engine.render, args=[], kw=kw, start=1) 
    197198 
    198199    return engine.render(**kw) 
    199200