当前位置: 首页>>代码示例>>Python>>正文


Python view.template函数代码示例

本文整理汇总了Python中ptah.view.template函数的典型用法代码示例。如果您正苦于以下问题:Python template函数的具体用法?Python template怎么用?Python template使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了template函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_customize_layers_with_custom_name

    def test_customize_layers_with_custom_name(self):
        self.dir3 = tempfile.mkdtemp()

        self._mkfile1(self.file1)
        f = open(os.path.join(self.dir1, 'file2.pt'), 'wb')
        f.write(self.file2)
        f.close()

        tmpl1 = view.template(os.path.join(self.dir1, 'file.pt'),
                              layer = 'layer')
        tmpl2 = view.template(os.path.join(self.dir1, 'file2.pt'),
                              layer = 'layer')
        self.assertEqual(tmpl1(), '<div>Test template 1</div>')
        self.assertEqual(tmpl2(), '<div>Test template 2</div>')

        # layers
        view.layer('layer', self.dir2)
        view.layer('layer', self.dir3)

        # override file.pt
        f = open(os.path.join(self.dir2, 'file.pt'), 'wb')
        f.write(self.file2)
        f.close()

        # override file2.pt
        f = open(os.path.join(self.dir3, 'file2.pt'), 'wb')
        f.write(self.file1)
        f.close()

        # initialize layers
        customize._Manager.initialize()

        self.assertEqual(tmpl1(), '<div>Test template 2</div>')
        self.assertEqual(tmpl2(), '<div>Test template 1</div>')
开发者ID:mcdonc,项目名称:ptah,代码行数:34,代码来源:test_customize.py

示例2: test_tmpl_multiple_disable_packages

 def test_tmpl_multiple_disable_packages(self):
     tmpl = view.template('ptah.view.tests:templates/test.pt',
                          nolayer = True)
     tmpl = view.template('ptah.view.tests:templates/test.pt',
                          nolayer = True)
     self.assertEqual(
         tapi.registry.keys(), [])
开发者ID:blaflamme,项目名称:ptah,代码行数:7,代码来源:test_tmpl.py

示例3: test_tmpl_multiple_extra_params

    def test_tmpl_multiple_extra_params(self):
        view.template('ptah.view.tests:templates/test.pt',
                      title = 'Test template',
                      description = 'Test template description')

        self.assertEqual(tapi.registry['ptah.view.tests']['test.pt'][1:3],
                         ['Test template', 'Test template description'])
开发者ID:WouterVH,项目名称:ptah,代码行数:7,代码来源:test_tmpl.py

示例4: test_tmpl

    def test_tmpl(self):
        tmpl = view.template('ptah.view.tests:templates/test.pt')
        self.assertTrue('PageTemplateFile' in repr(tmpl))

        tmpl = view.template('ptah.view.tests:templates/test.txt')
        self.assertTrue('PageTextTemplateFile' in repr(tmpl))

        self.assertEqual(tapi.registry['ptah.view.tests'].keys(),
                         ['test.pt', 'test.txt'])
开发者ID:blaflamme,项目名称:ptah,代码行数:9,代码来源:test_tmpl.py

示例5: test_renderer_tmpl_extra_params_none

    def test_renderer_tmpl_extra_params_none(self):
        def viewFactory(context, request):
            return None, None

        r = Renderer(template=view.template('templates/test.pt'))
        res = r(Context(), self.request, viewFactory)
        self.assertEqual(res.body.strip(), '<div>My snippet</div>')
开发者ID:mcdonc,项目名称:ptah,代码行数:7,代码来源:test_renderers.py

示例6: test_commands_template_customize_error2

    def test_commands_template_customize_error2(self):
        tmpl = view.template('ptah.view:/tests/templates/test.pt')
        sys.argv[:] = ['paste', 'templates', '-c', 'unknownpkg:filename']

        val = self._run()

        self.assertTrue("Can't find package 'unknownpkg'" in val)
开发者ID:mcdonc,项目名称:ptah,代码行数:7,代码来源:test_commands.py

示例7: test_commands_template_custom_layer_name

    def test_commands_template_custom_layer_name(self):
        tmpl = view.template('ptah.view:/tests/templates/test.pt',
                             layer = 'test-unknown')

        sys.argv[:] = ['paste', 'templates', '-l', 'test-unknown']

        val = self._run()
开发者ID:mcdonc,项目名称:ptah,代码行数:7,代码来源:test_commands.py

示例8: test_customize_global_reenable

    def test_customize_global_reenable(self):
        self._mkfile1(self.file1)
        self._mkfile2(self.file2)

        f = open(os.path.join(self.dir2, 'test'), 'wb')
        f.write(' ')
        f.close()

        tmpl = view.template(os.path.join(self.dir1, 'file.pt'))
        self.assertEqual(tmpl(), '<div>Test template 1</div>')

        # load without watcher
        self._init_ptah({'template.custom': os.path.join(self.dir2, 'test')})

        self.assertTrue(customize.TEMPLATE._manager is None)
        self.assertTrue(customize.TEMPLATE._watcher is None)
        self.assertEqual(tmpl(), '<div>Test template 1</div>')

        # reinitialize
        customize.TEMPLATE['custom'] = self.dir2
        customize.TEMPLATE['watcher'] = ''
        customize.initialize(config.SettingsInitializing(object()))

        self.assertTrue(customize.TEMPLATE._manager is not None)
        self.assertTrue(customize.TEMPLATE._watcher is None)

        self.assertEqual(tmpl(), '<div>Test template 2</div>')
开发者ID:mcdonc,项目名称:ptah,代码行数:27,代码来源:test_customize.py

示例9: test_customize_global_createfolder_and_reloadpackage

    def test_customize_global_createfolder_and_reloadpackage(self):
        self._mkfile1(self.file1)

        tmpl = view.template(os.path.join(self.dir1, 'file.pt'))
        self.assertEqual(tmpl(), '<div>Test template 1</div>')

        self.dir2 = os.path.join(self.dir2, 'test')

        # enable custom folder
        self._init_ptah({'template.custom': self.dir2})

        self.assertTrue(os.path.isdir(self.dir2))
        self.assertEqual(tmpl(), '<div>Test template 1</div>')

        # create new custom resource
        os.mkdir(os.path.join(self.dir2, 'ptah.view.tests'))
        self._mkfile2(self.file2)
        time.sleep(0.1)

        # template reloaded
        self.assertEqual(tmpl(), '<div>Test template 2</div>')

        # remove template
        shutil.rmtree(os.path.join(self.dir2, 'ptah.view.tests'))

        time.sleep(0.1)
        self.assertEqual(tmpl(), '<div>Test template 1</div>')
开发者ID:mcdonc,项目名称:ptah,代码行数:27,代码来源:test_customize.py

示例10: test_view_with_template

    def test_view_with_template(self):
        view.register_view(
            'index.html', view.View, Context,
            template=view.template('ptah.view.tests:templates/test.pt'))

        self._init_ptah()

        res = view.render_view('index.html', Context(), self.request)
        self.assertEqual(res.body.strip(), '<div>My snippet</div>')
开发者ID:mcdonc,项目名称:ptah,代码行数:9,代码来源:test_view.py

示例11: test_customize_global_enabled

    def test_customize_global_enabled(self):
        self._mkfile1(self.file1)
        self._mkfile2(self.file2)

        tmpl = view.template(os.path.join(self.dir1, 'file.pt'))
        self.assertEqual(tmpl(), '<div>Test template 1</div>')

        # enable custom folder
        self._init_ptah({'template.custom': self.dir2})
开发者ID:mcdonc,项目名称:ptah,代码行数:9,代码来源:test_customize.py

示例12: test_renderer_tmpl

    def test_renderer_tmpl(self):
        def viewFactory(context, request):
            return None, {}

        r = Renderer(template=view.template('templates/test.pt'))
        res = r(Context(), self.request, viewFactory)

        self.assertTrue(isinstance(res, Response))
        self.assertEqual(res.body.strip(), '<div>My snippet</div>')
        self.assertEqual(res.status, '200 OK')
        self.assertEqual(res.content_type, 'text/html')
开发者ID:mcdonc,项目名称:ptah,代码行数:11,代码来源:test_renderers.py

示例13: test_view_register_view_function_requestonly_template

    def test_view_register_view_function_requestonly_template(self):
        def render(request):
            return {}

        view.register_view('index.html', render,
                          template = view.template('templates/test.pt'))
        self._init_ptah()

        context = Context()
        v = self._view('index.html', context, self.request)
        self.assertEqual(v.body.strip(), '<div>My snippet</div>')
开发者ID:mcdonc,项目名称:ptah,代码行数:11,代码来源:test_view.py

示例14: test_view_httpresp_from_update

    def test_view_httpresp_from_update(self):
        class MyView(view.View):
            def update(self):
                raise HTTPForbidden()

        view.register_view('index.html', MyView, Context,
                          template = view.template('templates/test.pt'))
        self._init_ptah()

        resp = view.render_view('index.html', Context(), self.request)
        self.assertIsInstance(resp, HTTPForbidden)
开发者ID:mcdonc,项目名称:ptah,代码行数:11,代码来源:test_view.py

示例15: test_renderer_tmpl_with_layout

    def test_renderer_tmpl_with_layout(self):
        class Layout(view.Layout):
            def render(self, content):
                return '<html>%s</html>'%content

        view.register_layout('test', klass=Layout)
        self._init_ptah()

        def viewFactory(context, request):
            return None, {}

        # renderer layout is different
        r = Renderer(view.template('templates/test.pt'), '')
        res = r(Context(), self.request, viewFactory)
        self.assertEqual(res.body.strip(), '<div>My snippet</div>')

        # layout is 'test'
        config.cleanup_system()
        r = Renderer(view.template('templates/test.pt'), 'test')
        res = r(Context(), self.request, viewFactory)
        self.assertEqual(''.join(res.body.split()), '<html><div>Mysnippet</div></html>')
开发者ID:mcdonc,项目名称:ptah,代码行数:21,代码来源:test_renderers.py


注:本文中的ptah.view.template函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。