|
@@ -177,12 +177,19 @@ class CustomField(CloningMixin, ExportTemplatesMixin, ChangeLoggedModel):
|
|
|
blank=True,
|
|
blank=True,
|
|
|
null=True
|
|
null=True
|
|
|
)
|
|
)
|
|
|
- ui_visibility = models.CharField(
|
|
|
|
|
|
|
+ ui_visible = models.CharField(
|
|
|
max_length=50,
|
|
max_length=50,
|
|
|
- choices=CustomFieldVisibilityChoices,
|
|
|
|
|
- default=CustomFieldVisibilityChoices.VISIBILITY_READ_WRITE,
|
|
|
|
|
- verbose_name=_('UI visibility'),
|
|
|
|
|
- help_text=_('Specifies the visibility of custom field in the UI')
|
|
|
|
|
|
|
+ choices=CustomFieldUIVisibleChoices,
|
|
|
|
|
+ default=CustomFieldUIVisibleChoices.ALWAYS,
|
|
|
|
|
+ verbose_name=_('UI visible'),
|
|
|
|
|
+ help_text=_('Specifies whether the custom field is displayed in the UI')
|
|
|
|
|
+ )
|
|
|
|
|
+ ui_editable = models.CharField(
|
|
|
|
|
+ max_length=50,
|
|
|
|
|
+ choices=CustomFieldUIEditableChoices,
|
|
|
|
|
+ default=CustomFieldUIEditableChoices.YES,
|
|
|
|
|
+ verbose_name=_('UI editable'),
|
|
|
|
|
+ help_text=_('Specifies whether the custom field value can be edited in the UI')
|
|
|
)
|
|
)
|
|
|
is_cloneable = models.BooleanField(
|
|
is_cloneable = models.BooleanField(
|
|
|
default=False,
|
|
default=False,
|
|
@@ -195,7 +202,7 @@ class CustomField(CloningMixin, ExportTemplatesMixin, ChangeLoggedModel):
|
|
|
clone_fields = (
|
|
clone_fields = (
|
|
|
'content_types', 'type', 'object_type', 'group_name', 'description', 'required', 'search_weight',
|
|
'content_types', 'type', 'object_type', 'group_name', 'description', 'required', 'search_weight',
|
|
|
'filter_logic', 'default', 'weight', 'validation_minimum', 'validation_maximum', 'validation_regex',
|
|
'filter_logic', 'default', 'weight', 'validation_minimum', 'validation_maximum', 'validation_regex',
|
|
|
- 'choice_set', 'ui_visibility', 'is_cloneable',
|
|
|
|
|
|
|
+ 'choice_set', 'ui_visible', 'ui_editable', 'is_cloneable',
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
|
class Meta:
|
|
@@ -229,6 +236,12 @@ class CustomField(CloningMixin, ExportTemplatesMixin, ChangeLoggedModel):
|
|
|
return self.choice_set.choices
|
|
return self.choice_set.choices
|
|
|
return []
|
|
return []
|
|
|
|
|
|
|
|
|
|
+ def get_ui_visible_color(self):
|
|
|
|
|
+ return CustomFieldUIVisibleChoices.colors.get(self.ui_visible)
|
|
|
|
|
+
|
|
|
|
|
+ def get_ui_editable_color(self):
|
|
|
|
|
+ return CustomFieldUIEditableChoices.colors.get(self.ui_editable)
|
|
|
|
|
+
|
|
|
def get_choice_label(self, value):
|
|
def get_choice_label(self, value):
|
|
|
if not hasattr(self, '_choice_map'):
|
|
if not hasattr(self, '_choice_map'):
|
|
|
self._choice_map = dict(self.choices)
|
|
self._choice_map = dict(self.choices)
|
|
@@ -379,7 +392,7 @@ class CustomField(CloningMixin, ExportTemplatesMixin, ChangeLoggedModel):
|
|
|
|
|
|
|
|
set_initial: Set initial data for the field. This should be False when generating a field for bulk editing.
|
|
set_initial: Set initial data for the field. This should be False when generating a field for bulk editing.
|
|
|
enforce_required: Honor the value of CustomField.required. Set to False for filtering/bulk editing.
|
|
enforce_required: Honor the value of CustomField.required. Set to False for filtering/bulk editing.
|
|
|
- enforce_visibility: Honor the value of CustomField.ui_visibility. Set to False for filtering.
|
|
|
|
|
|
|
+ enforce_visibility: Honor the value of CustomField.ui_visible. Set to False for filtering.
|
|
|
for_csv_import: Return a form field suitable for bulk import of objects in CSV format.
|
|
for_csv_import: Return a form field suitable for bulk import of objects in CSV format.
|
|
|
"""
|
|
"""
|
|
|
initial = self.default if set_initial else None
|
|
initial = self.default if set_initial else None
|
|
@@ -504,10 +517,10 @@ class CustomField(CloningMixin, ExportTemplatesMixin, ChangeLoggedModel):
|
|
|
field.help_text = render_markdown(self.description)
|
|
field.help_text = render_markdown(self.description)
|
|
|
|
|
|
|
|
# Annotate read-only fields
|
|
# Annotate read-only fields
|
|
|
- if enforce_visibility and self.ui_visibility == CustomFieldVisibilityChoices.VISIBILITY_READ_ONLY:
|
|
|
|
|
|
|
+ if enforce_visibility and self.ui_editable != CustomFieldUIEditableChoices.YES:
|
|
|
field.disabled = True
|
|
field.disabled = True
|
|
|
prepend = '<br />' if field.help_text else ''
|
|
prepend = '<br />' if field.help_text else ''
|
|
|
- field.help_text += f'{prepend}<i class="mdi mdi-alert-circle-outline"></i> ' + _('Field is set to read-only.')
|
|
|
|
|
|
|
+ field.help_text += f'{prepend}<i class="mdi mdi-alert-circle-outline"></i> ' + _('Field is not editable.')
|
|
|
|
|
|
|
|
return field
|
|
return field
|
|
|
|
|
|