Skip to content
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

Fix 584 #656

Closed
wants to merge 1 commit into from
Closed

Fix 584 #656

wants to merge 1 commit into from

Conversation

mope
Copy link
Contributor

@mope mope commented Sep 27, 2014

Issue

If a form is configured to have a checkbox field with multiple choices and a user submits that form with multiple boxes checked for that field, then only the last box checked will be recorded. This occurs because form data is extracted using the items() method.

Fix

I considered the following approaches:

  1. When saving a form submission, convert lists to strings. Save all data as strings.
  2. When saving a form submission, save all values as lists. Single values are saved as lists of one item. When form data is viewed in Wagtail Admin, display the lists as comma-separated strings.
  3. When saving a form submission, save strings as strings and lists as lists.

This pull request implements option (2) for the following reasons:

  1. Saving lists as lists preserves their structure. Saving all items as lists preserves uniformity of data representation.
  2. The Wagtail Admin Forms page is likely to be viewed less often than the form itself and by administrators rather than website visitors, so it is better to incur performance overhead there.
  3. This approach is much simpler than an implementation of option 3 would be.

Disadvantages of this approach:

  1. Most field types do not require their values to be stored as lists, almost all saved forms submissions will consist of large numbers of single-entry lists.
  2. Existing installations will have saved their form data as strings, but will begin saving it as lists after they upgrade. This will make reporting more complex and may break existing reporting code.

This allows form submission fields with multiple values to be saved correctly.
@mope mope changed the title Fix 584 Fix #584 Sep 27, 2014
@mope mope changed the title Fix #584 Fix 584 Sep 27, 2014
@mope
Copy link
Contributor Author

mope commented Sep 27, 2014

There seems to be a Python 3 compatibility issue here.

@kaedroho
Copy link
Contributor

This looks like the Python 3 issue:

https://docs.python.org/3.1/whatsnew/3.0.html#views-and-iterators-instead-of-lists

"Also, the dict.iterkeys(), dict.iteritems() and dict.itervalues() methods are no longer supported."

@kaedroho kaedroho added this to the 0.8 milestone Oct 9, 2014
@kaedroho kaedroho self-assigned this Oct 15, 2014
data = json.loads(self.form_data)
for k, v in data.iteritems():
if hasattr(v, '__iter__'):
data[k] = ", ".join(data[k])
Copy link
Contributor

Choose a reason for hiding this comment

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

This breaks the CSV export. Strings are iterable and they are being printed out as "H", "e", "l", "l", "o", " ", "w", "o", "r", "l", "d"

@kaedroho
Copy link
Contributor

I've fixed the Python 3 issues. Please could you merge https://github.com/kaedroho/wagtail/tree/mope-584-fix-formbuilder-checkboxes and into this PR and fix #656 (comment)

@kaedroho kaedroho assigned mope and unassigned kaedroho Oct 15, 2014
@gasman
Copy link
Collaborator

gasman commented Oct 15, 2014

I've not had chance to look into this in detail yet, but I have to say I'm not massively keen on the idea of changing the representation of all field types to list, just to fix an issue with one specific field type. Can we look into the feasibility of an option (3) solution?

@chrxr chrxr assigned kaedroho and unassigned mope Oct 16, 2014
@kaedroho kaedroho mentioned this pull request Oct 30, 2014
@kaedroho
Copy link
Contributor

Continuing development here: #768

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants