def delete_project(manager, project, void=True): project_id, qid = project.id, project.qid [reminder.void(void) for reminder in (Reminder.objects.filter(project_id=project_id))] questionnaire = FormModel.get(manager, qid) questionnaire.void(void) [survey_response.void(void) for survey_response in get_survey_responses(manager, questionnaire.form_code, None, None)] project.set_void(manager, void)
def test_error_messages_are_being_logged_in_survey_responses(self): text = "clinic .EID %s .ARV 150 " % self.entity.short_code self.send_sms_v2(text) survey_responses = get_survey_responses(self.manager, self.form_model_id, 0, self._tomorrow()) self.assertEquals(1, len(survey_responses)) self.assertEquals( u"Answer 150 for question ARV is greater than allowed.", survey_responses[0].errors)
def test_should_get_survey_responses_for_form(self): self.manager._save_document( SurveyResponseDocument(channel="web", destination="", form_model_id="abc", values={ 'Q1': 'ans1', 'Q2': 'ans2' }, status=False, error_message="", data_record_id='2345678')) self.manager._save_document( SurveyResponseDocument(channel="web", destination="", form_model_id="abc", values={ 'Q1': 'ans12', 'Q2': 'ans22' }, status=False, error_message="", data_record_id='1234567')) self.manager._save_document( SurveyResponseDocument(channel="web", destination="", form_model_id="def", values={ 'defQ1': 'defans12', 'defQ2': 'defans22' }, status=False, error_message="", data_record_id='345678')) oneDay = datetime.timedelta(days=1) tomorrow = datetime.datetime.now() + oneDay survey_responses = get_survey_responses( self.manager, "abc", 0, int(mktime(tomorrow.timetuple())) * 1000) self.assertEquals(2, len(survey_responses)) self.assertEquals({ 'Q1': 'ans12', 'Q2': 'ans22' }, survey_responses[0].values) self.assertEquals({ 'Q1': 'ans1', 'Q2': 'ans2' }, survey_responses[1].values)
def test_error_messages_are_being_logged_in_survey_responses(self): text = { 'form_code': 'clinic', 'EID': self.entity.short_code, 'ARV': '150' } self.add_survey_response(text, reporter_id="rep1") oneDay = datetime.timedelta(days=1) tomorrow = datetime.datetime.now() + oneDay survey_responses = get_survey_responses( self.manager, self.form_model.id, 0, int(mktime(tomorrow.timetuple())) * 1000) self.assertEquals(1, len(survey_responses)) self.assertEquals( u"Answer 150 for question ARV is greater than allowed.", survey_responses[0].errors)
def activate_project(request, project_id=None): manager = get_database_manager(request.user) project = Project.load(manager.database, project_id) project.activate(manager) form_model = FormModel.get(manager, project.qid) oneDay = datetime.timedelta(days=1) tomorrow = datetime.datetime.now() + oneDay survey_responses = get_survey_responses(manager, form_model.form_code, from_time=0, to_time=int(mktime(tomorrow.timetuple())) * 1000, page_size=None) feeds_dbm = get_feeds_database(request.user) service = SurveyResponseService(manager, logger, feeds_dbm) additional_feed_dictionary = get_project_details_dict_for_feed(project) for survey_response in survey_responses: service.delete_survey(survey_response, additional_feed_dictionary) UserActivityLog().log(request, action=ACTIVATED_PROJECT, project=project.name) return HttpResponseRedirect(reverse('project-overview', args=[project_id]))
def test_get_survey_responses_for_form(self): self._prepare_survey_responses() survey_responses = get_survey_responses(self.manager, FORM_MODEL_ID, 0, self._tomorrow()) self.assertEquals(3, len(survey_responses)) self.assertEquals({ 'Q3': 'ans12', 'Q4': 'ans22' }, survey_responses[0].values) self.assertEquals({ 'Q1': 'ans12', 'Q2': 'ans22' }, survey_responses[1].values) self.assertEquals({ 'Q1': 'ans1', 'Q2': 'ans2' }, survey_responses[2].values)
def get_submissions(self): submission_list = [] submissions = get_survey_responses( self.manager, self.questionnaire.id, None, None, view_name="undeleted_survey_response") for submission in submissions: submission_list.append({ 'submission_uuid': submission.id, 'version': submission.version, 'project_uuid': self.questionnaire.id, 'created': py_datetime_to_js_datestring(submission.created) }) return submission_list
def _update_survey_responses(manager, questionnaire, void): [ survey_response.void(void) for survey_response in get_survey_responses( manager, questionnaire.id, None, None) ]