Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
django-forms-as-jsonschema
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AlekSIS®
Libraries
django-forms-as-jsonschema
Commits
0e53b338
Commit
0e53b338
authored
2 years ago
by
Julian
Browse files
Options
Downloads
Patches
Plain Diff
Allow Python 3.9
parent
7be9aec0
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
django_forms_as_jsonschema/jsonschema.py
+81
-78
81 additions, 78 deletions
django_forms_as_jsonschema/jsonschema.py
pyproject.toml
+1
-1
1 addition, 1 deletion
pyproject.toml
with
82 additions
and
79 deletions
django_forms_as_jsonschema/jsonschema.py
+
81
−
78
View file @
0e53b338
...
...
@@ -76,89 +76,92 @@ class JSONSchema:
# string, number, integer, boolean.
match
type
(
field
.
widget
):
case
forms
.
TextInput
:
if
type
(
field
.
widget
)
==
forms
.
TextInput
:
new_field
[
"
type
"
]
=
"
string
"
elif
type
(
field
.
widget
)
==
forms
.
NumberInput
:
new_field
[
"
type
"
]
=
"
integer
"
if
type
(
field
)
==
forms
.
IntegerField
else
"
number
"
elif
type
(
field
.
widget
)
==
forms
.
EmailInput
:
new_field
[
"
type
"
]
=
"
string
"
new_field
[
"
format
"
]
=
"
email
"
elif
type
(
field
.
widget
)
==
forms
.
URLInput
:
new_field
[
"
type
"
]
=
"
string
"
new_field
[
"
format
"
]
=
"
url
"
elif
type
(
field
.
widget
)
==
forms
.
PasswordInput
:
new_field
[
"
type
"
]
=
"
string
"
new_field
[
"
format
"
]
=
"
password
"
new_field
[
"
x-display
"
]
=
"
password
"
elif
type
(
field
.
widget
)
==
forms
.
HiddenInput
:
new_field
[
"
type
"
]
=
"
string
"
new_field
[
"
format
"
]
=
"
hidden
"
elif
type
(
field
.
widget
)
==
forms
.
MultipleHiddenInput
:
...
elif
type
(
field
.
widget
)
in
[
forms
.
FileInput
,
forms
.
ClearableFileInput
]:
new_field
|=
{
"
type
"
:
"
string
"
,
"
contentMediaType
"
:
"
image/*
"
if
type
(
field
)
==
forms
.
ImageField
else
"
*
"
,
"
writeOnly
"
:
True
}
# Fixme: differentiate between clearable and non-clearable
# elif type(field.widget) == forms.ClearableFileInput:
# ...
elif
type
(
field
.
widget
)
==
forms
.
Textarea
:
new_field
[
"
x-display
"
]
=
"
textarea
"
elif
type
(
field
.
widget
)
==
forms
.
DateInput
:
new_field
[
"
type
"
]
=
"
string
"
new_field
[
"
format
"
]
=
"
date
"
elif
type
(
field
.
widget
)
==
forms
.
DateTimeInput
:
new_field
[
"
type
"
]
=
"
string
"
new_field
[
"
format
"
]
=
"
date-time
"
elif
type
(
field
.
widget
)
==
forms
.
TimeInput
:
new_field
[
"
type
"
]
=
"
string
"
new_field
[
"
format
"
]
=
"
time
"
elif
type
(
field
.
widget
)
==
forms
.
CheckboxInput
:
new_field
[
"
type
"
]
=
"
boolean
"
elif
type
(
field
.
widget
)
in
[
forms
.
Select
,
forms
.
SelectMultiple
,
forms
.
RadioSelect
,
forms
.
CheckboxSelectMultiple
,
forms
.
NullBooleanSelect
]:
one_of
=
[]
for
const
,
title
in
field
.
widget
.
choices
:
one_of
.
append
(
dict
(
const
=
str
(
const
),
title
=
str
(
title
)))
if
field
.
widget
.
allow_multiple_selected
:
new_field
[
"
type
"
]
=
"
array
"
new_field
[
"
items
"
]
=
{
"
type
"
:
"
string
"
,
"
oneOf
"
:
one_of
}
else
:
new_field
[
"
type
"
]
=
"
string
"
new_field
[
"
oneOf
"
]
=
one_of
case
forms
.
NumberInput
:
new_field
[
"
type
"
]
=
"
integer
"
if
type
(
field
)
==
forms
.
IntegerField
else
"
number
"
if
type
(
field
.
widget
)
==
forms
.
RadioSelect
:
new_field
[
"
x-display
"
]
=
"
radio
"
elif
type
(
field
.
widget
)
==
forms
.
CheckboxSelectMultiple
:
new_field
[
"
x-display
"
]
=
"
checkbox
"
case
forms
.
EmailInput
:
new_field
[
"
type
"
]
=
"
string
"
new_field
[
"
format
"
]
=
"
email
"
case
forms
.
URLInput
:
new_field
[
"
type
"
]
=
"
string
"
new_field
[
"
format
"
]
=
"
url
"
case
forms
.
PasswordInput
:
new_field
[
"
type
"
]
=
"
string
"
new_field
[
"
format
"
]
=
"
password
"
new_field
[
"
x-display
"
]
=
"
password
"
case
forms
.
HiddenInput
:
new_field
[
"
type
"
]
=
"
string
"
new_field
[
"
format
"
]
=
"
hidden
"
elif
type
(
field
.
widget
)
==
forms
.
SplitDateTimeWidget
:
...
case
forms
.
MultipleHiddenInpu
t
:
...
elif
type
(
field
.
widget
)
==
forms
.
SplitHiddenDateTimeWidge
t
:
...
case
forms
.
FileInput
|
forms
.
ClearableFileInput
:
new_field
|=
{
"
type
"
:
"
string
"
,
"
contentMediaType
"
:
"
image/*
"
if
type
(
field
)
==
forms
.
ImageField
else
"
*
"
,
"
writeOnly
"
:
True
}
elif
type
(
field
.
widget
)
==
forms
.
SelectDateWidget
:
...
# Fixme: differentiate between clearable and non-clearable
# case forms.ClearableFileInput:
# ...
case
forms
.
Textarea
:
new_field
[
"
x-display
"
]
=
"
textarea
"
case
forms
.
DateInput
:
new_field
[
"
type
"
]
=
"
string
"
new_field
[
"
format
"
]
=
"
date
"
case
forms
.
DateTimeInput
:
new_field
[
"
type
"
]
=
"
string
"
new_field
[
"
format
"
]
=
"
date-time
"
case
forms
.
TimeInput
:
new_field
[
"
type
"
]
=
"
string
"
new_field
[
"
format
"
]
=
"
time
"
case
forms
.
CheckboxInput
:
new_field
[
"
type
"
]
=
"
boolean
"
case
forms
.
Select
|
forms
.
SelectMultiple
|
forms
.
RadioSelect
|
forms
.
CheckboxSelectMultiple
,
forms
.
NullBooleanSelect
:
one_of
=
[]
for
const
,
title
in
field
.
widget
.
choices
:
one_of
.
append
(
dict
(
const
=
str
(
const
),
title
=
str
(
title
)))
if
field
.
widget
.
allow_multiple_selected
:
new_field
[
"
type
"
]
=
"
array
"
new_field
[
"
items
"
]
=
{
"
type
"
:
"
string
"
,
"
oneOf
"
:
one_of
}
else
:
new_field
[
"
type
"
]
=
"
string
"
new_field
[
"
oneOf
"
]
=
one_of
if
type
(
field
.
widget
)
==
forms
.
RadioSelect
:
new_field
[
"
x-display
"
]
=
"
radio
"
elif
type
(
field
.
widget
)
==
forms
.
CheckboxSelectMultiple
:
new_field
[
"
x-display
"
]
=
"
checkbox
"
case
forms
.
SplitDateTimeWidget
:
...
case
forms
.
SplitHiddenDateTimeWidget
:
...
case
forms
.
SelectDateWidget
:
...
else
:
print
(
field
,
type
(
field
),
type
(
field
.
widget
))
self
.
schema
[
"
properties
"
][
name
]
=
new_field
This diff is collapsed.
Click to expand it.
pyproject.toml
+
1
−
1
View file @
0e53b338
...
...
@@ -5,7 +5,7 @@ description = ""
authors
=
[
"Julian Leucker <leuckerj@gmail.com>"
]
[tool.poetry.dependencies]
python
=
"^3.
10
"
python
=
"^3.
9
"
Django
=
"^4.1"
[tool.poetry.dev-dependencies]
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment