def get_datum_meta_assertions_advanced(self, module, form): def get_target_module(case_type, module_id, with_product_details=False): if module_id: if module_id == module.unique_id: return module from corehq.apps.app_manager.models import ModuleNotFoundException try: target = module.get_app().get_module_by_unique_id(module_id) if target.case_type != case_type: raise ParentModuleReferenceError("Module with ID %s has incorrect case type" % module_id) if with_product_details and not hasattr(target, "product_details"): raise ParentModuleReferenceError( "Module with ID %s has no product details configuration" % module_id ) return target except ModuleNotFoundException as ex: raise ParentModuleReferenceError(ex.message) else: if case_type == module.case_type: return module target_modules = [ mod for mod in module.get_app().modules if mod.case_type == case_type and (not with_product_details or hasattr(mod, "product_details")) ] try: return target_modules[0] except IndexError: raise ParentModuleReferenceError( "Module with case type %s in app %s not found" % (case_type, self.app) ) def get_manual_datum(action_, parent_filter_=""): target_module_ = get_target_module(action_.case_type, action_.details_module) referenced_by = form.actions.actions_meta_by_parent_tag.get(action_.case_tag) filter_xpath = EntriesHelper.get_filter_xpath(target_module_) detail_persistent, detail_inline = self.get_case_tile_datum_attrs(target_module_, target_module_) return SessionDatum( id=action_.case_session_var, nodeset=( EntriesHelper.get_nodeset_xpath(action_.case_type, filter_xpath=filter_xpath) + parent_filter_ ), value="./@case_id", detail_select=self.details_helper.get_detail_id_safe(target_module_, "case_short"), detail_confirm=( self.details_helper.get_detail_id_safe(target_module_, "case_long") if not referenced_by or referenced_by["type"] != "load" else None ), detail_persistent=detail_persistent, detail_inline=detail_inline, ) datums = [] assertions = [] for action in form.actions.get_load_update_actions(): auto_select = action.auto_select if auto_select and auto_select.mode: datum, assertions = EntriesHelper.get_auto_select_datums_and_assertions(action, auto_select, form) datums.append(FormDatumMeta(datum=datum, case_type=None, requires_selection=False, action=action)) else: if action.case_index.tag: parent_action = form.actions.actions_meta_by_tag[action.case_index.tag]["action"] parent_filter = EntriesHelper.get_parent_filter( action.case_index.reference_id, parent_action.case_session_var ) else: parent_filter = "" datums.append( FormDatumMeta( datum=get_manual_datum(action, parent_filter), case_type=action.case_type, requires_selection=True, action=action, ) ) if module.get_app().commtrack_enabled: try: last_action = list(form.actions.get_load_update_actions())[-1] if last_action.show_product_stock: nodeset = ProductInstanceXpath().instance() if last_action.product_program: nodeset = nodeset.select("program_id", last_action.product_program) target_module = get_target_module(last_action.case_type, last_action.details_module, True) datums.append( FormDatumMeta( datum=SessionDatum( id="product_id", nodeset=nodeset, value="./@id", detail_select=self.details_helper.get_detail_id_safe(target_module, "product_short"), ), case_type=None, requires_selection=True, action=None, ) ) except IndexError: pass self.add_parent_datums(datums, module) return datums, assertions
def get_datum_meta_assertions_advanced(self, module, form): def get_target_module(case_type, module_id, with_product_details=False): if module_id: if module_id == module.unique_id: return module from corehq.apps.app_manager.models import ModuleNotFoundException try: target = module.get_app().get_module_by_unique_id(module_id, error=_("Could not find target module used by form '{}'").format(form.default_name())) if target.case_type != case_type: raise ParentModuleReferenceError( _("Form '%s' in module '%s' references a module with an incorrect case type: " "module '%s' expected '%s', found '%s'") % ( form.default_name(), module.default_name(), target.default_name(), case_type, target.case_type, ) ) if with_product_details and not hasattr(target, 'product_details'): raise ParentModuleReferenceError( "Module with ID %s has no product details configuration" % module_id ) return target except ModuleNotFoundException as ex: raise ParentModuleReferenceError(ex.message) else: if case_type == module.case_type: return module target_modules = [ mod for mod in module.get_app().modules if mod.case_type == case_type and (not with_product_details or hasattr(mod, 'product_details')) ] try: return target_modules[0] except IndexError: raise ParentModuleReferenceError( "Module with case type %s in app %s not found" % (case_type, self.app) ) def get_manual_datum(action_, parent_filter_=''): target_module_ = get_target_module(action_.case_type, action_.details_module) referenced_by = form.actions.actions_meta_by_parent_tag.get(action_.case_tag) filter_xpath = EntriesHelper.get_filter_xpath(target_module_) return SessionDatum( id=action_.case_session_var, nodeset=(EntriesHelper.get_nodeset_xpath(action_.case_type, filter_xpath=filter_xpath) + parent_filter_), value="./@case_id", detail_select=self.details_helper.get_detail_id_safe(target_module_, 'case_short'), detail_confirm=( self.details_helper.get_detail_id_safe(target_module_, 'case_long') if not referenced_by or referenced_by['type'] != 'load' else None ), detail_persistent=self.get_detail_persistent_attr(target_module_, target_module_, "case_short"), detail_inline=self.get_detail_inline_attr(target_module_, target_module_, "case_short"), autoselect=target_module_.auto_select_case, ) datums = [] assertions = [] for action in form.actions.get_load_update_actions(): auto_select = action.auto_select load_case_from_fixture = action.load_case_from_fixture if auto_select and auto_select.mode: datum, assertions = EntriesHelper.get_auto_select_datums_and_assertions(action, auto_select, form) datums.append(FormDatumMeta( datum=datum, case_type=None, requires_selection=False, action=action )) elif load_case_from_fixture: target_module = get_target_module(action.case_type, action.details_module) datums.extend(self.get_load_case_from_fixture_datums(action, target_module, form)) else: if action.case_index.tag: parent_action = form.actions.actions_meta_by_tag[action.case_index.tag]['action'] parent_filter = EntriesHelper.get_parent_filter( action.case_index.reference_id, parent_action.case_session_var ) else: parent_filter = '' datums.append(FormDatumMeta( datum=get_manual_datum(action, parent_filter), case_type=action.case_type, requires_selection=True, action=action )) if module.get_app().commtrack_enabled: try: last_action = list(form.actions.get_load_update_actions())[-1] if last_action.show_product_stock: nodeset = ProductInstanceXpath().instance() if last_action.product_program: nodeset = nodeset.select('program_id', last_action.product_program) target_module = get_target_module(last_action.case_type, last_action.details_module, True) datums.append(FormDatumMeta( datum=SessionDatum( id='product_id', nodeset=nodeset, value="./@id", detail_select=self.details_helper.get_detail_id_safe(target_module, 'product_short'), detail_persistent=self.get_detail_persistent_attr( target_module, target_module, "product_short" ), detail_inline=self.get_detail_inline_attr( target_module, target_module, "product_short" ), ), case_type=None, requires_selection=True, action=None )) except IndexError: pass self.add_parent_datums(datums, module) return datums, assertions
def get_datum_meta_assertions_advanced(self, module, form): def get_target_module(case_type, module_id, with_product_details=False): if module_id: if module_id == module.unique_id: return module from corehq.apps.app_manager.models import ModuleNotFoundException try: target = module.get_app().get_module_by_unique_id(module_id, error=_("Could not find target module used by form '{}'").format(form.default_name())) if target.case_type != case_type: raise ParentModuleReferenceError( _( "Form '%(form_name)s' in module '%(module_name)s' " "references a module with an incorrect case type: " "module '%(target_name)s' expected '%(expected_case_type)s', " "found '%(target_case_type)s'" ) % { 'form_name': form.default_name(), 'module_name': module.default_name(), 'target_name': target.default_name(), 'expected_case_type': case_type, 'target_case_type': target.case_type, } ) if with_product_details and not hasattr(target, 'product_details'): raise ParentModuleReferenceError( "Module with ID %s has no product details configuration" % module_id ) return target except ModuleNotFoundException as ex: raise ParentModuleReferenceError(ex.message) else: if case_type == module.case_type: return module target_modules = [ mod for mod in module.get_app().modules if mod.case_type == case_type and (not with_product_details or hasattr(mod, 'product_details')) ] try: return target_modules[0] except IndexError: raise ParentModuleReferenceError( "Module with case type %s in app %s not found" % (case_type, self.app) ) def get_manual_datum(action_, parent_filter_=''): target_module_ = get_target_module(action_.case_type, action_.details_module) referenced_by = form.actions.actions_meta_by_parent_tag.get(action_.case_tag) filter_xpath = EntriesHelper.get_filter_xpath(target_module_) detail_inline = self.get_detail_inline_attr(target_module_, target_module_, "case_short") return SessionDatum( id=action_.case_session_var, nodeset=(EntriesHelper.get_nodeset_xpath(action_.case_type, filter_xpath=filter_xpath) + parent_filter_), value="./@case_id", detail_select=self.details_helper.get_detail_id_safe(target_module_, 'case_short'), detail_confirm=( self.details_helper.get_detail_id_safe(target_module_, 'case_long') if (not referenced_by or referenced_by['type'] != 'load') and not detail_inline else None ), detail_persistent=self.get_detail_persistent_attr(target_module_, target_module_, "case_short"), detail_inline=detail_inline, autoselect=target_module_.auto_select_case, ) datums = [] assertions = [] for action in form.actions.get_load_update_actions(): auto_select = action.auto_select load_case_from_fixture = action.load_case_from_fixture if auto_select and auto_select.mode: datum, assertions = EntriesHelper.get_auto_select_datums_and_assertions(action, auto_select, form) datums.append(FormDatumMeta( datum=datum, case_type=None, requires_selection=False, action=action )) elif load_case_from_fixture: target_module = get_target_module(action.case_type, action.details_module) datums.extend(self.get_load_case_from_fixture_datums(action, target_module, form)) else: if action.case_index.tag: parent_action = form.actions.actions_meta_by_tag[action.case_index.tag]['action'] parent_filter = EntriesHelper.get_parent_filter( action.case_index.reference_id, parent_action.case_session_var ) else: parent_filter = '' datums.append(FormDatumMeta( datum=get_manual_datum(action, parent_filter), case_type=action.case_type, requires_selection=True, action=action )) if module.get_app().commtrack_enabled: try: last_action = list(form.actions.get_load_update_actions())[-1] if last_action.show_product_stock: nodeset = ProductInstanceXpath().instance() if last_action.product_program: nodeset = nodeset.select('program_id', last_action.product_program) target_module = get_target_module(last_action.case_type, last_action.details_module, True) datums.append(FormDatumMeta( datum=SessionDatum( id='product_id', nodeset=nodeset, value="./@id", detail_select=self.details_helper.get_detail_id_safe(target_module, 'product_short'), detail_persistent=self.get_detail_persistent_attr( target_module, target_module, "product_short" ), detail_inline=self.get_detail_inline_attr( target_module, target_module, "product_short" ), ), case_type=None, requires_selection=True, action=None )) except IndexError: pass self.add_parent_datums(datums, module) return datums, assertions