def env(self): DIR = jnj.__file__ DIR = path.dirname(path.abspath(DIR)) TEMPLATES = [path.join(DIR, 'templates')] jinja_loader = TemplateEngine(TEMPLATES) template_loader = Template(engines={'html': jinja_loader}, *TEMPLATES) env = VersionedStorage() env.template = BoundTemplate(env, template_loader) return env
def setUp(self): class TestingBoundTemplate(BoundTemplate): def get_template_vars(self): return {'readonly': True} templates_dir = os.path.join(os.path.dirname(__file__), '..', '..', 'iktomi', 'templates', 'jinja2', 'templates') self.engine = TemplateEngine(templates_dir) template = Template(templates_dir, engines={'html': self.engine}) env = web.AppEnvironment.create() self.bound = TestingBoundTemplate(env, template)
def test_render(self): class F(Form): fields = [ Field('first', convs.Int(), initial=1), Field('second', convs.Int()), ] templates_dir = os.path.join(os.path.dirname(__file__), '..', '..', 'iktomi', 'templates', 'jinja2', 'templates') engine = TemplateEngine(templates_dir) template = Template(templates_dir, engines={'html': engine}) env = AppEnvironment.create(template=template) form = F(env) form.accept({'first': '123', 'second': '246'}) self.assertIn('<input', form.render()) self.assertIn('id="first"', form.render()) self.assertIn('value="123"', form.render()) self.assertIn('class="textinput"', form.render()) self.assertIn('id="second"', form.render()) self.assertIn('value="246"', form.render())
def setUp(self): templates_dir = os.path.join(os.path.dirname(__file__), '..', '..', 'iktomi', 'templates', 'jinja2', 'templates') self.engine = TemplateEngine(templates_dir) self.template = Template(templates_dir, engines={'html': self.engine})
# -*- coding: utf-8 -*- from iktomi import web from iktomi.web.filters import * from iktomi.templates import jinja2, Template from environment import Environment import cfg import handlers as h static = static_files(cfg.STATIC) media = static_files(cfg.MEDIA_DIR, cfg.MEDIA_URL) form_temp = static_files(cfg.FORM_TEMP, cfg.FORM_TEMP_URL) template = Template(cfg.TEMPLATES, jinja2.TEMPLATE_DIR, engines={'html': jinja2.TemplateEngine}) app = web.cases( static, media, form_temp, match('/', 'files') | web.cases( # Playing REST ;) method('GET') | h.list_files, method('POST') | h.post_file, #method('DELETE') | h.delete_files, ), ) wsgi_app = web.Application(app, env_class=Environment)
import logging from iktomi import web from iktomi.unstable.db.files import FileManager from iktomi.templates import Template, BoundTemplate as BaseBoundTemplate from iktomi.templates.jinja2 import TemplateEngine from iktomi.utils.storage import storage_cached_property from iktomi.utils import cached_property #from jinja2 import Markup import cfg logger = logging.getLogger(__name__) static = web.static_files('static') jinja_loader = TemplateEngine(cfg.TEMPLATES) template_loader = Template(engines={'html': jinja_loader}, *cfg.TEMPLATES) file_manager = FileManager(cfg.FORM_TEMP, cfg.MEDIA_DIR, cfg.FORM_TEMP_URL, cfg.MEDIA_URL) class Environment(web.AppEnvironment): cfg = cfg file_manager = file_manager @cached_property def url_for(self): return self.root.build_url @cached_property def url_for_static(self): return static.construct_reverse()