def db_archive_questionnaire_schema(store, submission): if (store.find(ArchivedSchema, ArchivedSchema.hash == submission.questionnaire_hash).count() <= 0): for lang in GLSettings.memory_copy.languages_enabled: aqs = ArchivedSchema() aqs.hash = submission.questionnaire_hash aqs.type = u'questionnaire' aqs.language = lang aqs.schema = db_get_context_steps(store, submission.context_id, lang) store.add(aqs) preview = [] for s in aqs.schema: for f in s['children']: if f['preview']: preview.append(f) aqsp = ArchivedSchema() aqsp.hash = submission.questionnaire_hash aqsp.type = u'preview' aqsp.language = lang aqsp.schema = preview store.add(aqsp)
def handle_internaltip_fixes(self, new_obj, old_obj): old_node = self.store_old.find(self.get_right_model("Node", 22)).one() questionnaire, answers = self.extract_answers_from_wb_steps( old_obj.wb_steps) new_obj.questionnaire_hash = sha256(json.dumps(questionnaire)) aqs = self.store_new.find( ArchivedSchema, ArchivedSchema.hash == unicode(new_obj.questionnaire_hash), ArchivedSchema.type == u'questionnaire', ArchivedSchema.language == unicode( old_node.default_language)).one() if not aqs: for lang in old_node.languages_enabled: aqs = ArchivedSchema() aqs.hash = new_obj.questionnaire_hash aqs.type = u'questionnaire' aqs.language = lang aqs.schema = questionnaire self.store_new.add(aqs) preview = [] for s in aqs.schema: for f in s['children']: if f['preview']: preview.append(f) aqsp = ArchivedSchema() aqsp.hash = new_obj.questionnaire_hash aqsp.type = u'preview' aqsp.language = lang aqsp.schema = preview self.store_new.add(aqsp) db_save_questionnaire_answers(self.store_new, new_obj, answers) new_obj.preview = extract_answers_preview(questionnaire, answers)
def handle_internaltip_fixes(self, new_obj, old_obj): old_node = self.store_old.find(self.get_right_model("Node", 22)).one() questionnaire, answers = self.extract_answers_from_wb_steps(old_obj.wb_steps) new_obj.questionnaire_hash = sha256(json.dumps(questionnaire)) aqs = self.store_new.find(ArchivedSchema, ArchivedSchema.hash == unicode(new_obj.questionnaire_hash), ArchivedSchema.type == u'questionnaire', ArchivedSchema.language == unicode(old_node.default_language)).one() if not aqs: for lang in old_node.languages_enabled: aqs = ArchivedSchema() aqs.hash = new_obj.questionnaire_hash aqs.type = u'questionnaire' aqs.language = lang aqs.schema = questionnaire self.store_new.add(aqs) preview = [] for s in aqs.schema: for f in s['children']: if f['preview']: preview.append(f) aqsp = ArchivedSchema() aqsp.hash = new_obj.questionnaire_hash aqsp.type = u'preview' aqsp.language = lang aqsp.schema = preview self.store_new.add(aqsp) db_save_questionnaire_answers(self.store_new, new_obj, answers) new_obj.preview = extract_answers_preview(questionnaire, answers)