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. """ api = VumiUserApi.from_config_sync(account_key, settings.VUMI_API_CONFIG) user_profile = UserProfile.objects.get(user_account=account_key) conversation = api.get_wrapped_conversation(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, include_old_questions=include_old_questions) email = EmailMessage( 'Survey export for: %s' % (conversation.name,), 'Please find the data for the survey %s attached.\n' % ( conversation.name), settings.DEFAULT_FROM_EMAIL, [user_profile.user.email]) zipio = StringIO() zf = ZipFile(zipio, "a", ZIP_DEFLATED) zf.writestr("survey-data-export.csv", csv_data) zf.close() email.attach('survey-data-export.zip', zipio.getvalue(), 'application/zip') email.send()
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. """ api = VumiUserApi.from_config_sync(account_key, settings.VUMI_API_CONFIG) user_profile = UserProfile.objects.get(user_account=account_key) conversation = api.get_wrapped_conversation(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, include_old_questions=include_old_questions) email = EmailMessage( "Survey export for: %s" % (conversation.name,), "Please find the data for the survey %s attached.\n" % (conversation.name), settings.DEFAULT_FROM_EMAIL, [user_profile.user.email], ) zipio = StringIO() zf = ZipFile(zipio, "a", ZIP_DEFLATED) zf.writestr("survey-data-export.csv", csv_data) zf.close() email.attach("survey-data-export.zip", zipio.getvalue(), "application/zip") email.send()
def test_edit(self): conv_helper = self.app_helper.create_conversation_helper() response = self.client.post(conv_helper.get_view_url('edit'), { 'questions-TOTAL_FORMS': 1, 'questions-INITIAL_FORMS': 0, 'questions-MAX_NUM_FORMS': '', 'questions-0-copy': 'What is your favorite music?', 'questions-0-label': 'favorite music', 'questions-0-valid_responses': 'rock, jazz, techno', 'completed_response-TOTAL_FORMS': 0, 'completed_response-INITIAL_FORMS': 0, 'completed_response-MAX_NUM_FORMS': '', }) self.assertRedirects(response, conv_helper.get_view_url('show')) poll_id = 'poll-%s' % (conv_helper.conversation_key,) pm, config = get_poll_config(poll_id) [question] = config['questions'] self.assertEqual(question['copy'], 'What is your favorite music?') self.assertEqual(question['valid_responses'], [ 'rock', 'jazz', 'techno']) self.assertEqual(question['label'], 'favorite music')
def create_poll(self, conversation, **kwargs): poll_id = 'poll-%s' % (conversation.key,) pm, config = get_poll_config(poll_id) config.update(kwargs) return pm, pm.register(poll_id, config)