Skip to content
Snippets Groups Projects
Commit 05519acb authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Document forms.py

parent b05d5d0a
No related branches found
No related tags found
No related merge requests found
......@@ -4,13 +4,19 @@ from .jsonschema import JSONSchema
class JSONSchemaFormMixin:
"""Mixin to extend Django forms with a converter into a JSON schema."""
layout = None
def as_jsonschema(self: Form) -> dict:
"""Encode form fields and layout into a JSON schema."""
schema = JSONSchema()
if self.layout is None:
# If no layout is provided, simply add all fields as individual rows
for name, field in self.fields.items():
schema.add_field(name, field)
else:
# Offload generation to the layout class
schema.update_properties(self.layout.build_schema(schema, self.fields)["properties"])
return schema.schema
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment