def build_static_info_context(manager, survey_response, ui_model=None, questionnaire_form_model=None, reporter_id=None): form_ui_model = OrderedDict() if ui_model is None else ui_model sender_name, sender_id = get_data_sender(manager, survey_response)[:2] if sender_id == 'N/A': static_content = {'Data Sender': (survey_response.created_by, '')} else: static_content = {'Data Sender': (sender_name, sender_id)} static_content.update({ 'Source': capitalize(survey_response.channel) if survey_response.channel == 'web' else survey_response.channel.upper(), 'Submission Date': survey_response.submitted_on.strftime( SUBMISSION_DATE_FORMAT_FOR_SUBMISSION) }) form_ui_model.update({'static_content': static_content}) form_ui_model.update({'is_edit': True}) form_ui_model.update({ 'status': ugettext('Success') if survey_response.status else ugettext('Error') }) return form_ui_model
def test_should_return_data_sender_TESTER_when_send_from_TEST_REPORTER_MOBILE_NUMBER( self): survey_response = SurveyResponse( TestDataSenderHelper.manager, TransportInfo("sms", TEST_REPORTER_MOBILE_NUMBER, "destination"), owner_uid=self.test_ds_id) data_sender = get_data_sender(TestDataSenderHelper.manager, survey_response) self.assertEqual(('TEST', 'test', data_sender[2]), data_sender)
def test_should_return_N_A_when_the_data_sender_was_deleted_and_send_from_smart_phone( self): survey_response = SurveyResponse(TestDataSenderHelper.manager, TransportInfo("smartPhone", "*****@*****.**", "destination"), owner_uid=self.deleted_ds_id) data_sender = get_data_sender(TestDataSenderHelper.manager, survey_response) self.assertEqual(("M K Gandhi", u"del1"), data_sender[:2])
def test_should_return_data_sender_information_send_from_web(self): beany_tester_id = get_by_short_code_include_voided( TestDataSenderHelper.manager, "rep1", REPORTER_ENTITY_TYPE).id survey_response = SurveyResponse(TestDataSenderHelper.manager, TransportInfo( "web", "*****@*****.**", "destination"), owner_uid=beany_tester_id) data_sender = get_data_sender(TestDataSenderHelper.manager, survey_response) self.assertEqual(("Beany", "rep1", data_sender[2]), data_sender)
def build_static_info_context(manager, survey_response, ui_model=None): form_ui_model = OrderedDict() if ui_model is None else ui_model static_content = {'Data Sender': get_data_sender(manager, survey_response), 'Source': capitalize( survey_response.channel) if survey_response.channel == 'web' else survey_response.channel.upper(), 'Submission Date': survey_response.submitted_on.strftime(SUBMISSION_DATE_FORMAT_FOR_SUBMISSION) } form_ui_model.update({'static_content': static_content}) form_ui_model.update({'is_edit': True}) form_ui_model.update({'status': ugettext('Success') if survey_response.status else ugettext('Error')}) return form_ui_model
def edit(request, project_id, survey_response_id, tab=0): manager = get_database_manager(request.user) questionnaire_form_model = Project.get(manager, project_id) dashboard_page = settings.HOME_PAGE + "?deleted=true" reporter_id = NGOUserProfile.objects.get(user=request.user).reporter_id is_linked = reporter_id in questionnaire_form_model.data_senders reporter_name = NGOUserProfile.objects.get( user=request.user).user.first_name if questionnaire_form_model.is_void(): return HttpResponseRedirect(dashboard_page) disable_link_class, hide_link_class = get_visibility_settings_for( request.user) survey_response = get_survey_response_by_id(manager, survey_response_id) back_link = reverse(index, kwargs={ "project_id": project_id, "questionnaire_code": questionnaire_form_model.form_code, "tab": tab }) form_ui_model = build_static_info_context( manager, survey_response, questionnaire_form_model=questionnaire_form_model, reporter_id=reporter_id) form_ui_model.update({ "back_link": back_link, 'is_datasender': is_data_sender(request), 'hide_change': questionnaire_form_model.is_poll and questionnaire_form_model.is_open_survey }) data_sender = get_data_sender(manager, survey_response) short_code = data_sender[1] enable_datasender_edit = True if survey_response.owner_uid else False if request.method == 'GET': form_initial_values = construct_request_dict(survey_response, questionnaire_form_model, short_code) survey_response_form = SurveyResponseForm( questionnaire_form_model, form_initial_values, datasender_name=data_sender[0], reporter_id=reporter_id, reporter_name=reporter_name, enable_datasender_edit=enable_datasender_edit) form_ui_model.update( get_form_context(questionnaire_form_model, survey_response_form, manager, hide_link_class, disable_link_class)) form_ui_model.update({ "redirect_url": "", "reporter_id": reporter_id, "is_linked": is_linked, "is_pro_sms": get_organization(request).is_pro_sms, "reporter_name": reporter_name }) if not survey_response_form.is_valid( ) or form_ui_model['datasender_error_message']: error_message = _("Please check your answers below for errors.") form_ui_model.update({ 'error_message': error_message, "reporter_id": reporter_id, "is_linked": is_linked, "reporter_name": reporter_name }) return render_to_response("project/web_questionnaire.html", form_ui_model, context_instance=RequestContext(request)) if request.method == 'POST': send_to_carbon(create_path('submissions.web.simple'), 1) original_survey_response = survey_response.copy() is_errored_before_edit = True if survey_response.errors != '' else False submitted_values = request.POST owner_id = submitted_values.get("dsid") form_ui_model.update({ "redirect_url": submitted_values.get("redirect_url"), 'is_datasender': is_data_sender(request), "is_pro_sms": get_organization(request).is_pro_sms }) form_ui_model.update( {"click_after_reload": submitted_values.get("click_after_reload")}) if submitted_values.get("discard"): survey_response_form = SurveyResponseForm(questionnaire_form_model, survey_response.values) form_ui_model.update( get_form_context(questionnaire_form_model, survey_response_form, manager, hide_link_class, disable_link_class)) form_ui_model.update({ "reporter_id": reporter_id, "is_linked": is_linked, "reporter_name": reporter_name }) return render_to_response("project/web_questionnaire.html", form_ui_model, context_instance=RequestContext(request)) else: form_initial_values = construct_request_dict( survey_response, questionnaire_form_model, short_code) if not owner_id: submitted_values = submitted_values.copy() submitted_values['dsid'] = form_initial_values['dsid'] survey_response_form = SurveyResponseForm( questionnaire_form_model, submitted_values, initial=form_initial_values, enable_datasender_edit=enable_datasender_edit) form_ui_model.update( get_form_context(questionnaire_form_model, survey_response_form, manager, hide_link_class, disable_link_class)) form_ui_model.update({ "reporter_id": reporter_id, "is_linked": is_linked }) if not survey_response_form.is_valid(): error_message = _("Please check your answers below for errors.") form_ui_model.update({ 'error_message': error_message, "reporter_id": reporter_id, "is_linked": is_linked }) return render_to_response("project/web_questionnaire.html", form_ui_model, context_instance=RequestContext(request)) success_message = _("Your changes have been saved.") form_ui_model.update({ 'success_message': success_message, "reporter_id": reporter_id, "is_linked": is_linked, "reporter_name": reporter_name }) # if len(survey_response_form.changed_data) or is_errored_before_edit: created_request = helper.create_request(survey_response_form, request.user.username) additional_feed_dictionary = get_project_details_dict_for_feed( questionnaire_form_model) user_profile = NGOUserProfile.objects.get(user=request.user) feeds_dbm = get_feeds_database(request.user) response = WebPlayerV2(manager, feeds_dbm, user_profile.reporter_id) \ .edit_survey_response(created_request, survey_response, owner_id, additional_feed_dictionary, websubmission_logger) mail_feed_errors(response, manager.database_name) if response.success: build_static_info_context(manager, survey_response, form_ui_model, questionnaire_form_model, reporter_id) ReportRouter().route(get_organization(request).org_id, response) _update_static_info_block_status(form_ui_model, is_errored_before_edit) log_edit_action(original_survey_response, survey_response, request, questionnaire_form_model.name, questionnaire_form_model) if submitted_values.get("redirect_url"): return HttpResponseRedirect( submitted_values.get("redirect_url")) else: del form_ui_model["success_message"] survey_response_form._errors = helper.errors_to_list( response.errors, questionnaire_form_model.fields) form_ui_model.update({ "reporter_id": reporter_id, "is_linked": is_linked, "reporter_name": reporter_name }) return render_to_response("project/web_questionnaire.html", form_ui_model, context_instance=RequestContext(request))