示例#1
0
 def render_template(self, endpoint, **kwargs):
     try:
         return getcontent(endpoint, **kwargs)
     except TemplateNotFound:
         if ':' in endpoint:
             raise
         return getcontent('{0}:{1}'.format(self.component, endpoint), **kwargs)
示例#2
0
 def render_template(self, endpoint, **kwargs):
     try:
         return getcontent(endpoint, **kwargs)
     except TemplateNotFound:
         if ':' in endpoint:
             raise
         return getcontent('{0}:{1}'.format(self.component, endpoint), **kwargs)
示例#3
0
    def test_endpoint_template_variable(self):
        try:
            # had to switch the variable name, we are just identifying the problem
            # with this test
            c = getcontent('getcontent.html', __endpoint='foo')
            assert False
        except TypeError as e:
            msg_str = str(e)
            assert msg_str.startswith("getcontent() got multiple values for ")
            assert msg_str.endswith("'__endpoint'")

        c = getcontent('getcontent.html', endpoint='foo')
        assert c.primary == 'the endpoint: foo', c.primary
示例#4
0
    def test_endpoint_template_variable(self):
        try:
            # had to switch the variable name, we are just identifying the problem
            # with this test
            c = getcontent('getcontent.html', __endpoint='foo')
            assert False
        except TypeError as e:
            msg_str = str(e)
            assert msg_str.startswith("getcontent() got multiple values for ")
            assert msg_str.endswith("'__endpoint'")

        c = getcontent('getcontent.html', endpoint='foo')
        assert c.primary == 'the endpoint: foo', c.primary
示例#5
0
 def test_page_methods_are_not_autoescaped(self):
     c = getcontent('nesting_content.html', endpoint='foo')
     body = c.primary
     # JS
     assert '// no & autoescape' in body, body
     # CSS
     assert '/* no & autoescape */' in body, body
示例#6
0
    def test_page_method_formatting(self):
        c = getcontent('nesting_content2.html')
        icss = '/* nesting_content2.css */\n' +\
               '        \n' + \
               '        /* nesting_content3.css */'
        css = '/* nesting_content2.css */\n\n/* nesting_content3.css */'

        ijs = '// nesting_content2.js\n' +\
              '        \n' + \
              '        // nesting_content3.js'
        js = '// nesting_content2.js\n\n// nesting_content3.js'

        # re-indent levels are set through the placeholder method
        c.page_css_ph()
        c.page_js_ph()

        assert icss == c.css_ph.content(), c.css_ph.content()
        assert ijs == c.js_ph.content(), repr(c.js_ph.content())

        # re-indent levels are set through the placeholder method
        c.page_css_ph(reindent=None)
        c.page_js_ph(reindent=None)

        assert css == c.css_ph.content()
        assert js == c.js_ph.content(), repr(c.js_ph.content())
示例#7
0
 def test_page_methods_are_not_autoescaped(self):
     c = getcontent('nesting_content.html', endpoint='foo')
     body = c.primary
     # JS
     assert '// no & autoescape' in body, body
     # CSS
     assert '/* no & autoescape */' in body, body
示例#8
0
    def test_context_variable_takes_precedence(self):
        user.name = 'foo'

        class MyUser(object):
            name = 'bar'
        c = getcontent('user_test.html', user=MyUser())
        assert c.primary == 'user\'s name: bar', c.primary
示例#9
0
    def test_include_markdown(self):
        c = getcontent('include_mkdn.html')
        eq_(
            c.primary, """
<p>from <em>include_mkdn.mkdn</em></p>
<p>from <em>include_mkdn.mkdn</em></p>
""".lstrip())
示例#10
0
    def test_include_rst(self):
        c = getcontent('include_rst.html')
        eq_(
            c.primary, """
<p>from <em>include_rst.rst</em></p>
<p>from <em>include_rst.rst</em></p>
""".lstrip())
示例#11
0
    def test_page_method_formatting(self):
        c = getcontent('nesting_content2.html')
        icss = '/* nesting_content2.css */\n' +\
               '        \n' + \
               '        /* nesting_content3.css */'
        css = '/* nesting_content2.css */\n\n/* nesting_content3.css */'

        ijs = '// nesting_content2.js\n' +\
              '        \n' + \
              '        // nesting_content3.js'
        js = '// nesting_content2.js\n\n// nesting_content3.js'

        # re-indent levels are set through the placeholder method
        c.page_css_ph()
        c.page_js_ph()

        assert icss == c.css_ph.content(), c.css_ph.content()
        assert ijs == c.js_ph.content(), repr(c.js_ph.content())

        # re-indent levels are set through the placeholder method
        c.page_css_ph(reindent=None)
        c.page_js_ph(reindent=None)

        assert css == c.css_ph.content()
        assert js == c.js_ph.content(), repr(c.js_ph.content())
示例#12
0
 def test_direct_includes(self):
     c = getcontent('direct_include.html')
     body = c.primary
     assert 'nesting_content2.html' in body, body
     assert 'nesting_content3.html' in body, body
     assert '/* nesting_content2.css */' in body, body
     assert '// nesting_content2.js' in body
     assert '/* nesting_content3.css */' in body, body
示例#13
0
 def test_direct_includes(self):
     c = getcontent('direct_include.html')
     body = c.primary
     assert 'nesting_content2.html' in body, body
     assert 'nesting_content3.html' in body, body
     assert '/* nesting_content2.css */' in body, body
     assert '// nesting_content2.js' in body
     assert '/* nesting_content3.css */' in body, body
示例#14
0
    def test_context_variable_takes_precedence(self):
        user.name = 'foo'

        class MyUser(object):
            name = 'bar'

        c = getcontent('user_test.html', user=MyUser())
        assert c.primary == 'user\'s name: bar', c.primary
示例#15
0
    def test_include_markdown(self):
        c = getcontent('include_mkdn.html')
        eq_(
            c.primary,
            """
<p>from <em>include_mkdn.mkdn</em></p>
<p>from <em>include_mkdn.mkdn</em></p>
""".lstrip()
        )
示例#16
0
    def test_super(self):
        """
            test_super

            had a problem with the way we wrapped block rendering functions
            which resulted in super() not working
        """
        c = getcontent('test_super.html')
        eq_(c.primary.strip(), 'The Title |')
示例#17
0
    def test_super(self):
        """
            test_super

            had a problem with the way we wrapped block rendering functions
            which resulted in super() not working
        """
        c = getcontent('test_super.html')
        eq_(c.primary.strip(), 'The Title |')
示例#18
0
    def test_include_rst(self):
        c = getcontent('include_rst.html')
        eq_(
            c.primary,
            """
<p>from <em>include_rst.rst</em></p>
<p>from <em>include_rst.rst</em></p>
""".lstrip()
        )
示例#19
0
 def test_content_filter(self):
     def get_nesting_content2():
         return getcontent('nesting_content2.html')
     c = getcontent('content_filter.html', get_nesting_content2=get_nesting_content2)
     body = c.primary
     assert 'content filter' in body, body
     assert 'nesting_content2.html' in body, body
     assert 'nesting_content3.html' in body, body
     assert '/* nesting_content2.css */' in body, body
     assert '// nesting_content2.js' in body
     assert '/* nesting_content3.css */' in body, body
示例#20
0
 def test_css_and_js_urls(self):
     c = getcontent('nesting_content.html', endpoint='foo')
     body = c.primary
     assert '/* nesting_content.css */' in body
     assert '// nesting_content.js' in body
     assert 'nesting_content.htmlnesting_content2.html' in body, body
     assert 'nesting_content2.html' in body, body
     assert 'nc2 arg1: foo' in body, body
     assert '/* nesting_content2.css */' in body, body
     assert body.count('nesting_content2.html') == 1, body
     assert 'nesting_content3.html' in body, body
     assert '/* nesting_content3.css */' in body, body
示例#21
0
 def test_css_and_js_urls(self):
     c = getcontent('nesting_content.html', endpoint='foo')
     body = c.primary
     assert '/* nesting_content.css */' in body
     assert '// nesting_content.js' in body
     assert 'nesting_content.htmlnesting_content2.html' in body, body
     assert 'nesting_content2.html' in body, body
     assert 'nc2 arg1: foo' in body, body
     assert '/* nesting_content2.css */' in body, body
     assert body.count('nesting_content2.html') == 1, body
     assert 'nesting_content3.html' in body, body
     assert '/* nesting_content3.css */' in body, body
示例#22
0
    def test_content_filter(self):
        def get_nesting_content2():
            return getcontent('nesting_content2.html')

        c = getcontent('content_filter.html',
                       get_nesting_content2=get_nesting_content2)
        body = c.primary
        assert 'content filter' in body, body
        assert 'nesting_content2.html' in body, body
        assert 'nesting_content3.html' in body, body
        assert '/* nesting_content2.css */' in body, body
        assert '// nesting_content2.js' in body
        assert '/* nesting_content3.css */' in body, body
示例#23
0
 def test_script_and_link_tags(self):
     c = getcontent('nesting_content.html', endpoint='foo')
     body = c.primary
     assert '<link href="/static/linked_nesting_content.css" rel="stylesheet" ' \
         'type="text/css" />' in body, body
     assert '<script src="/static/linked_nesting_content.js" type="text/javascript">' \
         '</script>' in body, body
     assert '<link href="static/linked_nesting_content_rel.css" rel="stylesheet" ' \
         'type="text/css" />' in body, body
     assert '<script src="static/linked_nesting_content_rel.js" type="text/javascript">' \
         '</script>' in body, body
     assert '<link charset="utf-8" href="/static/linked_nesting_content3.css" media="print" ' \
         'rel="stylesheet" type="text/css" />' in body, body
     assert '<script src="/static/linked_nesting_content3.js" type="text/javascript">' \
         '</script>' in body, body
     # make sure the template functions are returning empty strings and not
     # None
     assert 'None' not in body, body
示例#24
0
 def test_script_and_link_tags(self):
     c = getcontent('nesting_content.html', endpoint='foo')
     body = c.primary
     assert '<link href="/static/linked_nesting_content.css" rel="stylesheet" ' \
         'type="text/css" />' in body, body
     assert '<script src="/static/linked_nesting_content.js" type="text/javascript">' \
         '</script>' in body, body
     assert '<link href="static/linked_nesting_content_rel.css" rel="stylesheet" ' \
         'type="text/css" />' in body, body
     assert '<script src="static/linked_nesting_content_rel.js" type="text/javascript">' \
         '</script>' in body, body
     assert '<link charset="utf-8" href="/static/linked_nesting_content3.css" media="print" ' \
         'rel="stylesheet" type="text/css" />' in body, body
     assert '<script src="/static/linked_nesting_content3.js" type="text/javascript">' \
         '</script>' in body, body
     # make sure the template functions are returning empty strings and not
     # None
     assert 'None' not in body, body
示例#25
0
    def render_endpoint(self, endpoint, send_response=True):
        """
            Render a template or Content object by endpoint:

            # look for a template file by endpoint, useful if you need a
            # template from another component:
            self.render_endpoint('othercomponent:some_template.html')

            # or if the view is component level and a template from the main
            # application is needed.
            self.render_endpoint('app_level.html')

            # a Content object can also be rendered by omitting an extension:
            self.render_endpoint('mycomponent:SomeContent')
        """
        c = getcontent(endpoint, **self.template_vars)
        self.retval = c
        if send_response:
            self.send_response()
        return c
示例#26
0
文件: views.py 项目: level12/blazeweb
    def render_endpoint(self, endpoint, send_response=True):
        """
            Render a template or Content object by endpoint:

            # look for a template file by endpoint, useful if you need a
            # template from another component:
            self.render_endpoint('othercomponent:some_template.html')

            # or if the view is component level and a template from the main
            # application is needed.
            self.render_endpoint('app_level.html')

            # a Content object can also be rendered by omitting an extension:
            self.render_endpoint('mycomponent:SomeContent')
        """
        c = getcontent(endpoint, **self.template_vars)
        self.retval = c
        if send_response:
            self.send_response()
        return c
示例#27
0
 def get_nesting_content2():
     return getcontent('nesting_content2.html')
示例#28
0
 def test_included_content_default_safe(self):
     c = getcontent('nesting_content.html', endpoint='foo')
     assert 'nc2 autoescape: &amp; False' in c.primary, c.primary
示例#29
0
 def test_template_usage(self):
     c = getcontent('index.html', a='foo')
     assert c.primary == 'app index: foo', c.primary
示例#30
0
 def test_class_usage(self):
     c = getcontent('HelloWorld')
     assert c.primary == 'hello world', c.primary
示例#31
0
 def test_user_proxy_in_template(self):
     c = getcontent('user_proxy_test.html')
     # user is not authenticated, so we should see False twice
     assert 'False\nFalse' in c.primary
示例#32
0
 def test_user_proxy_in_template(self):
     c = getcontent('user_proxy_test.html')
     # user is not authenticated, so we should see False twice
     assert 'False\nFalse' in c.primary
示例#33
0
 def test_include_markdown_not_found(self):
     getcontent('include_mkdn_nf.html')
示例#34
0
 def test_include_markdown_not_found(self):
     getcontent('include_mkdn_nf.html')
示例#35
0
 def test_template_usage(self):
     c = getcontent('index.html', a='foo')
     assert c.primary == 'app index: foo', c.primary
示例#36
0
 def test_class_usage(self):
     c = getcontent('HelloWorld')
     assert c.primary == 'hello world', c.primary
示例#37
0
def send_reset_password_email(user_obj):
    subject = '%s - User Password Reset' % (settings.name.full)
    body = getcontent('auth:password_reset_email.txt',
                      user_obj=user_obj).primary
    email = EmailMessage(subject, body, None, [user_obj.email_address])
    return send_email_or_log_error(email)
示例#38
0
 def default(self):
     self.retval = getcontent('tests:HwSnippet').primary
示例#39
0
 def test_in_request_usage(self):
     user.name = 'foo'
     c = getcontent('user_test.html')
     assert c.primary == 'user\'s name: foo', c.primary
示例#40
0
 def test_rg_usage(self):
     rg.test_prop = 'Testing Property'
     c = getcontent('rg_test.html')
     assert c.primary == 'rg.test_prop: Testing Property', c.primary
示例#41
0
文件: views.py 项目: level12/blazeweb
 def default(self):
     self.assign('output', getcontent('tests:text_snippet.txt'))
     self.render_template(default_ext='txt')
示例#42
0
 def default(self):
     self.assign('output', getcontent('tests:text_snippet.txt'))
     self.render_template(default_ext='txt')
示例#43
0
def send_new_user_email(user_obj):
    subject = '%s - User Login Information' % (settings.name.full)
    body = getcontent('auth:new_user_email.txt', user_obj=user_obj).primary
    email = EmailMessage(subject, body, None, [user_obj.email_address])
    return send_email_or_log_error(email)
示例#44
0
 def test_in_request_usage(self):
     user.name = 'foo'
     c = getcontent('user_test.html')
     assert c.primary == 'user\'s name: foo', c.primary
示例#45
0
文件: views.py 项目: level12/blazeweb
 def default(self):
     self.retval = getcontent('tests:HwSnippet').primary
示例#46
0
 def test_rg_usage(self):
     rg.test_prop = 'Testing Property'
     c = getcontent('rg_test.html')
     assert c.primary == 'rg.test_prop: Testing Property', c.primary
示例#47
0
 def test_included_content_default_safe(self):
     c = getcontent('nesting_content.html', endpoint='foo')
     assert 'nc2 autoescape: &amp; False' in c.primary, c.primary
示例#48
0
 def get_nesting_content2():
     return getcontent('nesting_content2.html')