Fix/metadata serialization - #29
Merged
Merged
Conversation
Contributor
Reviewer's GuideAdds serialization of placeholder and initial metadata for form fields in the API, including proper JSON-safe handling of callable and date/datetime initial values, and introduces tests to cover these behaviors. Sequence diagram for the form fields API metadata serializationsequenceDiagram
actor Client
participant APIView as FormFieldsAPIView
participant Forms as get_form_fields
participant Serializer as _serialize_initial
Client->>APIView: GET /api/forms/{slug}/fields
APIView->>Forms: get_form_fields(request, slug)
Forms->>Forms: build fields dict from form
loop For each field
Forms->>Forms: widget_attrs = field.widget.attrs
Forms->>Forms: field_info base attributes
Forms->>Forms: placeholder = widget_attrs.get(placeholder)
alt placeholder is not None or empty
Forms->>Forms: field_info.placeholder = placeholder
end
Forms->>Serializer: _serialize_initial(field.initial)
Serializer->>Serializer: if callable(value) then value()
Serializer->>Serializer: if value is None return None
Serializer->>Serializer: if value is date/datetime return isoformat()
Serializer-->>Forms: initial_value
alt initial_value is not None
Forms->>Forms: field_info.initial = initial_value
end
Forms->>Forms: add choices if present
end
Forms-->>APIView: list of field_info
APIView-->>Client: JSON response with placeholder and initial metadata
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
… and initial values
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary by Sourcery
Expose additional form field metadata through the API and normalize initial values for JSON responses.
New Features:
Enhancements:
Tests: