diff --git a/app/api/react_ui_metadata.py b/app/api/react_ui_metadata.py index e0651f32..b482f7d9 100644 --- a/app/api/react_ui_metadata.py +++ b/app/api/react_ui_metadata.py @@ -271,14 +271,23 @@ class ReactUIMetadata(OverRideJSONAPIMetadata): else: field_info["relationship_resource"] = get_related_resource_type(field) + if hasattr(field, 'autolink'): + + if field.autolink: + + field_info['autolink'] = field.autolink + + field_info["required"] = getattr(field, "required", False) + if hasattr(field, 'style_class'): field_info["style"]: dict = { 'class': field.style_class } + attrs = [ "read_only", "write_only", diff --git a/app/core/fields/char.py b/app/core/fields/char.py index 973778ee..04c50c2f 100644 --- a/app/core/fields/char.py +++ b/app/core/fields/char.py @@ -4,6 +4,8 @@ from rest_framework import serializers class CharField(serializers.CharField): + autolink: bool = False + source = '' label = '' @@ -11,7 +13,14 @@ class CharField(serializers.CharField): textarea: bool - def __init__(self, multiline = False, **kwargs): + def __init__( + self, + autolink = False, + multiline = False, + **kwargs + ): + + self.autolink = autolink self.textarea = multiline diff --git a/app/core/serializers/celery_log.py b/app/core/serializers/celery_log.py index 492937b4..0da0205a 100644 --- a/app/core/serializers/celery_log.py +++ b/app/core/serializers/celery_log.py @@ -9,6 +9,8 @@ from access.serializers.organization import OrganizationBaseSerializer from app.serializers.user import UserBaseSerializer +from core import fields as centurion_field + class TaskResultBaseSerializer(serializers.ModelSerializer): @@ -57,6 +59,8 @@ class TaskResultModelSerializer(TaskResultBaseSerializer): ), } + task_id = centurion_field.CharField( autolink = True ) + class Meta: diff --git a/docs/projects/centurion_erp/development/fields.md b/docs/projects/centurion_erp/development/fields.md new file mode 100644 index 00000000..7fcdcbb7 --- /dev/null +++ b/docs/projects/centurion_erp/development/fields.md @@ -0,0 +1,29 @@ +--- +title: Fields +description: Centurion ERP Fields development documentation +date: 2024-11-13 +template: project.html +about: https://github.com/nofusscomputing/centurion_erp +--- + +Fields are used by the serializers for the data. We have our fields specified in module `core.fields`. These fields are `rest_framework` fields. + + +## Char Field + +This field extends `rest_framework.serializers.CharField` with additional attributes that are used by the UI. The additional attributes are: + +- `autolink`, _Boolean_ The interface will render the field as an anchor using the url at path `_urls._self` of the objects data. + +- `multiline`, _Boolean_. The field should be rendered as a `textarea` input field. + +if attribute `multiline` is not specified, by default the field is rendered as an input text field. + + +## Markdown Field + +This field extends `core.fields.CharField`. The field metadata sets the field type to `Markdown`, which tells the UI to render the field as markdown. The additional attributes are: + +- `multiline`, _Boolean_. The field should be rendered as a `textarea` input field. + +- `style_class` _String_ This field is a space seperated value (ssv) of CSS classes to use for the field. The UI will use this value as additional CSS classes to append to the field. diff --git a/docs/projects/centurion_erp/development/index.md b/docs/projects/centurion_erp/development/index.md index 7d38b447..12cc01b0 100644 --- a/docs/projects/centurion_erp/development/index.md +++ b/docs/projects/centurion_erp/development/index.md @@ -15,6 +15,8 @@ Centurion ERP is a Django Application. We have added a lot of little tid bits th - [Application API Documentation](./api/index.md) +- [Fields](./fields.md) + - [Forms](./forms.md) - [Models](./models.md) diff --git a/mkdocs.yml b/mkdocs.yml index 52a51464..7a5dc91e 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -145,6 +145,8 @@ nav: - projects/centurion_erp/development/api/tests/notes_permissions.md + - projects/centurion_erp/development/fields.md + - projects/centurion_erp/development/forms.md - projects/centurion_erp/development/models.md