Example #1
0
 def index(self, req):
     _index = Template.from_filename('index.html')
     conn = Connection()
     db = conn.comet
     coll = db.points
     data = coll.find()
     _index = _index.substitute(data=data)
     return _index
Example #2
0
 def get_template(self, name, **kw):
     if self._lookup is None:
         self._lookup = TemplateLookup(directories=self.directories, **kw)
     try:
         return self._lookup.get_template('%s.%s' % (name, self.extension))
     except TopLevelLookupException:
         filename = os.path.join(MAKO_TEMPLATES, '%s.mako_tmpl' % name)
         if os.path.isfile(filename):
             template = TempitaTemplate.from_filename(filename)
             return MakoTemplate(template.substitute(template_engine='mako'), **kw)
Example #3
0
 def get_template(self, name, **kw):
     if self._lookup is None:
         self._lookup = TemplateLookup(directories=self.directories, **kw)
     try:
         return self._lookup.get_template('%s.%s' % (name, self.extension))
     except TopLevelLookupException:
         filename = os.path.join(MAKO_TEMPLATES, '%s.mako_tmpl' % name)
         if os.path.isfile(filename):
             template = TempitaTemplate.from_filename(filename)
             return MakoTemplate(template.substitute(template_engine='mako'), **kw)
Example #4
0
 def bookmarklet(self, req, name, content_type='text/javascript'):
     tmpl = Template.from_filename(os.path.join(here, name))
     with open(os.path.join(here, 'docserialize.js')) as fp:
         docserialize = fp.read()
     body = tmpl.substitute(
         uiType='annotation',
         appUrl=req.application_url,
         options={},
         bookmarkletUrl=req.url,
         docserializeJs=docserialize,
         appIncludeJs=self.appinclude_js,
         )
     return Response(
         body=body,
         content_type=content_type)
Example #5
0
    def paste_template(self, template_name, template=None, deploy_dir=None):
        " Paste template. "

        LOGGER.info("Paste template: %s" % template_name)
        deploy_dir = deploy_dir or self.deploy_dir
        template = template or self._get_template_path(template_name)
        self.read([op.join(template, settings.CFGNAME)], extending=True)

        for fname in gen_template_files(template):
            curdir = op.join(deploy_dir, op.dirname(fname))
            if not op.exists(curdir):
                makedirs(curdir)

            source = op.join(template, fname)
            target = op.join(deploy_dir, fname)
            copy2(source, target)
            name, ext = op.splitext(fname)
            if ext == '.tmpl':
                t = Template.from_filename(target, namespace=self.as_dict())
                with open(op.join(deploy_dir, name), 'w') as f:
                    f.write(t.substitute())
                remove(target)

        return deploy_dir
Example #6
0
    def paste_template(self, template_name, template=None, deploy_dir=None):
        " Paste template. "

        LOGGER.debug("Paste template: %s" % template_name)
        deploy_dir = deploy_dir or self.deploy_dir
        template = template or self._get_template_path(template_name)
        self.read([op.join(template, settings.CFGNAME)], extending=True)

        for fname in gen_template_files(template):
            curdir = op.join(deploy_dir, op.dirname(fname))
            if not op.exists(curdir):
                makedirs(curdir)

            source = op.join(template, fname)
            target = op.join(deploy_dir, fname)
            copy2(source, target)
            name, ext = op.splitext(fname)
            if ext == '.tmpl':
                t = Template.from_filename(target, namespace=self.as_dict())
                with open(op.join(deploy_dir, name), 'w') as f:
                    f.write(t.substitute())
                remove(target)

        return deploy_dir
Example #7
0
def _render_template(filename, namespace):                    
    return Template.from_filename(os.path.join(template_dir, filename), namespace=namespace).substitute()
Example #8
0
def render_template(filename, namespace):
    return Template.from_filename(path.join(template_dir, filename), namespace=namespace).substitute()
 def __call__(self, template_name, context):
     content = Template.from_filename(self.templates_dir + template_name)
     return content.substitute(**context)
Example #10
0
 def get_template(self, name, **kw):
     filename = self.get_filename(name)
     if filename:
         return TempitaTemplate.from_filename(filename, **kw)
Example #11
0
 def load_unattended_template(self):
     """Loads the unattended template that is used for installation."""
     path = self.get_contrib_path('Autounattend.xml')
     return Template.from_filename(path)
Example #12
0
 def get_template(self, name, **kw):
     filename = self.get_filename(name)
     if filename:
         return TempitaTemplate.from_filename(filename, **kw)
Example #13
0
 def test_read_template_from_file_without_encoding(self):
     filename = '/tests/test_basetemplate.txt'
     namespace = dict(name="Arthur Dent")
     t = Template.from_filename(sys.path[0] + filename, namespace=namespace, encoding=None)
     print(t)