Indexes a template by `name` into the `name_to_template` dictionary.

        :param tpl: The template to index
        :type tpl: alignak.objects.item.Item
        :return: None
15309
def index_template(self, tpl):
        
        objcls = self.inner_class.my_type
        name = getattr(tpl, 'name', '')
        if not name:
            mesg = "a %s template has been defined without name, from: %s" % \
                   (objcls, tpl.imported_from)
            tpl.add_error(mesg)
        elif name in self.name_to_template:
            tpl = self.manage_conflict(tpl, name)
        self.name_to_template[name] = tpl
        logger.debug("Indexed a %s template: %s, uses: %s",
                     tpl.my_type, name, getattr(tpl, 'use', 'Nothing'))
        return tpl
341957
def get_template(self, template_name):
        """"""
        try:
            return self.loader.load(template_name, encoding=self.encoding)
        except self.not_found_exception, e:
            # catch the exception raised by Genshi, convert it into a werkzeug
            # exception (for the sake of consistency)
            raise TemplateNotFound(template_name)
163451
def linkify_templates(self):
        
        # First we create a list of all templates
        for i in itertools.chain(iter(list(self.items.values())),
                                 iter(list(self.templates.values()))):
            self.linkify_item_templates(i)
        for i in self:
            i.tags = self.get_all_tags(i)
608030
def _get_template(self, template_name, template_file):
        
        template = os.path.join(self.location, 'templates',
                                template_name, template_file)
        return jinja2.Template(open(template).read())
809539
def parse_mailcap_nametemplate(tmplate='%s'):
    """"""
    nt_list = tmplate.split('%s')
    template_prefix = ''
    template_suffix = ''
    if len(nt_list) == 2:
        template_suffix = nt_list[1]
        template_prefix = nt_list[0]
    else:
        template_suffix = tmplate
    return (template_prefix, template_suffix)
552013
def get_template(self, name):
        """"""
        source = name
        if name and name[0] is '/':
            source = name[1:]
        elif self.source is not None:
            source = '/'.join((self.source, name))
        return self.env.get_template(source)
662254
def template_list(call=None):
    '''
    

    '''
    templates = {}
    session = _get_session()
    vms = session.xenapi.VM.get_all()
    for vm in vms:
        record = session.xenapi.VM.get_record(vm)
        if record['is_a_template']:
            templates[record['name_label']] = record
    return templates
1373813
def find_template(self, name):
        """"""
        deftemplate = lib.EnvFindDeftemplate(self._env, name.encode())
        if deftemplate == ffi.NULL:
            raise LookupError("Template '%s' not found" % name)

        return Template(self._env, deftemplate)
582261
def _dumpdata_template(self, stringbuffer, index, name, opts):
        
        context = self._get_dump_item_context(index, name, opts)

        stringbuffer.write(self.dumper_item_template.format(**context))

        return stringbuffer
1128908
def update_template(template,**kwargs):
    
    tmpl = db.DBSession.query(Template).filter(Template.id==template.id).one()
    tmpl.name = template.name
    if template.description:
        tmpl.description = template.description

    #Lazy load the rest of the template
    for tt in tmpl.templatetypes:
        for ta in tt.typeattrs:
            ta.attr

    if template.layout:
        tmpl.layout = get_layout_as_string(template.layout)

    type_dict = dict([(t.id, t) for t in tmpl.templatetypes])
    existing_templatetypes = []

    if template.types is not None or template.templatetypes is not None:
        types = template.types if template.types is not None else template.templatetypes
        for templatetype in types:
            if templatetype.id is not None:
                type_i = type_dict[templatetype.id]
                _update_templatetype(templatetype, type_i)
                existing_templatetypes.append(type_i.id)
            else:
                #Give it a template ID if it doesn't have one
                templatetype.template_id = template.id
                new_templatetype_i = _update_templatetype(templatetype)
                existing_templatetypes.append(new_templatetype_i.id)

    for tt in tmpl.templatetypes:
        if tt.id not in existing_templatetypes:
            delete_templatetype(tt.id)

    db.DBSession.flush()

    return tmpl
906611
def render_to_string(template_name, context=None, request=None, using=None):
    
    if isinstance(template_name, (list, tuple)):
        template = select_template(template_name, using=using)
    else:
        template = get_template(template_name, using=using)
    return template.render(context, request)
921856
def index_template_get(name, hosts=None, profile=None):
    '''
    
    '''
    es = _get_instance(hosts, profile)

    try:
        return es.indices.get_template(name=name)
    except elasticsearch.exceptions.NotFoundError:
        return None
    except elasticsearch.TransportError as e:
        raise CommandExecutionError("Cannot retrieve template {0}, server returned code {1} with message {2}".format(name, e.status_code, e.error))
611645
def template_name_from_class_name(class_name):
    
    suffix = 'Template'
    output = class_name
    if (class_name.endswith(suffix)):
        output = class_name[:-len(suffix)]
    return output
1266159
def unindex_item(self, item):
        
        name_property = getattr(self.__class__, "name_property", None)
        if name_property is None:
            return
        name = getattr(item, name_property, None)
        if name is None:
            return
        self.name_to_item.pop(name, None)
1246309
def copy_template(self, name=None):
        
        ret = Table(self.table_name)
        ret._indexes.update(dict((k, v.copy_template()) for k, v in self._indexes.items()))
        ret(name)
        return ret
208618
def get_template_by_name(name,**kwargs):
    
    try:
        tmpl_i = db.DBSession.query(Template).filter(Template.name == name).options(joinedload_all('templatetypes.typeattrs.default_dataset.metadata')).one()
        return tmpl_i
    except NoResultFound:
        log.info("%s is not a valid identifier for a template",name)
        raise HydraError('Template "%s" not found'%name)
684006
def template(tpl, template_adapter=SimpleTemplate, **kwargs):
    '''
    
    '''
    if tpl not in TEMPLATES or DEBUG:
        settings = kwargs.get('template_settings',{})
        lookup = kwargs.get('template_lookup', TEMPLATE_PATH)
        if isinstance(tpl, template_adapter):
            TEMPLATES[tpl] = tpl
            if settings: TEMPLATES[tpl].prepare(settings)
        elif "\n" in tpl or "{" in tpl or "%" in tpl or '$' in tpl:
            TEMPLATES[tpl] = template_adapter(source=tpl, lookup=lookup, settings=settings)
        else:
            TEMPLATES[tpl] = template_adapter(name=tpl, lookup=lookup, settings=settings)
    if not TEMPLATES[tpl]:
        abort(500, 'Template (%s) not found' % tpl)
    kwargs['abort'] = abort
    kwargs['request'] = request
    kwargs['response'] = response
    return TEMPLATES[tpl].render(**kwargs)