def get_template(archivist, context): """Return the correct Jinja2 Template object for this archetype.""" templates = [] # Most specific to least specific. Does the archetype request a # custom template? Note that config values may be a list, or a # single string. t = context.get('template') if is_sequence(t): templates.extend(t) elif t: templates.append(t) # Next, we'll look for templates specific to the itemtype, crawling up the # hierarchy for fallbacks. if 'itemtype' in context: templates.append(context['itemtype']) (root, _) = path.split(context['itemtype']) while root: templates.append(root) (root, _) = path.split(root) # Does the siteconfig specify a default template? t = archivist.siteconfig.get('default_template') if is_sequence(t): templates.extend(t) elif t: templates.append(t) # If no configured default, fall back to "emergency" default. templates.append(Template(fallback_template)) return archivist.jinja.select_template(templates)
def test_list_is_sequence(): assert is_sequence(['a list'])
def test_string_is_sequence(): assert not is_sequence('test string')