예제 #1
0
def test_truncate_purified_field_xss():
    """Truncating should not introduce xss issues."""
    s = 'safe <script>alert("omg")</script>'
    t = PurifiedTranslation(localized_string=s)
    actual = env.from_string('{{ s|truncate(100) }}').render({'s': t})
    eq_(actual, 'safe &lt;script&gt;alert("omg")&lt;/script&gt;')
    actual = env.from_string('{{ s|truncate(5) }}').render({'s': t})
    eq_(actual, 'safe ...')
예제 #2
0
def test_truncate_purified_field_xss():
    """Truncating should not introduce xss issues."""
    s = 'safe <script>alert("omg")</script>'
    t = PurifiedTranslation(localized_string=s)
    actual = env.from_string('{{ s|truncate(100) }}').render({'s': t})
    eq_(actual, 'safe &lt;script&gt;alert("omg")&lt;/script&gt;')
    actual = env.from_string('{{ s|truncate(5) }}').render({'s': t})
    eq_(actual, 'safe ...')
예제 #3
0
def rendered_content(self):
    from mkt.site.utils import env  # django import order LOL :-(
    template = self.template_name
    context_instance = self.resolve_context(self.context_data)
    request = context_instance['request']

    # Gross, let's figure out if we're in the admin.
    if self._current_app == 'admin':
        source = loader.render_to_string(template, context_instance)
        template = env.from_string(source)
        # This interferes with our media() helper.
        if 'media' in self.context_data:
            del self.context_data['media']

    # ``render_to_string`` only accepts a Template instance or a template name,
    # not a list.
    if isinstance(template, (list, tuple)):
        template = loader.select_template(template)
    return jingo.render_to_string(request, template, self.context_data)
예제 #4
0
파일: __init__.py 프로젝트: wangeek/zamboni
def rendered_content(self):
    from mkt.site.utils import env  # django import order LOL :-(
    template = self.template_name
    if 'user' not in self.context_data:
        self.context_data['user'] = self._request.user
    context_instance = self.resolve_context(self.context_data)

    # Gross, let's figure out if we're in the admin.
    if getattr(self._request, 'current_app', None) == 'admin':
        source = loader.render_to_string(
            template, RequestContext(self._request, context_instance))
        template = env.from_string(source)
        # This interferes with our media() helper.
        if 'media' in self.context_data:
            del self.context_data['media']

    # ``render_to_string`` only accepts a Template instance or a template name,
    # not a list.
    if isinstance(template, (list, tuple)):
        template = loader.select_template(template)
    if isinstance(template, Template):
        template = template.template
    return jingo.render_to_string(self._request, template, self.context_data)
예제 #5
0
def rendered_content(self):
    from mkt.site.utils import env  # django import order LOL :-(
    template = self.template_name
    if 'user' not in self.context_data:
        self.context_data['user'] = self._request.user
    context_instance = self.resolve_context(self.context_data)

    # Gross, let's figure out if we're in the admin.
    if getattr(self._request, 'current_app', None) == 'admin':
        source = loader.render_to_string(
            template, RequestContext(self._request, context_instance))
        template = env.from_string(source)
        # This interferes with our media() helper.
        if 'media' in self.context_data:
            del self.context_data['media']

    # ``render_to_string`` only accepts a Template instance or a template name,
    # not a list.
    if isinstance(template, (list, tuple)):
        template = loader.select_template(template)
    if isinstance(template, Template):
        template = template.template
    return jingo.render_to_string(self._request, template,
                                  self.context_data)
예제 #6
0
def test_truncate_purified_field():
    s = '<i>one</i><i>two</i>'
    t = PurifiedTranslation(localized_string=s)
    actual = env.from_string('{{ s|truncate(6) }}').render({'s': t})
    eq_(actual, s)
예제 #7
0
def render(s, context={}):
    return env.from_string(s).render(context)
예제 #8
0
 def render(self, s, context={}):
     t = env.from_string(s)
     return t.render(context)
예제 #9
0
def test_truncate_purified_field():
    s = '<i>one</i><i>two</i>'
    t = PurifiedTranslation(localized_string=s)
    actual = env.from_string('{{ s|truncate(6) }}').render({'s': t})
    eq_(actual, s)
예제 #10
0
def render(s, context={}):
    return env.from_string(s).render(context)