Пример #1
0
 def render_template(self, template=None):
     if template is None:
         template = self.__class__.identifier + '.html'
     context = dict(self.__dict__)
     context.update(url_for=self.url_for, self=self)
     body_tmpl = Template.from_file(path.join(templates, template))
     layout_tmpl = Template.from_file(path.join(templates, 'layout.html'))
     context['body'] = body_tmpl.render(context)
     return layout_tmpl.render(context)
Пример #2
0
 def get_template(self, name):
     """Get a template from a given name."""
     filename = path.join(self.search_path, *[p for p in name.split('/')
                                              if p and p[0] != '.'])
     if not path.exists(filename):
         raise TemplateNotFound(name)
     return Template.from_file(filename, self.encoding)
Пример #3
0
 def get_template(self, name):
     """Get a template from a given name."""
     filename = path.join(self.search_path, *[p for p in name.split('/')
                                              if p and p[0] != '.'])
     if not path.exists(filename):
         raise TemplateNotFound(name)
     return Template.from_file(filename, self.encoding)
Пример #4
0
 def generate(self, rsp, **kwargs):
     global settings
     kwargs['cfg_line'] = lambda s, d=None: s + ' = ' + repr(settings.get(s, d))
     for filename in ('launch.wsgi', 'app.py', 'settings.py', 'manage.py'):
         with open(in_cwd(filename), 'w') as f:
             # Template strips off trailing whitespace...
             f.write(Template.from_file(in_skeld(filename + '.tmpl')).render(**kwargs) + '\n')
     os.chmod(in_cwd('manage.py'), 0755)
Пример #5
0
def test_from_file_with_filename():
    """Template from_file where file parameter is a filename"""
    fd, filename = tempfile.mkstemp()
    try:
        os.write(fd, "Hello ${you}!")
    finally:
        os.close(fd)
    try:
        t = Template.from_file(filename)
        assert t.render(you="World") == "Hello World!"
    finally:
        os.unlink(filename)
Пример #6
0
def test_from_file_with_filename():
    """Template from_file where file parameter is a filename"""
    fd, filename = tempfile.mkstemp()
    try:
        os.write(fd, "Hello ${you}!")
    finally:
        os.close(fd)
    try:
        t = Template.from_file(filename)
        assert t.render(you="World") == "Hello World!"
    finally:
        os.unlink(filename)
Пример #7
0
def get_template(name):
    return Template.from_file(join(dirname(__file__), 'shared', name), unicode_mode=False, errors='ignore')
Пример #8
0
def get_template(filename):
    return Template.from_file(join(dirname(__file__), 'templates', filename))
Пример #9
0
def get_template(name):
    return Template.from_file(join(dirname(__file__), 'shared', name),
                              unicode_mode=False,
                              errors='ignore')
Пример #10
0
 def generate(self, rsp, **kwargs):
     template_data = self.req.environ.copy()
     template_data.update(kwargs)
     rsp.data = Template.from_file(self.filename).render(template_data)
Пример #11
0
def test_from_file_with_fileobject():
    """Template from_file where file parameter is a file object"""
    t = Template.from_file(sio.StringIO("Hello ${you}!"))
    assert t.render(you="World") == "Hello World!"
Пример #12
0
def test_from_file_with_fileobject():
    """Template from_file where file parameter is a file object"""
    t = Template.from_file(sio.StringIO("Hello ${you}!"))
    assert t.render(you="World") == "Hello World!"
Пример #13
0
 def render_template(self, name, values):
     return Template.from_file(path.join(TEMPLATES, name)).render(values)