Exemplo n.º 1
0
 def get_auto_select_datums_and_assertions(action, auto_select, form):
     from corehq.apps.app_manager.models import AUTO_SELECT_USER, AUTO_SELECT_CASE, \
         AUTO_SELECT_FIXTURE, AUTO_SELECT_RAW, AUTO_SELECT_USERCASE
     if auto_select.mode == AUTO_SELECT_USER:
         return EntriesHelper.get_userdata_autoselect(
             auto_select.value_key,
             action.case_session_var,
             auto_select.mode,
         )
     elif auto_select.mode == AUTO_SELECT_CASE:
         try:
             ref = form.actions.actions_meta_by_tag[auto_select.value_source]['action']
             sess_var = ref.case_session_var
         except KeyError:
             raise ValueError("Case tag not found: %s" % auto_select.value_source)
         xpath = CaseIDXPath(session_var(sess_var)).case().index_id(auto_select.value_key)
         assertions = EntriesHelper.get_auto_select_assertions(xpath, auto_select.mode, [auto_select.value_key])
         return SessionDatum(
             id=action.case_session_var,
             function=xpath
         ), assertions
     elif auto_select.mode == AUTO_SELECT_FIXTURE:
         xpath_base = ItemListFixtureXpath(auto_select.value_source).instance()
         xpath = xpath_base.slash(auto_select.value_key)
         fixture_assertion = EntriesHelper.get_assertion(
             "{0} = 1".format(xpath_base.count()),
             'case_autoload.{0}.exactly_one_fixture'.format(auto_select.mode),
             [auto_select.value_source]
         )
         assertions = EntriesHelper.get_auto_select_assertions(xpath, auto_select.mode, [auto_select.value_key])
         return SessionDatum(
             id=action.case_session_var,
             function=xpath
         ), [fixture_assertion] + assertions
     elif auto_select.mode == AUTO_SELECT_RAW:
         case_id_xpath = auto_select.value_key
         case_count = CaseIDXPath(case_id_xpath).case().count()
         return SessionDatum(
             id=action.case_session_var,
             function=case_id_xpath
         ), [
             EntriesHelper.get_assertion(
                 "{0} = 1".format(case_count),
                 'case_autoload.{0}.case_missing'.format(auto_select.mode)
             )
         ]
     elif auto_select.mode == AUTO_SELECT_USERCASE:
         case = UserCaseXPath().case()
         return SessionDatum(
             id=action.case_session_var,
             function=case.slash('@case_id')
         ), [
             EntriesHelper.get_assertion(
                 "{0} = 1".format(case.count()),
                 'case_autoload.{0}.case_missing'.format(auto_select.mode)
             )
         ]
Exemplo n.º 2
0
 def get_auto_select_datums_and_assertions(action, auto_select, form):
     from corehq.apps.app_manager.models import AUTO_SELECT_USER, AUTO_SELECT_CASE, \
         AUTO_SELECT_FIXTURE, AUTO_SELECT_RAW, AUTO_SELECT_USERCASE
     if auto_select.mode == AUTO_SELECT_USER:
         return EntriesHelper.get_userdata_autoselect(
             auto_select.value_key,
             action.case_session_var,
             auto_select.mode,
         )
     elif auto_select.mode == AUTO_SELECT_CASE:
         try:
             ref = form.actions.actions_meta_by_tag[auto_select.value_source]['action']
             sess_var = ref.case_session_var
         except KeyError:
             raise ValueError("Case tag not found: %s" % auto_select.value_source)
         xpath = CaseIDXPath(session_var(sess_var)).case().index_id(auto_select.value_key)
         assertions = EntriesHelper.get_auto_select_assertions(xpath, auto_select.mode, [auto_select.value_key])
         return SessionDatum(
             id=action.case_session_var,
             function=xpath
         ), assertions
     elif auto_select.mode == AUTO_SELECT_FIXTURE:
         xpath_base = ItemListFixtureXpath(auto_select.value_source).instance()
         xpath = xpath_base.slash(auto_select.value_key)
         fixture_assertion = EntriesHelper.get_assertion(
             "{0} = 1".format(xpath_base.count()),
             'case_autoload.{0}.exactly_one_fixture'.format(auto_select.mode),
             [auto_select.value_source]
         )
         assertions = EntriesHelper.get_auto_select_assertions(xpath, auto_select.mode, [auto_select.value_key])
         return SessionDatum(
             id=action.case_session_var,
             function=xpath
         ), [fixture_assertion] + assertions
     elif auto_select.mode == AUTO_SELECT_RAW:
         case_id_xpath = auto_select.value_key
         case_count = CaseIDXPath(case_id_xpath).case().count()
         return SessionDatum(
             id=action.case_session_var,
             function=case_id_xpath
         ), [
             EntriesHelper.get_assertion(
                 "{0} = 1".format(case_count),
                 'case_autoload.{0}.case_missing'.format(auto_select.mode)
             )
         ]
     elif auto_select.mode == AUTO_SELECT_USERCASE:
         case = UserCaseXPath().case()
         return SessionDatum(
             id=action.case_session_var,
             function=case.slash('@case_id')
         ), [
             EntriesHelper.get_assertion(
                 "{0} = 1".format(case.count()),
                 'case_autoload.{0}.case_missing'.format(auto_select.mode)
             )
         ]
Exemplo n.º 3
0
    def get_datum_meta_module(self, module, use_filter=False):
        datums = []
        datum_module = module.source_module if module.module_type == 'shadow' else module
        datums_meta = get_select_chain_meta(self.app, datum_module)
        for i, datum in enumerate(datums_meta):
            # get the session var for the previous datum if there is one
            parent_id = datums_meta[i - 1]['session_var'] if i >= 1 else ''
            if parent_id:
                parent_filter = EntriesHelper.get_parent_filter(
                    datum['module'].parent_select.relationship, parent_id
                )
            else:
                parent_filter = ''

            detail_module = module if module.module_type == 'shadow' else datum['module']
            detail_persistent = self.get_detail_persistent_attr(datum['module'], detail_module, "case_short")
            detail_inline = self.get_detail_inline_attr(datum['module'], detail_module, "case_short")

            fixture_select_filter = ''
            if datum['module'].fixture_select.active:
                datums.append(FormDatumMeta(
                    datum=SessionDatum(
                        id=id_strings.fixture_session_var(datum['module']),
                        nodeset=ItemListFixtureXpath(datum['module'].fixture_select.fixture_type).instance(),
                        value=datum['module'].fixture_select.variable_column,
                        detail_select=id_strings.fixture_detail(detail_module)
                    ),
                    case_type=None,
                    requires_selection=True,
                    action='fixture_select'
                ))
                filter_xpath_template = datum['module'].fixture_select.xpath
                fixture_value = session_var(id_strings.fixture_session_var(datum['module']))
                fixture_select_filter = "[{}]".format(
                    filter_xpath_template.replace('$fixture_value', fixture_value)
                )

            filter_xpath = EntriesHelper.get_filter_xpath(detail_module) if use_filter else ''

            datums.append(FormDatumMeta(
                datum=SessionDatum(
                    id=datum['session_var'],
                    nodeset=(EntriesHelper.get_nodeset_xpath(datum['case_type'], filter_xpath=filter_xpath)
                             + parent_filter + fixture_select_filter),
                    value="./@case_id",
                    detail_select=self.details_helper.get_detail_id_safe(detail_module, 'case_short'),
                    detail_confirm=(
                        self.details_helper.get_detail_id_safe(detail_module, 'case_long')
                        if datum['index'] == 0 and not detail_inline else None
                    ),
                    detail_persistent=detail_persistent,
                    detail_inline=detail_inline,
                    autoselect=datum['module'].auto_select_case,
                ),
                case_type=datum['case_type'],
                requires_selection=True,
                action='update_case'
            ))
        return datums
Exemplo n.º 4
0
    def get_datum_meta_module(self, module, use_filter=False):
        datums = []
        datum_module = module.source_module if module.module_type == 'shadow' else module
        datums_meta = get_select_chain_meta(self.app, datum_module)
        for i, datum in enumerate(datums_meta):
            # get the session var for the previous datum if there is one
            parent_id = datums_meta[i - 1]['session_var'] if i >= 1 else ''
            if parent_id:
                parent_filter = EntriesHelper.get_parent_filter(
                    datum['module'].parent_select.relationship, parent_id
                )
            else:
                parent_filter = ''

            # Figure out which module will supply the details (select, confirm, etc.)
            # for this datum. Normally this is the datum's own module.
            detail_module = datum['module']

            # Shadow modules are different because datums_meta is generated based on the source module,
            # but the various details should be supplied based on the shadow's own configuration.
            if module.module_type == 'shadow':
                if datum['module'].unique_id == module.source_module_id:
                    # We're looking at the datum that corresponds to the original module,
                    # so use that module for details
                    detail_module = module
                else:
                    # Check for case list parent child selection. If both shadow and source use parent case
                    # selection, datums_meta will contain a datum for the parent case, based on the SOURCE's
                    # parent select, and when we see that datum, we need to use the SHADOW's parent select
                    # to supply the details.
                    shadow_active = hasattr(module, 'parent_select') and module.parent_select.active
                    source_active = hasattr(datum_module, 'parent_select') and datum_module.parent_select.active
                    if shadow_active and source_active:
                        if datum['module'].unique_id == datum_module.parent_select.module_id:
                            detail_module = self.app.get_module_by_unique_id(module.parent_select.module_id)

            detail_persistent = self.get_detail_persistent_attr(datum['module'], detail_module, "case_short")
            detail_inline = self.get_detail_inline_attr(datum['module'], detail_module, "case_short")

            fixture_select_filter = ''
            if datum['module'].fixture_select.active:
                datums.append(FormDatumMeta(
                    datum=SessionDatum(
                        id=id_strings.fixture_session_var(datum['module']),
                        nodeset=ItemListFixtureXpath(datum['module'].fixture_select.fixture_type).instance(),
                        value=datum['module'].fixture_select.variable_column,
                        detail_select=id_strings.fixture_detail(detail_module)
                    ),
                    case_type=None,
                    requires_selection=True,
                    action='fixture_select'
                ))
                filter_xpath_template = datum['module'].fixture_select.xpath
                fixture_value = session_var(id_strings.fixture_session_var(datum['module']))
                fixture_select_filter = "[{}]".format(
                    filter_xpath_template.replace('$fixture_value', fixture_value)
                )

            filter_xpath = EntriesHelper.get_filter_xpath(detail_module) if use_filter else ''

            datums.append(FormDatumMeta(
                datum=SessionDatum(
                    id=datum['session_var'],
                    nodeset=(EntriesHelper.get_nodeset_xpath(datum['case_type'], filter_xpath=filter_xpath)
                             + parent_filter + fixture_select_filter),
                    value="./@case_id",
                    detail_select=self.details_helper.get_detail_id_safe(detail_module, 'case_short'),
                    detail_confirm=(
                        self.details_helper.get_detail_id_safe(detail_module, 'case_long')
                        if datum['index'] == 0 and not detail_inline else None
                    ),
                    detail_persistent=detail_persistent,
                    detail_inline=detail_inline,
                    autoselect=datum['module'].auto_select_case,
                ),
                case_type=datum['case_type'],
                requires_selection=True,
                action='update_case'
            ))
        return datums