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: add all data for submission versions #173

Merged
merged 1 commit into from
Feb 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 3 additions & 2 deletions apollo/formsframework/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
ugly_phone = re.compile(r'[^\d]*')


def update_submission_version(sender, document, **kwargs):
def update_submission_version(phone, sender, document, **kwargs):
if sender != services.submissions.__model__:
return

Expand All @@ -42,10 +42,11 @@ def update_submission_version(sender, document, **kwargs):

services.submission_versions.create(
submission=document,
deployment=document.deployment,
data=json.dumps(version_data),
timestamp=datetime.utcnow(),
channel=channel,
identity=g.get('phone', '')
identity=phone
)


Expand Down
2 changes: 1 addition & 1 deletion apollo/messaging/views_messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def lookup_participant(msg, event=None):

def update_datastore(inbound, outbound, submission, had_errors):
if submission:
update_submission.delay(str(submission.pk))
update_submission.delay(str(submission.pk), inbound.sender)
participant = submission.contributor
else:
participant = lookup_participant(inbound)
Expand Down
10 changes: 7 additions & 3 deletions apollo/submissions/tasks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# -*- coding: utf-8 -*-
from functools import partial

from mongoengine import signals

from apollo import models
Expand Down Expand Up @@ -27,15 +29,17 @@ def init_submissions(deployment_pk, event_pk, form_pk, role_pk,


@celery.task
def update_submission(submission_pk):
def update_submission(submission_pk, sender):
try:
submission = models.Submission.objects.get(pk=submission_pk)
except models.Submission.DoesNotExist:
return

post_save_handler = partial(update_submission_version, sender)

with signals.post_save.connected_to(
update_submission_version,
models.Submission):
post_save_handler,
sender=models.Submission):
# save with precomputation enabled
submission.save()

Expand Down