當前位置: 首頁>>代碼示例>>Python>>正文


Python defaultfilters.linebreaksbr方法代碼示例

本文整理匯總了Python中django.template.defaultfilters.linebreaksbr方法的典型用法代碼示例。如果您正苦於以下問題:Python defaultfilters.linebreaksbr方法的具體用法?Python defaultfilters.linebreaksbr怎麽用?Python defaultfilters.linebreaksbr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.template.defaultfilters的用法示例。


在下文中一共展示了defaultfilters.linebreaksbr方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: contents

# 需要導入模塊: from django.template import defaultfilters [as 別名]
# 或者: from django.template.defaultfilters import linebreaksbr [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

示例2: contents

# 需要導入模塊: from django.template import defaultfilters [as 別名]
# 或者: from django.template.defaultfilters import linebreaksbr [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

示例3: to_html

# 需要導入模塊: from django.template import defaultfilters [as 別名]
# 或者: from django.template.defaultfilters import linebreaksbr [as 別名]
def to_html(self, fieldsubmission=None):
        return mark_safe('<p>' + linebreaksbr(fieldsubmission.data['info'], autoescape=True) + '</p>') 
開發者ID:sfu-fas,項目名稱:coursys,代碼行數:4,代碼來源:text.py

示例4: __init__

# 需要導入模塊: from django.template import defaultfilters [as 別名]
# 或者: from django.template.defaultfilters import linebreaksbr [as 別名]
def __init__(self, *args, **kwargs):
        email_message = kwargs.pop('email_message', None)
        super(DraftDecisionForm, self).__init__(*args, **kwargs)
        self.fields['email_message'].initial = linebreaksbr(email_message) 
開發者ID:BirkbeckCTP,項目名稱:janeway,代碼行數:6,代碼來源:forms.py

示例5: edit_email_template

# 需要導入模塊: from django.template import defaultfilters [as 別名]
# 或者: from django.template.defaultfilters import linebreaksbr [as 別名]
def edit_email_template(request, template_code, subject=False):
    """
    Allows staff to edit email templates and subjects
    :param request: HttpRequest object
    :param template_code: string, name of the template to be edited
    :param subject: boolean, if True we are editing the subject field not the body
    :return: HttpResponse object
    """
    if subject:
        template_value = setting_handler.get_setting('email_subject', 'subject_{0}'.format(template_code),
                                                     request.journal, create=True)
    else:
        template_value = setting_handler.get_setting('email', template_code, request.journal, create=True)

    if template_value.setting.types == 'rich-text':
        template_value.value = linebreaksbr(template_value.value)

    edit_form = forms.EditKey(key_type=template_value.setting.types, value=template_value.value)

    if request.POST:
        value = request.POST.get('value')
        template_value.value = value
        template_value.save()

        cache.clear()

        return redirect(reverse('core_email_templates'))

    template = 'core/manager/email/edit_email_template.html'
    context = {
        'template_value': template_value,
        'edit_form': edit_form,
        'setting': template_value.setting,
    }

    return render(request, template, context) 
開發者ID:BirkbeckCTP,項目名稱:janeway,代碼行數:38,代碼來源:views.py

示例6: contents

# 需要導入模塊: from django.template import defaultfilters [as 別名]
# 或者: from django.template.defaultfilters import linebreaksbr [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 field in self.form.fields:
                widget = self.form[field].field.widget
                # This isn't elegant but suffices for contrib.auth's
                # ReadOnlyPasswordHashWidget.
                if getattr(widget, 'read_only', False):
                    return widget.render(field, value)
            if f is None:
                if getattr(attr, 'boolean', False):
                    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:PacktPublishing,項目名稱:Hands-On-Application-Development-with-PyCharm,代碼行數:31,代碼來源:helpers.py

示例7: contents

# 需要導入模塊: from django.template import defaultfilters [as 別名]
# 或者: from django.template.defaultfilters import linebreaksbr [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 = force_text(value)
                        if getattr(attr, "allow_tags", False):
                            warnings.warn(
                                "Deprecated allow_tags attribute used on %s. "
                                "Use django.utils.html.format_html(), format_html_join(), "
                                "or django.utils.safestring.mark_safe() instead." % attr,
                                RemovedInDjango20Warning
                            )
                            result_repr = mark_safe(value)
                        else:
                            result_repr = linebreaksbr(result_repr)
            else:
                if isinstance(f.remote_field, ManyToManyRel) and value is not None:
                    result_repr = ", ".join(map(six.text_type, 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:Yeah-Kun,項目名稱:python,代碼行數:36,代碼來源:helpers.py

示例8: contents

# 需要導入模塊: from django.template import defaultfilters [as 別名]
# 或者: from django.template.defaultfilters import linebreaksbr [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 = smart_text(value)
                        if getattr(attr, "allow_tags", False):
                            warnings.warn(
                                "Deprecated allow_tags attribute used on %s. "
                                "Use django.utils.safestring.format_html(), "
                                "format_html_join(), or mark_safe() instead." % attr,
                                RemovedInDjango20Warning
                            )
                            result_repr = mark_safe(value)
                        else:
                            result_repr = linebreaksbr(result_repr)
            else:
                if isinstance(f.remote_field, ManyToManyRel) and value is not None:
                    result_repr = ", ".join(map(six.text_type, value.all()))
                else:
                    result_repr = display_for_field(value, f, self.empty_value_display)
        return conditional_escape(result_repr) 
開發者ID:drexly,項目名稱:openhgsenti,代碼行數:35,代碼來源:helpers.py

示例9: test_newline

# 需要導入模塊: from django.template import defaultfilters [as 別名]
# 或者: from django.template.defaultfilters import linebreaksbr [as 別名]
def test_newline(self):
        self.assertEqual(linebreaksbr('line 1\nline 2'), 'line 1<br>line 2') 
開發者ID:nesdis,項目名稱:djongo,代碼行數:4,代碼來源:test_linebreaksbr.py

示例10: test_carriage

# 需要導入模塊: from django.template import defaultfilters [as 別名]
# 或者: from django.template.defaultfilters import linebreaksbr [as 別名]
def test_carriage(self):
        self.assertEqual(linebreaksbr('line 1\rline 2'), 'line 1<br>line 2') 
開發者ID:nesdis,項目名稱:djongo,代碼行數:4,代碼來源:test_linebreaksbr.py

示例11: test_carriage_newline

# 需要導入模塊: from django.template import defaultfilters [as 別名]
# 或者: from django.template.defaultfilters import linebreaksbr [as 別名]
def test_carriage_newline(self):
        self.assertEqual(linebreaksbr('line 1\r\nline 2'), 'line 1<br>line 2') 
開發者ID:nesdis,項目名稱:djongo,代碼行數:4,代碼來源:test_linebreaksbr.py

示例12: test_non_string_input

# 需要導入模塊: from django.template import defaultfilters [as 別名]
# 或者: from django.template.defaultfilters import linebreaksbr [as 別名]
def test_non_string_input(self):
        self.assertEqual(linebreaksbr(123), '123') 
開發者ID:nesdis,項目名稱:djongo,代碼行數:4,代碼來源:test_linebreaksbr.py

示例13: test_autoescape

# 需要導入模塊: from django.template import defaultfilters [as 別名]
# 或者: from django.template.defaultfilters import linebreaksbr [as 別名]
def test_autoescape(self):
        self.assertEqual(
            linebreaksbr('foo\n<a>bar</a>\nbuz'),
            'foo<br>&lt;a&gt;bar&lt;/a&gt;<br>buz',
        ) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:7,代碼來源:test_linebreaksbr.py

示例14: edit_setting

# 需要導入模塊: from django.template import defaultfilters [as 別名]
# 或者: from django.template.defaultfilters import linebreaksbr [as 別名]
def edit_setting(request, setting_group, setting_name):
    """
    Allows a user to edit a setting. Fields are auto generated based on the setting.kind field
    :param request: HttpRequest object
    :param setting_group: string, SettingGroup.name
    :param setting_name: string, Setting.name
    :return: HttpResponse object
    """
    setting = models.Setting.objects.get(
            name=setting_name, group__name=setting_group)
    setting_value = setting_handler.get_setting(
            setting_group,
            setting_name,
            request.journal,
            default=False
        )

    if setting_value and setting_value.setting.types == 'rich-text':
        setting_value.value = linebreaksbr(setting_value.value)

    edit_form = forms.EditKey(
            key_type=setting.types,
            value=setting_value.value if setting_value else None
    )

    if request.POST and 'delete' in request.POST and setting_value:
        setting_value.delete()

        return redirect(reverse('core_settings_index'))

    if request.POST:
        value = request.POST.get('value')
        if request.FILES:
            value = logic.handle_file(request, setting_value, request.FILES['value'])

        setting_value = setting_handler.save_setting(
            setting_group, setting_name, request.journal, value)
        cache.clear()

        return redirect(reverse('core_settings_index'))

    template = 'core/manager/settings/edit_setting.html'
    context = {
        'setting': setting,
        'setting_value': setting_value,
        'group': setting.group,
        'edit_form': edit_form,
        'value': setting_value.value if setting_value else None
    }
    return render(request, template, context) 
開發者ID:BirkbeckCTP,項目名稱:janeway,代碼行數:52,代碼來源:views.py


注:本文中的django.template.defaultfilters.linebreaksbr方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。