예제 #1
0
    def build_two_error_survey_responses(self):
        doc_id3 = self.manager._save_document(
            SurveyResponseDocument(channel="transport",
                                   destination=12345,
                                   form_model_id=FORM_MODEL_ID,
                                   values={
                                       'Q3': 'ans12',
                                       'Q4': 'ans22'
                                   },
                                   status=False,
                                   error_message=""))
        doc_id4 = self.manager._save_document(
            SurveyResponseDocument(channel="transport",
                                   destination=12345,
                                   form_model_id="def",
                                   values={
                                       'defQ1': 'defans12',
                                       'defQ2': 'defans22'
                                   },
                                   status=False,
                                   error_message=""))

        return [
            SurveyResponse.get(self.manager, id) for id in [doc_id3, doc_id4]
        ]
예제 #2
0
    def build_two_successful_survey_responses(self):
        doc_id1 = self.manager._save_document(
            SurveyResponseDocument(channel="transport",
                                   destination=12345,
                                   form_model_id=FORM_MODEL_ID,
                                   values={
                                       'Q1': 'ans1',
                                       'Q2': 'ans2'
                                   },
                                   status=True,
                                   error_message=""))
        doc_id2 = self.manager._save_document(
            SurveyResponseDocument(channel="transport",
                                   destination=12345,
                                   form_model_id=FORM_MODEL_ID,
                                   values={
                                       'Q1': 'ans12',
                                       'Q2': 'ans22'
                                   },
                                   status=True,
                                   error_message=""))

        return [
            SurveyResponse.get(self.manager, id) for id in [doc_id1, doc_id2]
        ]
예제 #3
0
def delete(request, project_id):
    dbm = get_database_manager(request.user)
    questionnaire = Project.get(dbm, project_id)
    dashboard_page = settings.HOME_PAGE + "?deleted=true"
    if questionnaire.is_void():
        return HttpResponseRedirect(dashboard_page)
    survey_response_ids = get_survey_response_ids_from_request(dbm, request, questionnaire)
    received_times = []
    for survey_response_id in survey_response_ids:
        survey_response = SurveyResponse.get(dbm, survey_response_id)
        received_times.append(datetime.datetime.strftime(survey_response.submitted_on, "%d/%m/%Y %X"))
        feeds_dbm = get_feeds_database(request.user)
        additional_feed_dictionary = get_project_details_dict_for_feed(questionnaire)
        delete_response = WebPlayerV2(dbm, feeds_dbm).delete_survey_response(survey_response,
                                                                             additional_feed_dictionary,
                                                                             websubmission_logger)
        mail_feed_errors(delete_response, dbm.database_name)
        if survey_response.data_record:
            ReportRouter().delete(get_organization(request).org_id, survey_response.form_code,
                                  survey_response.data_record.id)

    if len(received_times):
        UserActivityLog().log(request, action=DELETED_DATA_SUBMISSION, project=questionnaire.name,
                              detail=json.dumps({"Date Received": "[%s]" % ", ".join(received_times)}))
        response = encode_json({'success_message': ugettext("The selected records have been deleted"), 'success': True})
    else:
        response = encode_json({'error_message': ugettext("No records deleted"), 'success': False})

    return HttpResponse(response)
예제 #4
0
 def build(self, owner_id):
     survey_response_id = self.manager._save_document(
         SurveyResponseDocument(channel=self.channel,
                                destination=self.destination,
                                values=self.values,
                                status=self.status,
                                error_message=self.error_message,
                                form_model_id=self.form_model_id,
                                owner_uid=owner_id))
     return SurveyResponse.get(self.manager, survey_response_id)
def _get_survey_responses_with_no_eid(dbm, logger):
    rows = dbm.database.view("surveyresponse/surveyresponse", reduce=False)
    inconsistent_survey_response_list = []
    for row in rows:
        try:
            survey_response = SurveyResponse.get(dbm, row.id)
            form_model = get_form_model_by_code(dbm, survey_response.form_code)
            if form_model.is_entity_type_reporter(
            ) and "eid" not in survey_response.values.keys():
                inconsistent_survey_response_list.append(survey_response)
        except Exception as e:
            logger.exception(e)
    return inconsistent_survey_response_list
예제 #6
0
 def migrate_document(self, survey_response_id):
     survey_response = SurveyResponse.get(self.dbm, survey_response_id)
     self._migrate(survey_response)
     self._log_success_message(survey_response)