def get_preload_action(): preload = { '/data/start_date': 'start_date', '/data/start_time': 'start_time', '/data/end_date': 'end_date', '/data/end_time': 'end_time', } for item_group in self.iter_item_groups(): for item in item_group.iter_items(): preload['/data/{}/{}'.format( item_group.question_name, item.question_name)] = item.question_name return PreloadAction(preload=preload, condition=FormActionCondition(type='always'))
def add_edit_form_to_module(module_): edit_form = module_.new_form('Edit Subject', None) edit_form.get_unique_id() edit_form.source = self.get_subject_form_source('Edit Subject') edit_form.requires = 'case' update = dict(self.case_update, name='/data/' + CC_SUBJECT_KEY) preload = {v: k for k, v in update.items()} edit_form.actions.case_preload = PreloadAction( preload=preload, condition=FormActionCondition(type='always') ) edit_form.actions.update_case = UpdateCaseAction( update=update, condition=FormActionCondition(type='always') )
def form_requires_case(form, case_type=None, parent_case_type=None, update=None, preload=None): if update: update = { name: ConditionalCaseUpdate(question_path=question_path) for name, question_path in update.items() } if form.form_type == 'module_form': form.requires = 'case' if update: form.actions.update_case = UpdateCaseAction(update=update) form.actions.update_case.condition.type = 'always' if preload: form.actions.case_preload = PreloadAction(preload=preload) form.actions.case_preload.condition.type = 'always' if parent_case_type: module = form.get_module() module.parent_select.active = True parent_select_module = next( module for module in module.get_app().get_modules() if module.case_type == parent_case_type) module.parent_select.module_id = parent_select_module.unique_id else: case_type = case_type or form.get_module().case_type index = len([ load for load in form.actions.load_update_cases if load.case_type == case_type ]) kwargs = { 'case_type': case_type, 'case_tag': 'load_{}_{}'.format(case_type, index) } if update: kwargs['case_properties'] = update if preload: kwargs['preload'] = preload action = LoadUpdateAction(**kwargs) if parent_case_type: parent_action = form.actions.load_update_cases[-1] assert parent_action.case_type == parent_case_type action.case_index = CaseIndex(tag=parent_action.case_tag) form.actions.load_update_cases.append(action)
def test_legacy_preload_action_case_references(self): self.form.actions.load_from_form = PreloadAction({ "preload": { "/data/question": "name" }, "condition": { "answer": None, "question": None, "type": "always", "operator": None, } }) _assert_references_equal(self, self.form.case_references, {"load": { "/data/question": ["name"] }})
def test_usercase_id_added_preload(self): app = Application.new_app('domain', "Untitled Application") child_module = app.add_module( Module.new_module("Untitled Module", None)) child_module.case_type = 'child' child_form = app.new_form(0, "Untitled Form", None) child_form.xmlns = 'http://id_m1-f0' child_form.requires = 'case' child_form.actions.usercase_preload = PreloadAction( preload={'/data/question1': 'name'}) child_form.actions.usercase_preload.condition.type = 'always' self.assertXmlPartialEqual(self.get_xml('usercase_entry'), app.create_suite(), "./entry[1]")
def test_child_module_session_datums_added(self): m0f0 = self.module_0.get_form(0) # m0 is a user-case-only module. m0f0 does not update a normal case, only the user case. m0f0.actions.usercase_preload = PreloadAction(preload={'/data/question1': 'question1'}) m0f0.actions.usercase_preload.condition.type = 'always' self.factory.form_opens_case(m0f0, 'guppy', is_subcase=True) m1f0 = self.module_1.get_form(0) self.factory.form_requires_case(m1f0, 'guppy', parent_case_type='gold-fish') self.assertXmlPartialEqual( self.get_xml('child-module-entry-datums-added-usercase'), self.app.create_suite(), "./entry" )
def migrate_app(self, app_id): app = Application.get(app_id) if app.vellum_case_management: logger.info('already migrated app {}'.format(app_id)) return modules = [m for m in app.modules if m.module_type == 'basic'] for module in modules: forms = [f for f in module.forms if f.doc_type == 'Form'] for form in forms: preload = form.actions.case_preload.preload if preload: xform = XForm(form.source) xform.add_case_preloads(preload) save_xform(app, form, ET.tostring(xform.xml)) form.actions.load_from_form = form.actions.case_preload form.actions.case_preload = PreloadAction() app.vellum_case_management = True app.save()
def test_child_module_session_datums_added(self): self.module_1.root_module_id = self.module_0.unique_id self.module_0.case_type = 'gold-fish' m0f0 = self.module_0.get_form(0) # m0 is a user-case-only module. m0f0 does not update a normal case, only the user case. m0f0.actions.usercase_preload = PreloadAction( preload={'/data/question1': 'question1'}) m0f0.actions.usercase_preload.condition.type = 'always' m0f0.actions.subcases.append( OpenSubCaseAction(case_type='guppy', case_name="/data/question1", condition=FormActionCondition(type='always'))) self.module_1.case_type = 'guppy' m1f0 = self.module_1.get_form(0) self._load_case(m1f0, 'gold-fish') self._load_case(m1f0, 'guppy', parent_module=self.module_0) self.assertXmlPartialEqual( self.get_xml('child-module-entry-datums-added-usercase'), self.app.create_suite(), "./entry")
def migrate_app(self, app_id): app = Application.get(app_id) if app.vellum_case_management: logger.info('already migrated app {}'.format(app_id)) return modules = [m for m in app.modules if m.module_type == 'basic'] for module in modules: forms = [f for f in module.forms if f.doc_type == 'Form'] for form in forms: preload = form.actions.case_preload.preload if preload: if form.requires == 'case': xform = XForm(form.source) xform.add_case_preloads(preload) save_xform(app, form, ET.tostring(xform.xml)) form.case_references = {"load": {path: [case_property] for path, case_property in preload.iteritems()}} form.actions.case_preload = PreloadAction() app.vellum_case_management = True app.save()
def get_preload_action(): return PreloadAction(preload={'/data/subject_name': 'name'}, condition=FormActionCondition(type='always'))
def _update_case_refs_from_form_builder(form, reference_json): if form.form_type == 'module_form': form.actions.load_from_form = PreloadAction.wrap(reference_json)