Skip to content
Snippets Groups Projects
Commit 59687322 authored by Julian's avatar Julian
Browse files

Use a local dict to create fields

parent 23a7fe56
No related branches found
No related tags found
No related merge requests found
......@@ -67,36 +67,37 @@ class JSONSchema:
# }
def add_field(self, name, field):
type_ = "string"
format_ = None
x_display = None
enum = None
new_field = {
"type": "string",
"title": str(field.label),
"description": str(field.help_text),
}
# string, number, integer, boolean.
match type(field.widget):
case forms.TextInput:
type_ = "string"
new_field["type"] = "string"
case forms.NumberInput:
type_ = "number"
new_field["type"] = "integer" if type(field) == forms.IntegerField else "number"
case forms.EmailInput:
type_ = "string"
format_ = "email"
new_field["type"] = "string"
new_field["format"] = "email"
case forms.URLInput:
type_ = "string"
format_ = "url"
new_field["type"] = "string"
new_field["format"] = "url"
case forms.PasswordInput:
type_ = "string"
format_ = "password"
x_display = "password"
new_field["type"] = "string"
new_field["format"] = "password"
new_field["x-display"] = "password"
case forms.HiddenInput:
type_ = "string"
format_ = "hidden"
new_field["type"] = "string"
new_field["format"] = "hidden"
case forms.MultipleHiddenInput:
...
......@@ -108,26 +109,26 @@ class JSONSchema:
...
case forms.Textarea:
x_display = "textarea"
new_field["x-display"] = "textarea"
case forms.DateInput:
type_ = "string"
format_ = "date"
new_field["type"] = "string"
new_field["format"] = "date"
case forms.DateTimeInput:
type_ = "string"
format_ = "date-time"
new_field["type"] = "string"
new_field["format"] = "date-time"
case forms.TimeInput:
type_ = "string"
format_ = "time"
new_field["type"] = "string"
new_field["format"] = "time"
case forms.CheckboxInput:
type_ = "boolean"
new_field["type"] = "boolean"
case forms.Select:
type_ = "string"
enum = [] # Fixme: load data from widget.options(…)
new_field["type"] = "string"
new_field["enum"] = [] # Fixme: load data from widget.options(…)
case forms.NullBooleanSelect:
...
......@@ -150,14 +151,4 @@ class JSONSchema:
case forms.SelectDateWidget:
...
self.schema["properties"][name] = {
"type": type_,
"title": str(field.label),
"description": str(field.help_text),
}
if x_display:
self.schema["properties"][name]["x-display"] = x_display
if format_:
self.schema["properties"][name]["format"] = format_
if enum:
self.schema["properties"][name]["enum"] = enum
self.schema["properties"][name] = new_field
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