django.utils.html.mark_safe - python examples

Here are the examples of the python api django.utils.html.mark_safe taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

71 Examples 7

3 View Complete Implementation : renderers.py
Copyright Apache License 2.0
Author : BeanWei
    def render(self, data, accepted_media_type=None, renderer_context=None):
        codec = coreapi.codecs.CoreJSONCodec()
        schema = base64.b64encode(codec.encode(data)).decode('ascii')

        template = loader.get_template(self.template)
        context = {'schema': mark_safe(schema)}
        request = renderer_context['request']
        return template.render(context, request=request)

3 View Complete Implementation : bool_fa.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
@register.filter(name='bool_fa')
def bool_fa(boolean):
    if boolean:
        return mark_safe('<i clast="fa fa-check-circle"></i>')
    else:
        return mark_safe('<i clast="fa fa-times-circle"></i>')

3 View Complete Implementation : hooks.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
@register.simple_tag(takes_context=True)
def hook(context, hook_name):
    try:
        html = ''
        for hook in settings.PLUGIN_HOOKS.get(hook_name, []):
            hook_module = import_module(hook.get('module'))
            function = getattr(hook_module, hook.get('function'))
            html = html + function(context)

        return mark_safe(html)
    except BaseException as e:
        # This is a broad exception to stop a plugin breaking the site.
        if settings.DEBUG:
            print('Error rendering hook {0}: {1}'.format(hook_name, e))

3 View Complete Implementation : jinja2.py
Copyright MIT License
Author : codeforamerica
def contact_info_to_html(contact_info_dict):
    phone = contact_info_dict.get('sms', '')
    if phone:
        phone = format_phone_number(phone)
    email = contact_info_dict.get('email', '')

    html = oxford_comma([
        thing for thing in (phone, email) if thing])
    return mark_safe(html)

3 View Complete Implementation : admin.py
Copyright MIT License
Author : dellsystem
    def display_tag(self, obj):
        return mark_safe(
            '<a clast="ui large {c} label" href="{u}">{s}</a>'.format(
                c=obj.get_colour(),
                u=reverse('admin:books_tag_change', args=[obj.id]),
                s=obj,
            )
        )

3 View Complete Implementation : widgets_old.py
Copyright MIT License
Author : dima-kov
    def make_script_vars(self, name):
        context = self.process_croppie_context(name)
        vars = 'var croppieFieldName = "{}"\n var croppieOptions = {}' \
            .format(
                context['croppie_field_name'],
                context['croppie_options'],
            )
        return mark_safe(vars)

3 View Complete Implementation : views.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : django-functest
    def as_p(self):
        retval = super(AddSpacersMixin, self).as_p()
        if self.add_spacers:
            # Hack to help test interacting with elements
            # that aren't in view.
            retval = mark_safe(retval.replace('</p>', '</p>' + ('<br>' * 100)))
        return retval

3 View Complete Implementation : common_tags.py
Copyright GNU Affero General Public License v3.0
Author : freedomofpress
@register.filter
def richtext_inline(value):
    "Returns HTML-formatted rich text stripped of block level elements"
    text = richtext(value)
    return mark_safe(bleach.clean(
        text,
        strip=True,
        tags=[
            'a', 'abbr', 'acronym', 'b', 'code', 'em', 'i', 'strong', 'span'
        ]
    ))

3 View Complete Implementation : website_app.py
Copyright Apache License 2.0
Author : google
@register.simple_tag
def request_solution(script):
  subject = "Request For A %s StarThinker Solution" % script.get_name()
  body = "Hi,\n\nI'd like to learn more about the %s solution.\n\nStarThinker Link: %s\n\nCan we set up some time to over it?\n\nThanks" % (
    script.get_name(),
    script.get_link()
  )
  return mark_safe('mailto:%s?subject=%s&body=%s' % (
    ','.join(script.get_authors()).replace(' ', ''), 
    quote_plus(subject),
    quote_plus(body)
  ))

3 View Complete Implementation : website_app.py
Copyright Apache License 2.0
Author : google
@register.simple_tag
def mailto(emails, subject='', body=''):
  return mark_safe('mailto:%s?subject=%s&body=%s' % (
    ','.join(emails).replace(' ', ''), 
    quote_plus(subject),
    quote_plus(body)
  ))