Changeset 5699

Show
Ignore:
Timestamp:
11/17/08 15:21:13 (2 months ago)
Author:
faide
Message:

Doc for the tg.view.base._choose_engine function

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.1/turbogears/view/base.py

    r5692 r5699  
    2828 
    2929def _choose_engine(template): 
     30    """a private method to parse template name from the 
     31    expose template argument. If the @expose decorator did not contain 
     32    a template argument, we fetch the default engine info from the 
     33    configuration file. 
     34 
     35    @param template: a template string as seen in the expose decorator. 
     36    This can be "kid:myproj.templates.welcome" or just 
     37    "myproj.templates.welcome". 
     38    If a colon is found, then we try to get the engine name from the 
     39    template string. Else we try to search it from the default engine in 
     40    the configuration file. 
     41    @type template: basestring or None 
     42    """ 
    3043    if isinstance(template, basestring): 
     44        # if a template arg was given we try to find the engine declaration 
     45        # in it by  
    3146        colon = template.find(":") 
    3247        if colon > -1: 
    3348            enginename = template[:colon] 
    3449            template = template[colon+1:] 
     50 
    3551        else: 
    3652            engine = engines.get(template, None) 
     
    3854                return engine, None, template 
    3955            enginename = config.get("tg.defaultview", "kid") 
     56 
    4057    else: 
    4158        enginename = config.get("tg.defaultview", "kid") 
     59 
    4260    engine = engines.get(enginename, None) 
     61 
    4362    if not engine: 
    4463        raise KeyError, \ 
    4564            "Template engine %s is not installed" % enginename 
     65 
    4666    return engine, template, enginename 
    4767 
     
    7393    template = format == 'json' and 'json' or info.pop( 
    7494        "tg_template", template) 
     95 
    7596    if not info.has_key("tg_flash"): 
    7697        if config.get("tg.empty_flash", True): 
    7798            info["tg_flash"] = None 
     99 
    78100    engine, template, enginename = _choose_engine(template) 
     101 
    79102    if format: 
    80103        if format == 'plain': 
    81104            if enginename == 'genshi': 
    82105                format = 'text' 
     106 
    83107        elif format == 'text': 
    84108            if enginename == 'kid': 
    85109                format = 'plain' 
     110 
    86111    else: 
    87112        format = enginename == 'json' and 'json' or config.get(