def make_feed_document_use_form_code_instead_of_form_model_id(db_name): dbm = get_db_manager(db_name) logger = logging.getLogger(db_name) feed_dbm = get_feed_db_from_main_db_name(db_name) questionnaires = dbm.load_all_rows_in_view('all_projects') for questionnaire in questionnaires: try: feeds = feed_dbm.database.iterview( "questionnaire_feed/questionnaire_feed", 1000, startkey=[questionnaire.id], endkey=[questionnaire.id, {}], include_docs=True) for feed in feeds: try: enriched_survey_response = EnrichedSurveyResponseDocument.wrap( feed.doc) enriched_survey_response.form_code = questionnaire[ 'value']['form_code'] feed_dbm._save_document( enriched_survey_response, modified=enriched_survey_response.modified) except Exception as e: logger.exception("failed for feed:" + feed.id) except Exception as e: logger.exception("failed for questionnaire:" + questionnaire.id) mark_as_completed(db_name)
def feed_document(self): status = 'success' if self.survey_response.status else 'error' return EnrichedSurveyResponseDocument( self.survey_response.uuid, self.survey_response.modified, self.survey_response.channel, self.form_model.form_code, self.survey_response.form_model_revision, self._values(), status, self.survey_response.errors, self._data_sender(), self.additional_details, self.survey_response.is_void())
def test_should_update_search_dict_with_form_field_questions_for_error_submissions( self): search_dict = {} values = {'eid': 'test_id', 'q2': 'wrong number', 'q3': 'wrong text'} submission_doc = EnrichedSurveyResponseDocument(values=values, status="error") with patch('datawinners.search.submission_index.lookup_entity_name' ) as lookup_entity_name: lookup_entity_name.return_value = 'Test' _update_with_form_model_fields(None, submission_doc, search_dict, self.form_model) self.assertEquals( { '1212_eid': 'Test', "entity_short_code": "test_id", '1212_q2': 'wrong number', '1212_q3': 'wrong text', 'void': False }, search_dict)
def _update_feed(self, raw_doc, survey_response): existing_enriched_response = EnrichedSurveyResponseDocument.wrap(raw_doc) document = self.enriched_dbm(survey_response) existing_enriched_response.update(document) self.feed_dbm._save_document(existing_enriched_response)