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

Commit

Permalink
Adds a meta column to the submissions table
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Krienbühl committed Dec 20, 2017
1 parent 69179cb commit e8d0dfd
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
4 changes: 4 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Changelog
---------

- Adds a meta column to the submissions table.
[href]

0.28.0 (2017-12-19)
~~~~~~~~~~~~~~~~~~~

Expand Down
9 changes: 6 additions & 3 deletions onegov/form/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def query(self):

return query

def add(self, name, form, state, id=None, payment_method=None):
def add(self, name, form, state, id=None, payment_method=None, meta=None):
""" Takes a filled-out form instance and stores the submission
in the database. The form instance is expected to have a ``_source``
parameter, which contains the source used to build the form (as only
Expand Down Expand Up @@ -169,6 +169,7 @@ def add(self, name, form, state, id=None, payment_method=None):
submission.id = id or uuid4()
submission.name = name
submission.state = state
submission.meta = meta or {}
submission.payment_method = (
payment_method or
definition and definition.payment_method or
Expand All @@ -189,7 +190,8 @@ def add(self, name, form, state, id=None, payment_method=None):

return submission

def add_external(self, form, state, id=None, payment_method=None):
def add_external(self, form, state, id=None, payment_method=None,
meta=None):
""" Takes a filled-out form instance and stores the submission
in the database. The form instance is expected to have a ``_source``
parameter, which contains the source used to build the form (as only
Expand All @@ -205,7 +207,8 @@ def add_external(self, form, state, id=None, payment_method=None):
form=form,
state=state,
id=id,
payment_method=payment_method
payment_method=payment_method,
meta=meta,
)

def complete_submission(self, submission):
Expand Down
3 changes: 3 additions & 0 deletions onegov/form/models/submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ class FormSubmission(Base, TimestampMixin, Payable, AssociatedFiles):
#: checksums are guaranteed to have the exact same definition
checksum = Column(Text, nullable=False)

#: metadata about this submission
meta = Column(JSON, nullable=False)

#: the submission data
data = Column(JSON, nullable=False)

Expand Down
11 changes: 11 additions & 0 deletions onegov/form/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from onegov.form import FormDefinitionCollection
from onegov.form import FormFile
from onegov.form import FormSubmission
from onegov.core.orm.types import JSON
from sqlalchemy import Column, Text


Expand Down Expand Up @@ -97,3 +98,13 @@ def add_payment_method_to_definitions_and_submissions(context):

for form in context.records_per_table('forms'):
form.content.pop('payment_method', None)


@upgrade_task('Add meta dictionary to submissions')
def add_meta_directory_to_submissions(context):

context.add_column_with_defaults(
table='submissions',
column=Column('meta', JSON, nullable=False),
default=lambda submission: dict()
)

0 comments on commit e8d0dfd

Please sign in to comment.