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


Python html.conditional_escape方法代码示例

本文整理汇总了Python中django.utils.html.conditional_escape方法的典型用法代码示例。如果您正苦于以下问题:Python html.conditional_escape方法的具体用法?Python html.conditional_escape怎么用?Python html.conditional_escape使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.utils.html的用法示例。


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

示例1: field_display

# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import conditional_escape [as 别名]
def field_display(field, safe=False):
    out = []
    if isinstance(field.field.widget, (forms.widgets.RadioSelect, forms.widgets.CheckboxSelectMultiple)):
        out.append('<div class="field radio">%s</div>' % (str(field)))
    else:
        out.append('<div class="field">%s</div>' % (str(field)))
    out.append(str(field.errors))

    if field.help_text:
        if isinstance(field.help_text, Promise):
            out.append('<div class="helptext">%s</div>' % (escape(field.help_text)))
        else:
            if safe:
                out.append('<div class="helptext">%s</div>' % (field.help_text))
            else:
                out.append('<div class="helptext">%s</div>' % (escape(field.help_text)))
    return mark_safe('\n'.join(out)) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:19,代码来源:form_display.py

示例2: label_display

# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import conditional_escape [as 别名]
def label_display(field, prefix=''):
    out = []

    labelid = str(field.name)
    if prefix:
        labelid = prefix + '-' + labelid
    if isinstance(field.field.widget, (RadioSelect, SupervisorWidget)):
        labelid += '_0'

    out.append('<label for="id_%s">' % (labelid,))
    out.append(escape(field.label))
    out.append(':')
    if field.field.required or (hasattr(field.field, 'force_display_required') and field.field.force_display_required):
        out.append('&nbsp;' + required_icon)

    out.append('</label>')

    return mark_safe(''.join(out)) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:20,代码来源:form_display.py

示例3: to_html

# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import conditional_escape [as 别名]
def to_html(self, fieldsubmission=None):

        the_choices = [(k, v) for k, v in self.config.items() if k.startswith("choice_") and self.config[k]]
        the_choices = sorted(the_choices, key=lambda choice: (int) (re.findall(r'\d+', choice[0])[0]))

        initial = []

        if fieldsubmission:
            initial = fieldsubmission.data['info']

        display_values = [dict(the_choices)[str(i)] for i in initial]

        if display_values:
            output = '<ul>'

            for item in display_values:
                output += '<li>%s</li>' % escape(str(item))
            output += '</ul>'
        else:
            output = '<p class="empty">None selected</p>'

        return mark_safe(output) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:24,代码来源:select.py

示例4: render

# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import conditional_escape [as 别名]
def render(self, name, value, attrs=None, renderer=None):
        name = str(name)
        substitutions = {
            'initial_text': self.initial_text,
            'input_text': self.input_text,
            'clear_template': '',
            'clear_checkbox_label': self.clear_checkbox_label,
        }
        template = '%(input)s'
        substitutions['input'] = super(forms.ClearableFileInput, self).render(name, value, attrs, renderer=renderer)

        if value and hasattr(value, "url"):
            template = self.template_with_initial
            substitutions['initial'] = ('<a href="%s">%s</a>'
                                        % (escape(value.file_sub.get_file_url()),
                                           escape(value.file_sub.display_filename())))
            if not self.is_required:
                checkbox_name = self.clear_checkbox_name(name)
                checkbox_id = self.clear_checkbox_id(checkbox_name)
                substitutions['clear_checkbox_name'] = escape(checkbox_name)
                substitutions['clear_checkbox_id'] = escape(checkbox_id)
                substitutions['clear'] = forms.CheckboxInput().render(checkbox_name, False, attrs={'id': checkbox_id})
                substitutions['clear_template'] = self.template_with_clear % substitutions

        return mark_safe(template % substitutions) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:27,代码来源:other.py

示例5: display_visas

# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import conditional_escape [as 别名]
def display_visas(person):
    visas = Visa.get_visas([person])
    if visas.count() > 1:
        result = '<a href="%s">More than one visa found</a>' % reverse('visas:list_all_visas', kwargs={'emplid':person.userid_or_emplid()})
        return mark_safe(result)

    elif visas.count() == 0:
        result = '<a href="%s">No visa found</a>' % reverse('visas:new_visa', kwargs={'emplid':person.userid_or_emplid()})
        return mark_safe(result)

    elif visas.count() == 1:
        visa = visas[0]

        result = ['<a href="', reverse('visas:edit_visa', kwargs={'visa_id': visa.id}), '" ',
                  e(add_visa_display_class(visa)),'>', e(visa.status),' valid from ', e(str(visa.start_date)), ' until ',
                  e(str(visa.end_date)), ' -- ', e(visa.get_validity()), '</a>']
        return mark_safe(''.join(result))

    else:
        return "Undefined visa error, please contact support." 
开发者ID:sfu-fas,项目名称:coursys,代码行数:22,代码来源:visa_display.py

示例6: settings_info

# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import conditional_escape [as 别名]
def settings_info():
    info = []
    info.append(('Deploy mode', settings.DEPLOY_MODE))
    info.append(('Database engine', settings.DATABASES['default']['ENGINE']))
    info.append(('Authentication Backends', settings.AUTHENTICATION_BACKENDS))
    info.append(('Cache backend', settings.CACHES['default']['BACKEND']))
    info.append(('Haystack engine', settings.HAYSTACK_CONNECTIONS['default']['ENGINE']))
    info.append(('Email backend', settings.EMAIL_BACKEND))
    if hasattr(settings, 'CELERY_EMAIL') and settings.CELERY_EMAIL:
        info.append(('Celery email backend', settings.CELERY_EMAIL_BACKEND))
    if hasattr(settings, 'CELERY_BROKER_URL'):
        info.append(('Celery broker', settings.CELERY_BROKER_URL.split(':')[0]))

    DATABASES = copy.deepcopy(settings.DATABASES)
    for d in DATABASES:
        if 'PASSWORD' in DATABASES[d]:
            DATABASES[d]['PASSWORD'] = '*****'
    info.append(('DATABASES',  mark_safe('<pre>'+escape(pprint.pformat(DATABASES))+'</pre>')))

    return info 
开发者ID:sfu-fas,项目名称:coursys,代码行数:22,代码来源:panel.py

示例7: get_owners_display

# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import conditional_escape [as 别名]
def get_owners_display(self, units):
        """
        HTML display of the owners list

        (some logic required since we want to link to faculty profiles if exists && permitted)
        """
        from django.utils.html import conditional_escape as escape
        from django.utils.safestring import mark_safe
        res = []
        for o in self.grantowner_set.all():
            p = o.person
            if Role.objects.filter(unit__in=units, role='FAC', person=p).exists():
                url = reverse('faculty:summary', kwargs={'userid': p.userid_or_emplid()})
                res.append('<a href="%s">%s</a>' %(escape(url), escape(o.person.name())))
            else:
                res.append(escape(o.person.name()))

        return mark_safe(', '.join(res)) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:20,代码来源:models.py

示例8: _get_new_field_html

# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import conditional_escape [as 别名]
def _get_new_field_html(self, field_name):
        try:
            f, attr, value = lookup_field(field_name, self.org_obj, self)
        except (AttributeError, ObjectDoesNotExist):
            return EMPTY_CHANGELIST_VALUE
        else:
            allow_tags = False
            if f is None:
                allow_tags = getattr(attr, 'allow_tags', False)
                boolean = getattr(attr, 'boolean', False)
                if boolean:
                    allow_tags = True
                    text = boolean_icon(value)
                else:
                    text = smart_text(value)
            else:
                if isinstance(f.rel, models.ManyToOneRel):
                    field_val = getattr(self.org_obj, f.name)
                    if field_val is None:
                        text = EMPTY_CHANGELIST_VALUE
                    else:
                        text = field_val
                else:
                    text = display_for_field(value, f)
            return mark_safe(text) if allow_tags else conditional_escape(text) 
开发者ID:stormsha,项目名称:StormOnline,代码行数:27,代码来源:editable.py

示例9: render

# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import conditional_escape [as 别名]
def render(self, name, value, attrs=None):
        substitutions = {
            'initial_text': self.initial_text,
            'input_text': self.input_text,
            'clear_template': '',
            'clear_checkbox_label': self.clear_checkbox_label,
        }
        template = '%(input)s'
        substitutions['input'] = super(ClearableFileInput, self).render(name, value, attrs)

        if self.is_initial(value):
            template = self.template_with_initial
            substitutions.update(self.get_template_substitution_values(value))
            if not self.is_required:
                checkbox_name = self.clear_checkbox_name(name)
                checkbox_id = self.clear_checkbox_id(checkbox_name)
                substitutions['clear_checkbox_name'] = conditional_escape(checkbox_name)
                substitutions['clear_checkbox_id'] = conditional_escape(checkbox_id)
                substitutions['clear'] = CheckboxInput().render(checkbox_name, False, attrs={'id': checkbox_id})
                substitutions['clear_template'] = self.template_with_clear % substitutions

        return mark_safe(template % substitutions) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:24,代码来源:widgets.py

示例10: contents

# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import conditional_escape [as 别名]
def contents(self):
        from django.contrib.admin.templatetags.admin_list import _boolean_icon
        from django.contrib.admin.views.main import EMPTY_CHANGELIST_VALUE
        field, obj, model_admin = self.field['field'], self.form.instance, self.model_admin
        try:
            f, attr, value = lookup_field(field, obj, model_admin)
        except (AttributeError, ValueError, ObjectDoesNotExist):
            result_repr = EMPTY_CHANGELIST_VALUE
        else:
            if f is None:
                boolean = getattr(attr, "boolean", False)
                if boolean:
                    result_repr = _boolean_icon(value)
                else:
                    result_repr = smart_text(value)
                    if getattr(attr, "allow_tags", False):
                        result_repr = mark_safe(result_repr)
                    else:
                        result_repr = linebreaksbr(result_repr)
            else:
                if isinstance(f.rel, ManyToManyRel) and value is not None:
                    result_repr = ", ".join(map(six.text_type, value.all()))
                else:
                    result_repr = display_for_field(value, f)
        return conditional_escape(result_repr) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:27,代码来源:helpers.py

示例11: render

# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import conditional_escape [as 别名]
def render(self, name, value, attrs=None):
        # render the hidden input first
        cachekey_field = super().render(name, value, attrs)

        # check if there is a cached file
        metadata = self.cache.metadata(value)
        if metadata is None:
            # if not, just return the hidden input
            return cachekey_field

        # or render the additional cached file
        return mark_safe(
            self.template_with_cachekey
            % {
                "file_name": conditional_escape(metadata["name"]),
                "cachekey_field": cachekey_field,
            }
        ) 
开发者ID:mozilla,项目名称:telemetry-analysis-service,代码行数:20,代码来源:widgets.py

示例12: label_tag

# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import conditional_escape [as 别名]
def label_tag(self):
        classes = []
        contents = conditional_escape(self.field.label)
        if self.is_checkbox:
            classes.append('vCheckboxLabel')

        if self.field.field.required:
            classes.append('required')
        if not self.is_first:
            classes.append('inline')
        attrs = {'class': ' '.join(classes)} if classes else {}
        # checkboxes should not have a label suffix as the checkbox appears
        # to the left of the label.
        return self.field.label_tag(
            contents=mark_safe(contents), attrs=attrs,
            label_suffix='' if self.is_checkbox else None,
        ) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:19,代码来源:helpers.py

示例13: contents

# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import conditional_escape [as 别名]
def contents(self):
        from django.contrib.admin.templatetags.admin_list import _boolean_icon
        field, obj, model_admin = self.field['field'], self.form.instance, self.model_admin
        try:
            f, attr, value = lookup_field(field, obj, model_admin)
        except (AttributeError, ValueError, ObjectDoesNotExist):
            result_repr = self.empty_value_display
        else:
            if f is None:
                boolean = getattr(attr, "boolean", False)
                if boolean:
                    result_repr = _boolean_icon(value)
                else:
                    if hasattr(value, "__html__"):
                        result_repr = value
                    else:
                        result_repr = linebreaksbr(value)
            else:
                if isinstance(f.remote_field, ManyToManyRel) and value is not None:
                    result_repr = ", ".join(map(str, value.all()))
                else:
                    result_repr = display_for_field(value, f, self.empty_value_display)
                result_repr = linebreaksbr(result_repr)
        return conditional_escape(result_repr) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:26,代码来源:helpers.py

示例14: user_display

# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import conditional_escape [as 别名]
def user_display(user):
    try:
        # Use django-user-accounts display function if available
        from account.utils import user_display as account_user_display
        return conditional_escape(account_user_display(user))
    except ImportError:
        return conditional_escape(user.username) 
开发者ID:pinax,项目名称:pinax-documents,代码行数:9,代码来源:pinax_documents_tags.py

示例15: render_column

# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import conditional_escape [as 别名]
def render_column(self, ra, column):
        if column == 'lump_sum_pay':
            return "${:,}".format(ra.lump_sum_pay)
        elif column == 'person':
            url = ra.get_absolute_url()
            name = ra.person.sortname()
            if ra.has_attachments():
                extra_string = '&nbsp; <i class="fa fa-paperclip" title="Attachment(s)"></i>'
            else:
                extra_string = ''
            return '<a href="%s">%s%s</a>' % (escape(url), escape(name), extra_string)
        elif column == 'unit':
            return ra.unit.label

        return str(getattr(ra, column)) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:17,代码来源:views.py


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