-
-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Fix DictField HTML input returning empty dict for missing fields #9891
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
34065b7
506ff84
31b8e0d
4e1adc1
5afa962
f1e43df
5242d9a
3324ed6
665cf39
dfe6628
e9ebed5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,7 +66,7 @@ def parse_html_list(dictionary, prefix='', default=None): | |
| return [ret[item] for item in sorted(ret)] if ret else default | ||
|
|
||
|
|
||
| def parse_html_dict(dictionary, prefix=''): | ||
| def parse_html_dict(dictionary, prefix='', default=None): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks consistent with what we do for parsing html list 👍🏻 : |
||
| """ | ||
|
Comment on lines
+69
to
70
|
||
| Used to support dictionary values in HTML forms. | ||
|
|
||
|
|
@@ -81,6 +81,9 @@ def parse_html_dict(dictionary, prefix=''): | |
| 'email': 'example@example.com' | ||
| } | ||
| } | ||
|
|
||
| :returns a MultiValueDict of the parsed data, or the value specified in | ||
| ``default`` if the dict field was not present in the input | ||
| """ | ||
| ret = MultiValueDict() | ||
| regex = re.compile(r'^%s\.(.+)$' % re.escape(prefix)) | ||
|
|
@@ -92,4 +95,4 @@ def parse_html_dict(dictionary, prefix=''): | |
| value = dictionary.getlist(field) | ||
| ret.setlist(key, value) | ||
|
|
||
| return ret | ||
| return ret if ret else default | ||
Uh oh!
There was an error while loading. Please reload this page.