Skip to content

Commit

Permalink
Replace webhelpers.html.tags.literal
Browse files Browse the repository at this point in the history
  • Loading branch information
smotornyuk committed Nov 21, 2019
1 parent 9213571 commit dfd93ee
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
3 changes: 1 addition & 2 deletions ckan/lib/base.py
Expand Up @@ -14,7 +14,6 @@
from pylons.controllers.util import abort as _abort
from pylons.decorators import jsonify
from pylons.templating import cached_template, pylons_globals
from webhelpers.html import literal
from jinja2.exceptions import TemplateNotFound

from flask import (
Expand Down Expand Up @@ -100,7 +99,7 @@ def render_snippet(*template_names, **kw):
output = (
'\n<!-- Snippet %s start -->\n%s\n<!-- Snippet %s end -->'
'\n' % (template_name, output, template_name))
return literal(output)
return h.literal(output)
except TemplateNotFound as exc:
if exc.name == template_name:
# the specified template doesn't exist - try the next fallback
Expand Down
19 changes: 16 additions & 3 deletions ckan/lib/helpers.py
Expand Up @@ -17,7 +17,7 @@
import uuid

from paste.deploy import converters
from webhelpers.html import HTML, literal, tags, tools
from webhelpers.html import HTML, tags, tools
from webhelpers import paginate
import webhelpers.text as whtext
import webhelpers.date as date
Expand Down Expand Up @@ -109,6 +109,19 @@ def __getitem__(self, key):
helper_functions = HelperAttributeDict()


class literal(markupsafe.Markup):
"""Represents an HTML literal.
"""
__slots__ = ()

@classmethod
def escape(cls, s):
if s is None:
return EMPTY
return super(literal, cls).escape(s)


def core_helper(f, name=None):
"""
Register a function as a builtin helper method.
Expand Down Expand Up @@ -1207,7 +1220,7 @@ def linked_user(user, maxlength=0, avatar=20):
if maxlength and len(user.display_name) > maxlength:
displayname = displayname[:maxlength] + '...'

return tags.literal(u'{icon} {link}'.format(
return literal(u'{icon} {link}'.format(
icon=gravatar(
email_hash=user.email_hash,
size=avatar
Expand Down Expand Up @@ -2640,7 +2653,7 @@ def clean_html(html):
core_helper(i18n.get_available_locales)
core_helper(i18n.get_locales_dict)
# Useful additions from the webhelpers library.
core_helper(tags.literal)
core_helper(literal)
core_helper(tags.link_to)
core_helper(tags.file)
core_helper(tags.submit)
Expand Down
3 changes: 1 addition & 2 deletions ckan/plugins/toolkit.py
Expand Up @@ -148,7 +148,6 @@ def _initialize(self):

import ckan.common as converters
import pylons
import webhelpers.html.tags

# Allow class access to these modules
self.__class__.ckan = ckan
Expand Down Expand Up @@ -234,7 +233,7 @@ def _initialize(self):
For example: ``bar = toolkit.aslist(config.get('ckan.foo.bar', []))``
'''
t['literal'] = webhelpers.html.tags.literal
t['literal'] = h.literal

t['get_action'] = logic.get_action
t['chained_action'] = logic.chained_action
Expand Down

0 comments on commit dfd93ee

Please sign in to comment.