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
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AlekSIS®
Libraries
django-forms-as-jsonschema
Compare revisions
bdcf9d9223bc5baafc6e00f4184269089e33e694 to 596873225988dfdfbd5f78b87d4612044e5df212
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
AlekSIS/libs/django-forms-as-jsonschema
Select target project
No results found
596873225988dfdfbd5f78b87d4612044e5df212
Select Git revision
Branches
11-create-model-for-instances-of-a-form
main
renovate/django-5.x
renovate/pytest-8.x
4 results
Swap
Target
AlekSIS/libs/django-forms-as-jsonschema
Select target project
AlekSIS/libs/django-forms-as-jsonschema
1 result
bdcf9d9223bc5baafc6e00f4184269089e33e694
Select Git revision
Branches
11-create-model-for-instances-of-a-form
main
renovate/django-5.x
renovate/pytest-8.x
4 results
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Commits on Source
3
Rename schema to jsonschema
· 8129242f
Julian
authored
Sep 4, 2022
8129242f
Remove build() method
· 23a7fe56
Julian
authored
Sep 4, 2022
23a7fe56
Use a local dict to create fields
· 59687322
Julian
authored
Sep 4, 2022
59687322
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
django_forms_as_jsonschema/forms.py
+3
-3
3 additions, 3 deletions
django_forms_as_jsonschema/forms.py
django_forms_as_jsonschema/jsonschema.py
+33
-49
33 additions, 49 deletions
django_forms_as_jsonschema/jsonschema.py
with
36 additions
and
52 deletions
django_forms_as_jsonschema/forms.py
View file @
59687322
from
django.forms
import
Form
from
django.forms
import
Form
from
django_forms_as_jsonschema.
schema
import
Schema
from
.json
schema
import
JSON
Schema
class
JSONSchemaFormMixin
:
class
JSONSchemaFormMixin
:
def
as_jsonschema
(
self
:
Form
)
->
str
:
def
as_jsonschema
(
self
:
Form
)
->
dict
:
schema
=
Schema
()
schema
=
JSON
Schema
()
for
name
,
field
in
self
.
fields
.
items
():
for
name
,
field
in
self
.
fields
.
items
():
schema
.
add_field
(
name
,
field
)
schema
.
add_field
(
name
,
field
)
return
schema
.
schema
return
schema
.
schema
This diff is collapsed.
Click to expand it.
django_forms_as_jsonschema/schema.py
→
django_forms_as_jsonschema/
json
schema.py
View file @
59687322
import
copy
import
json
from
django
import
forms
from
django
import
forms
class
Schema
:
class
JSONSchema
:
SCHEMA
=
{
def
__init__
(
self
):
self
.
schema
=
{
"
$schema
"
:
"
https://json-schema.org/draft/2020-12/schema
"
,
"
$schema
"
:
"
https://json-schema.org/draft/2020-12/schema
"
,
"
type
"
:
"
object
"
,
"
type
"
:
"
object
"
,
"
properties
"
:
{},
"
properties
"
:
{},
}
}
def
__init__
(
self
):
self
.
schema
=
copy
.
deepcopy
(
self
.
SCHEMA
)
# example_json = {
# example_json = {
# "type": "object",
# "type": "object",
# "properties": {
# "properties": {
...
@@ -70,40 +66,38 @@ class Schema:
...
@@ -70,40 +66,38 @@ class Schema:
# }
# }
# }
# }
def
build
(
self
):
return
json
.
dumps
(
self
.
schema
)
def
add_field
(
self
,
name
,
field
):
def
add_field
(
self
,
name
,
field
):
type_
=
"
string
"
new_field
=
{
format_
=
None
"
type
"
:
"
string
"
,
x_display
=
None
"
title
"
:
str
(
field
.
label
),
enum
=
None
"
description
"
:
str
(
field
.
help_text
),
}
# string, number, integer, boolean.
# string, number, integer, boolean.
match
type
(
field
.
widget
):
match
type
(
field
.
widget
):
case
forms
.
TextInput
:
case
forms
.
TextInput
:
type
_
=
"
string
"
new_field
[
"
type
"
]
=
"
string
"
case
forms
.
NumberInput
:
case
forms
.
NumberInput
:
type_
=
"
number
"
new_field
[
"
type
"
]
=
"
integer
"
if
type
(
field
)
==
forms
.
IntegerField
else
"
number
"
case
forms
.
EmailInput
:
case
forms
.
EmailInput
:
type
_
=
"
string
"
new_field
[
"
type
"
]
=
"
string
"
format
_
=
"
email
"
new_field
[
"
format
"
]
=
"
email
"
case
forms
.
URLInput
:
case
forms
.
URLInput
:
type
_
=
"
string
"
new_field
[
"
type
"
]
=
"
string
"
format
_
=
"
url
"
new_field
[
"
format
"
]
=
"
url
"
case
forms
.
PasswordInput
:
case
forms
.
PasswordInput
:
type
_
=
"
string
"
new_field
[
"
type
"
]
=
"
string
"
format
_
=
"
password
"
new_field
[
"
format
"
]
=
"
password
"
x_
display
=
"
password
"
new_field
[
"
x-
display
"
]
=
"
password
"
case
forms
.
HiddenInput
:
case
forms
.
HiddenInput
:
type
_
=
"
string
"
new_field
[
"
type
"
]
=
"
string
"
format
_
=
"
hidden
"
new_field
[
"
format
"
]
=
"
hidden
"
case
forms
.
MultipleHiddenInput
:
case
forms
.
MultipleHiddenInput
:
...
...
...
@@ -115,26 +109,26 @@ class Schema:
...
@@ -115,26 +109,26 @@ class Schema:
...
...
case
forms
.
Textarea
:
case
forms
.
Textarea
:
x_
display
=
"
textarea
"
new_field
[
"
x-
display
"
]
=
"
textarea
"
case
forms
.
DateInput
:
case
forms
.
DateInput
:
type
_
=
"
string
"
new_field
[
"
type
"
]
=
"
string
"
format
_
=
"
date
"
new_field
[
"
format
"
]
=
"
date
"
case
forms
.
DateTimeInput
:
case
forms
.
DateTimeInput
:
type
_
=
"
string
"
new_field
[
"
type
"
]
=
"
string
"
format
_
=
"
date-time
"
new_field
[
"
format
"
]
=
"
date-time
"
case
forms
.
TimeInput
:
case
forms
.
TimeInput
:
type
_
=
"
string
"
new_field
[
"
type
"
]
=
"
string
"
format
_
=
"
time
"
new_field
[
"
format
"
]
=
"
time
"
case
forms
.
CheckboxInput
:
case
forms
.
CheckboxInput
:
type
_
=
"
boolean
"
new_field
[
"
type
"
]
=
"
boolean
"
case
forms
.
Select
:
case
forms
.
Select
:
type
_
=
"
string
"
new_field
[
"
type
"
]
=
"
string
"
enum
=
[]
# Fixme: load data from widget.options(…)
new_field
[
"
enum
"
]
=
[]
# Fixme: load data from widget.options(…)
case
forms
.
NullBooleanSelect
:
case
forms
.
NullBooleanSelect
:
...
...
...
@@ -157,14 +151,4 @@ class Schema:
...
@@ -157,14 +151,4 @@ class Schema:
case
forms
.
SelectDateWidget
:
case
forms
.
SelectDateWidget
:
...
...
self
.
schema
[
"
properties
"
][
name
]
=
{
self
.
schema
[
"
properties
"
][
name
]
=
new_field
"
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
This diff is collapsed.
Click to expand it.