Просмотр исходного кода

12685 use markdown for custom fields added to form (#13828)

* 12685 use markdown for custom fields added to form

* 13809 change markdown to use utilities

* Add help_text for CustomField description indicating Markdown support

---------

Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
Arthur Hanson 2 лет назад
Родитель
Сommit
6e4b4a553b
2 измененных файлов с 4 добавлено и 2 удалено
  1. 2 1
      netbox/extras/forms/model_forms.py
  2. 2 1
      netbox/extras/models/customfields.py

+ 2 - 1
netbox/extras/forms/model_forms.py

@@ -76,7 +76,8 @@ class CustomFieldForm(BootstrapMixin, forms.ModelForm):
             'type': _(
                 "The type of data stored in this field. For object/multi-object fields, select the related object "
                 "type below."
-            )
+            ),
+            'description': _("This will be displayed as help text for the form field. Markdown is supported.")
         }
 
     def __init__(self, *args, **kwargs):

+ 2 - 1
netbox/extras/models/customfields.py

@@ -28,6 +28,7 @@ from utilities.forms.fields import (
 from utilities.forms.utils import add_blank_choice
 from utilities.forms.widgets import APISelect, APISelectMultiple, DatePicker, DateTimePicker
 from utilities.querysets import RestrictedQuerySet
+from utilities.templatetags.builtins.filters import render_markdown
 from utilities.validators import validate_regex
 
 __all__ = (
@@ -498,7 +499,7 @@ class CustomField(CloningMixin, ExportTemplatesMixin, ChangeLoggedModel):
         field.model = self
         field.label = str(self)
         if self.description:
-            field.help_text = escape(self.description)
+            field.help_text = render_markdown(self.description)
 
         # Annotate read-only fields
         if enforce_visibility and self.ui_visibility == CustomFieldVisibilityChoices.VISIBILITY_READ_ONLY: