Skip to content
Open
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
216aeb5
test text
Arthur-Milchior Mar 5, 2020
5f5b32e
test enum
Arthur-Milchior Mar 5, 2020
08080a3
test boolean
Arthur-Milchior Mar 5, 2020
07bea04
spin respect min/max and steps
Arthur-Milchior Mar 5, 2020
5d85aee
use a dict to send type to their default method
Arthur-Milchior Mar 5, 2020
ea9fd82
ignore tmp files
Arthur-Milchior Mar 5, 2020
b7482db
ignore pycache
Arthur-Milchior Mar 5, 2020
9351cc6
pep8 and sort import
Arthur-Milchior Mar 5, 2020
44b3b56
add default value for numeric
Arthur-Milchior Mar 5, 2020
dbb03d0
return default for const
Arthur-Milchior Mar 5, 2020
126b63a
default value when no type, enum nor const
Arthur-Milchior Mar 5, 2020
cbfb0d6
deal with values of multiple possible types
Arthur-Milchior Mar 5, 2020
54c53a0
separate list and tuple defaults
Arthur-Milchior Mar 5, 2020
d596bab
list_default return min_items elements
Arthur-Milchior Mar 5, 2020
c1f7900
deal with "contains" in list
Arthur-Milchior Mar 5, 2020
a7529be
default boolean
Arthur-Milchior Mar 5, 2020
5c38f34
string default
Arthur-Milchior Mar 5, 2020
6d104ed
apply max length to string
Arthur-Milchior Mar 5, 2020
6b5f3f2
comments
Arthur-Milchior Mar 5, 2020
d3c9702
USAGE.md
Arthur-Milchior Mar 5, 2020
c2553e9
allow to give a parent window
Arthur-Milchior Mar 6, 2020
16625af
default empty ui_schema
Arthur-Milchior Mar 6, 2020
ea2a337
save layout as FormWidget parameter
Arthur-Milchior Mar 7, 2020
74a57e7
directory for file
Arthur-Milchior Mar 7, 2020
54c558e
tool tip over labels in objects
Arthur-Milchior Mar 7, 2020
37017b7
error message for some wrong value
Arthur-Milchior Mar 11, 2020
b715080
remove example and redirects to test
Arthur-Milchior Mar 11, 2020
d803b11
create get_widget_variant
Arthur-Milchior Mar 11, 2020
ae1b255
all __init__ have args ans kwargs
Arthur-Milchior Mar 12, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions qt_jsonschema_form/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,16 @@ def object_defaults(schema):
def array_defaults(schema):
items_schema = schema['items']
if isinstance(items_schema, dict):
# in this case, it should be a list of items_schema
return []

# in this case, it's a tuple.
return [compute_defaults(s) for s in schema["items"]]

defaults = {
"array": array_defaults,
"object": object_defaults,
}

def compute_defaults(schema):
if "default" in schema:
Expand All @@ -27,10 +33,7 @@ def compute_defaults(schema):

schema_type = schema["type"]

if schema_type == "object":
return object_defaults(schema)

elif schema_type == "array":
return array_defaults(schema)
if schema_type in defaults:
return defaults[schema_type](schema)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest changing this to return defaults.get(schema_type)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand your point.
your code return a function. It does not apply it to the schema.
Of course I could do
return defaults.get(schema_type, lambda _: None)(schema)
but it does not really seems interesting


return None