Skip to content
This repository has been archived by the owner on Sep 5, 2019. It is now read-only.

Commit

Permalink
Adds the ability to exclude certain fields from the submission update
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Krienbühl committed Apr 13, 2016
1 parent 369e6a7 commit eb5d9d6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
3 changes: 3 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Changelog
---------

- Adds the ability to exclude certain fields from the submission update.
[href]

0.10.2 (2016-04-11)
~~~~~~~~~~~~~~~~~~~

Expand Down
10 changes: 7 additions & 3 deletions onegov/form/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,15 +210,19 @@ def complete_submission(self, submission):

self.session.expunge(submission)

def update(self, submission, form):
def update(self, submission, form, exclude=None):
""" Takes a submission and a form and updates the submission data
as well as the files stored in a spearate table.
"""
assert submission.id and submission.state

exclude = exclude or set()

submission.definition = form._source
submission.data = form.data
submission.data = {
k: v for k, v in form.data.items() if k not in exclude
}

# never include the csrf token
if form.meta.csrf and form.meta.csrf_field_name in submission.data:
Expand All @@ -227,7 +231,7 @@ def update(self, submission, form):
# move uploaded files to a separate table
files = set(
field_id for field_id, field in form._fields.items()
if isinstance(field, UploadField)
if isinstance(field, UploadField) and field_id not in exclude
)

files_to_remove = set(
Expand Down

0 comments on commit eb5d9d6

Please sign in to comment.