Skip to content
This repository has been archived by the owner on Jun 12, 2018. It is now read-only.

Commit

Permalink
Add ability to export old survey questions via CSV.
Browse files Browse the repository at this point in the history
  • Loading branch information
hodgestar committed Dec 5, 2013
1 parent 0f9c247 commit 8ee3baa
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
5 changes: 3 additions & 2 deletions go/apps/surveys/definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ class DownloadUserDataAction(ConversationAction):
def perform_action(self, action_data):
# This is Django-only, but the module get imported in vumi-land.
from go.apps.surveys.tasks import export_vxpolls_data
return export_vxpolls_data.delay(self._conv.user_account.key,
self._conv.key)
return export_vxpolls_data.delay(
self._conv.user_account.key, self._conv.key,
include_old_questions=action_data['include_old_questions'])


class ConversationDefinition(ConversationDefinitionBase):
Expand Down
5 changes: 3 additions & 2 deletions go/apps/surveys/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


@task(ignore_result=True)
def export_vxpolls_data(account_key, conversation_key):
def export_vxpolls_data(account_key, conversation_key, include_old_questions):
"""
Export the data from a vxpoll and send it as a zipped attachment
via email.
Expand All @@ -25,7 +25,8 @@ def export_vxpolls_data(account_key, conversation_key):
poll_id = 'poll-%s' % (conversation.key,)
pm, poll_data = get_poll_config(poll_id)
poll = pm.get(poll_id)
csv_data = pm.export_user_data_as_csv(poll)
csv_data = pm.export_user_data_as_csv(
poll, include_old_questions=include_old_questions)
email = EmailMessage(
'Survey export for: %s' % (conversation.name,),
'Please find the data for the survey %s attached.\n' % (
Expand Down
16 changes: 12 additions & 4 deletions go/apps/surveys/view_definition.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.forms import Form
from django.forms import BooleanField, Form
from django.conf import settings
from django.contrib import messages

Expand Down Expand Up @@ -98,12 +98,20 @@ def post(self, request, conversation):
})


class DownloadUserDataForm(Form):
include_old_questions = BooleanField(
label="Include old questions",
help_text=("Whether to include answers to old questions that were"
" once part of the poll but are no longer."),
initial=False, required=False)


class ConversationViewDefinition(ConversationViewDefinitionBase):
edit_view = SurveyEditView

action_forms = {
# TODO: These are both work-arounds for not being able to directly
# trigger POSTs via conversation action buttons
# TODO: The empty send_survey form is a work-around for not being able
# to directly trigger POSTs via conversation action buttons
'send_survey': Form,
'download_user_data': Form,
'download_user_data': DownloadUserDataForm,
}

0 comments on commit 8ee3baa

Please sign in to comment.