Example #1
0
    def _make_session_endpoint(self, module, form=None):
        if form is not None:
            endpoint_id = form.session_endpoint_id
        else:
            endpoint_id = module.session_endpoint_id

        stack = Stack()
        children = self.get_frame_children(module, form)
        argument_ids = self.get_argument_ids(children, form)

        # Add a claim request for each endpoint argument.
        # This assumes that all arguments are case ids.
        non_computed_argument_ids = [
            child.id for child in children
            if isinstance(child, WorkflowDatumMeta) and child.requires_selection
        ]
        for arg_id in non_computed_argument_ids:
            self._add_claim_frame(stack, arg_id, endpoint_id)

        # Add a frame to navigate to the endpoint
        frame = PushFrame()
        stack.add_frame(frame)
        for child in children:
            if isinstance(child, CommandId):
                frame.add_command(child.to_command())
            elif child.id in argument_ids:
                self._add_datum_for_arg(frame, child.id)

        return SessionEndpoint(
            id=endpoint_id,
            arguments=[Argument(id=i) for i in argument_ids],
            stack=stack,
        )
Example #2
0
    def _get_reg_form_action(self, module):
        """
        Returns registration form action
        """
        form = self.app.get_form(module.case_list_form.form_id)

        if self.app.enable_localized_menu_media:
            case_list_form = module.case_list_form
            action = LocalizedAction(
                menu_locale_id=id_strings.case_list_form_locale(module),
                media_image=case_list_form.uses_image(
                    build_profile_id=self.build_profile_id),
                media_audio=case_list_form.uses_audio(
                    build_profile_id=self.build_profile_id),
                image_locale_id=id_strings.case_list_form_icon_locale(module),
                audio_locale_id=id_strings.case_list_form_audio_locale(module),
                stack=Stack(),
                for_action_menu=True,
            )
        else:
            action = Action(display=Display(
                text=Text(locale_id=id_strings.case_list_form_locale(module)),
                media_image=module.case_list_form.default_media_image,
                media_audio=module.case_list_form.default_media_audio,
            ),
                            stack=Stack())

        frame = PushFrame()
        frame.add_command(XPath.string(id_strings.form_command(form)))

        target_form_dm = self.entries_helper.get_datums_meta_for_form_generic(
            form)
        source_form_dm = []
        if len(module.forms):
            source_form_dm = self.entries_helper.get_datums_meta_for_form_generic(
                module.get_form(0))
        for target_meta in target_form_dm:
            if target_meta.requires_selection:
                # This is true for registration forms where the case being created is a subcase
                try:
                    [source_dm] = [
                        source_meta for source_meta in source_form_dm
                        if source_meta.case_type == target_meta.case_type
                    ]
                except ValueError:
                    pass
                else:
                    frame.add_datum(
                        StackDatum(id=target_meta.datum.id,
                                   value=session_var(source_dm.datum.id)))
            else:
                s_datum = target_meta.datum
                frame.add_datum(
                    StackDatum(id=s_datum.id, value=s_datum.function))

        frame.add_datum(
            StackDatum(id=RETURN_TO,
                       value=XPath.string(id_strings.menu_id(module))))
        action.stack.add_frame(frame)
        return action
Example #3
0
 def _build_stack(self):
     stack = Stack()
     frame = PushFrame()
     frame.add_rewind(
         QuerySessionXPath(
             self.module.search_config.case_session_var).instance())
     stack.add_frame(frame)
     return stack
Example #4
0
 def _add_case_search_action_to_detail(detail, module):
     detail.action = Action(
         display=Display(
             text=Text(locale_id=id_strings.case_search_locale(module))
         ),
         stack=Stack()
     )
     frame = PushFrame()
     frame.add_command(XPath.string(id_strings.search_command(module)))
     detail.action.stack.add_frame(frame)
Example #5
0
 def _get_case_search_action(module):
     action = Action(
         display=Display(
             text=Text(locale_id=id_strings.case_search_locale(module))
         ),
         stack=Stack()
     )
     frame = PushFrame()
     frame.add_command(XPath.string(id_strings.search_command(module)))
     action.stack.add_frame(frame)
     return action
Example #6
0
    def _add_action_to_detail(self, detail, module):
        # add form action to detail
        form = self.app.get_form(module.case_list_form.form_id)

        if self.app.enable_localized_menu_media:
            case_list_form = module.case_list_form
            detail.action = LocalizedAction(
                menu_locale_id=id_strings.case_list_form_locale(module),
                media_image=bool(len(case_list_form.all_image_paths())),
                media_audio=bool(len(case_list_form.all_audio_paths())),
                image_locale_id=id_strings.case_list_form_icon_locale(module),
                audio_locale_id=id_strings.case_list_form_audio_locale(module),
                stack=Stack(),
                for_action_menu=True,
            )
        else:
            detail.action = Action(
                display=Display(
                    text=Text(locale_id=id_strings.case_list_form_locale(module)),
                    media_image=module.case_list_form.default_media_image,
                    media_audio=module.case_list_form.default_media_audio,
                ),
                stack=Stack()
            )

        frame = PushFrame()
        frame.add_command(XPath.string(id_strings.form_command(form)))

        target_form_dm = self.entries_helper.get_datums_meta_for_form_generic(form)
        source_form_dm = self.entries_helper.get_datums_meta_for_form_generic(module.get_form(0))
        for target_meta in target_form_dm:
            if target_meta.requires_selection:
                # This is true for registration forms where the case being created is a subcase
                try:
                    [source_dm] = [
                        source_meta for source_meta in source_form_dm
                        if source_meta.case_type == target_meta.case_type
                    ]
                except ValueError:
                    message = _(
                        "The '{form}' form selected as the case list registration form "
                        "for the '{module}' module requires a '{case_type}' case. "
                        "The '{module}' must load a case of this type.").format(
                        form=form.default_name(),
                        module=module.default_name(),
                        case_type=target_meta.case_type
                    )
                    raise SuiteValidationError(message)
                else:
                    frame.add_datum(StackDatum(
                        id=target_meta.datum.id,
                        value=session_var(source_dm.datum.id))
                    )
            else:
                s_datum = target_meta.datum
                frame.add_datum(StackDatum(id=s_datum.id, value=s_datum.function))

        frame.add_datum(StackDatum(id=RETURN_TO, value=XPath.string(id_strings.menu_id(module))))
        detail.action.stack.add_frame(frame)
Example #7
0
 def _get_case_search_action(module):
     action = Action(
         display=Display(
             text=Text(locale_id=id_strings.case_search_locale(module))
         ),
         stack=Stack()
     )
     frame = PushFrame()
     frame.add_mark()
     frame.add_command(XPath.string(id_strings.search_command(module)))
     action.stack.add_frame(frame)
     return action
Example #8
0
    def _get_reg_form_action(self, module):
        """
        Returns registration form action
        """
        form = self.app.get_form(module.case_list_form.form_id)

        if self.app.enable_localized_menu_media:
            case_list_form = module.case_list_form
            action = LocalizedAction(
                menu_locale_id=id_strings.case_list_form_locale(module),
                media_image=bool(len(case_list_form.all_image_paths())),
                media_audio=bool(len(case_list_form.all_audio_paths())),
                image_locale_id=id_strings.case_list_form_icon_locale(module),
                audio_locale_id=id_strings.case_list_form_audio_locale(module),
                stack=Stack(),
                for_action_menu=True,
            )
        else:
            action = Action(
                display=Display(
                    text=Text(locale_id=id_strings.case_list_form_locale(module)),
                    media_image=module.case_list_form.default_media_image,
                    media_audio=module.case_list_form.default_media_audio,
                ),
                stack=Stack()
            )

        frame = PushFrame()
        frame.add_command(XPath.string(id_strings.form_command(form)))

        target_form_dm = self.entries_helper.get_datums_meta_for_form_generic(form)
        source_form_dm = []
        if len(module.forms):
            source_form_dm = self.entries_helper.get_datums_meta_for_form_generic(module.get_form(0))
        for target_meta in target_form_dm:
            if target_meta.requires_selection:
                # This is true for registration forms where the case being created is a subcase
                try:
                    [source_dm] = [
                        source_meta for source_meta in source_form_dm
                        if source_meta.case_type == target_meta.case_type
                    ]
                except ValueError:
                    pass
                else:
                    frame.add_datum(StackDatum(
                        id=target_meta.datum.id,
                        value=session_var(source_dm.datum.id))
                    )
            else:
                s_datum = target_meta.datum
                frame.add_datum(StackDatum(id=s_datum.id, value=s_datum.function))

        frame.add_datum(StackDatum(id=RETURN_TO, value=XPath.string(id_strings.menu_id(module))))
        action.stack.add_frame(frame)
        return action
Example #9
0
 def _get_case_search_action(module):
     relevant_kwarg = {}
     if module.search_config.search_button_display_condition:
         relevant_kwarg = dict(
             relevant=XPath(module.search_config.search_button_display_condition),
         )
     action = Action(
         display=Display(
             text=Text(locale_id=id_strings.case_search_locale(module))
         ),
         stack=Stack(),
         **relevant_kwarg
     )
     frame = PushFrame()
     frame.add_mark()
     frame.add_command(XPath.string(id_strings.search_command(module)))
     action.stack.add_frame(frame)
     return action
Example #10
0
 def build_stack(self):
     stack = Stack()
     rewind_if = None
     if module_uses_smart_links(self.module):
         user_domain_xpath = session_var(COMMCARE_PROJECT, path="user/data")
         # For case in same domain, do a regular case claim rewind
         rewind_if = self._get_case_domain_xpath().eq(user_domain_xpath)
         # For case in another domain, jump to that other domain
         frame = PushFrame(if_clause=XPath.not_(rewind_if))
         frame.add_datum(
             StackJump(url=Text(xpath=TextXPath(
                 function=self.get_smart_link_function(),
                 variables=self.get_smart_link_variables(),
             ), ), ))
         stack.add_frame(frame)
     frame = PushFrame(if_clause=rewind_if)
     frame.add_rewind(QuerySessionXPath(self.case_session_var).instance())
     stack.add_frame(frame)
     return stack
Example #11
0
 def _get_case_search_action(module):
     relevant_kwarg = {}
     if module.search_config.search_button_display_condition:
         relevant_kwarg = dict(relevant=XPath(
             module.search_config.search_button_display_condition), )
     action = Action(display=Display(text=Text(
         locale_id=id_strings.case_search_locale(module))),
                     stack=Stack(),
                     **relevant_kwarg)
     frame = PushFrame()
     frame.add_mark()
     frame.add_command(XPath.string(id_strings.search_command(module)))
     action.stack.add_frame(frame)
     return action
Example #12
0
 def _get_case_search_action(module, in_search=False):
     action_kwargs = DetailContributor._get_action_kwargs(module, in_search)
     action = Action(
         display=Display(text=Text(locale_id=(
             id_strings.case_search_again_locale(module)
             if in_search else id_strings.case_search_locale(module)))),
         stack=Stack(),
         auto_launch=DetailContributor._get_auto_launch_expression(
             module, in_search),
         redo_last=in_search,
         **action_kwargs)
     frame = PushFrame()
     frame.add_mark()
     frame.add_command(XPath.string(id_strings.search_command(module)))
     action.stack.add_frame(frame)
     return action
Example #13
0
    def _make_session_endpoint(self, id_string, module, endpoint_id):
        stack = Stack()
        frame = PushFrame()
        stack.add_frame(frame)
        frame.add_command(XPath.string(id_string))
        arguments = []
        helper = WorkflowHelper(self.suite, self.app, self.modules)
        for child in helper.get_frame_children(id_string, module):
            if isinstance(child, WorkflowDatumMeta):
                arguments.append(Argument(id=child.id))
                frame.add_datum(StackDatum(id=child.id, value=f"${child.id}"))

        return SessionEndpoint(
            id=endpoint_id,
            arguments=arguments,
            stack=stack,
        )
Example #14
0
 def _get_case_search_action(module):
     relevant_kwarg = {}
     if module.search_config.search_button_display_condition:
         relevant_kwarg = dict(relevant=XPath(
             module.search_config.search_button_display_condition), )
     allow_auto_launch = toggles.CASE_CLAIM_AUTOLAUNCH.enabled(
         module.get_app().domain)
     action = Action(display=Display(text=Text(
         locale_id=id_strings.case_search_locale(module))),
                     stack=Stack(),
                     auto_launch=allow_auto_launch
                     and module.search_config.auto_launch,
                     **relevant_kwarg)
     frame = PushFrame()
     frame.add_mark()
     frame.add_command(XPath.string(id_strings.search_command(module)))
     action.stack.add_frame(frame)
     return action
Example #15
0
 def _get_case_search_action(module, in_search=False):
     relevant_kwarg = {}
     if not in_search and module.search_config.search_button_display_condition:
         relevant_kwarg = dict(relevant=XPath(
             module.search_config.search_button_display_condition), )
     allow_auto_launch = toggles.USH_CASE_CLAIM_UPDATES.enabled(
         module.get_app().domain) and not in_search
     action = Action(display=Display(text=Text(
         locale_id=(id_strings.case_search_again_locale(module) if in_search
                    else id_strings.case_search_locale(module)))),
                     stack=Stack(),
                     auto_launch=allow_auto_launch
                     and module.search_config.auto_launch,
                     redo_last=in_search,
                     **relevant_kwarg)
     frame = PushFrame()
     frame.add_mark()
     frame.add_command(XPath.string(id_strings.search_command(module)))
     action.stack.add_frame(frame)
     return action
Example #16
0
    def _get_case_search_action(self, module, in_search=False):
        action_kwargs = DetailContributor._get_action_kwargs(module, in_search)
        if in_search:
            search_label = module.search_config.search_again_label
        else:
            search_label = module.search_config.search_label

        if self.app.enable_localized_menu_media:
            action = LocalizedAction(
                menu_locale_id=(id_strings.case_search_again_locale(module)
                                if in_search else
                                id_strings.case_search_locale(module)),
                media_image=search_label.uses_image(
                    build_profile_id=self.build_profile_id),
                media_audio=search_label.uses_audio(
                    build_profile_id=self.build_profile_id),
                image_locale_id=(
                    id_strings.case_search_again_icon_locale(module) if
                    in_search else id_strings.case_search_icon_locale(module)),
                audio_locale_id=(
                    id_strings.case_search_again_audio_locale(module)
                    if in_search else
                    id_strings.case_search_audio_locale(module)),
                stack=Stack(),
                for_action_menu=True,
                **action_kwargs,
            )
        else:
            action = Action(display=Display(
                text=Text(locale_id=(
                    id_strings.case_search_again_locale(module)
                    if in_search else id_strings.case_search_locale(module))),
                media_image=search_label.default_media_image,
                media_audio=search_label.default_media_audio),
                            stack=Stack(),
                            **action_kwargs)
        frame = PushFrame()
        frame.add_mark()
        frame.add_command(XPath.string(id_strings.search_command(module)))
        action.stack.add_frame(frame)
        return action
Example #17
0
 def _build_stack(self):
     stack = Stack()
     frame = PushFrame()
     frame.add_rewind(QuerySessionXPath('case_id').instance())
     stack.add_frame(frame)
     return stack
Example #18
0
    def get_module_contributions(self, module):
        if module_offers_search(module):
            domain = self.app.domain

            details_helper = DetailsHelper(self.app)

            remote_request = RemoteRequest(
                post=RemoteRequestPost(
                    url=absolute_reverse('claim_case', args=[domain]),
                    relevant=module.search_config.relevant,
                    data=[
                        QueryData(
                            key='case_id',
                            ref=QuerySessionXPath('case_id').instance(),
                            # e.g. instance('querysession')/session/data/case_id
                        ),
                    ]),
                command=Command(
                    id=id_strings.search_command(module),
                    display=Display(text=Text(
                        locale_id=id_strings.case_search_locale(module)), ),
                ),
                instances=[
                    Instance(id=SESSION_INSTANCE, src='jr://instance/session'),
                    Instance(id='casedb', src='jr://instance/casedb'),
                ],
                session=RemoteRequestSession(
                    queries=[
                        RemoteRequestQuery(
                            url=absolute_reverse('remote_search',
                                                 args=[domain]),
                            storage_instance=RESULTS_INSTANCE,
                            data=([
                                QueryData(key='case_type',
                                          ref="'{}'".format(module.case_type)),
                                QueryData(
                                    key='include_closed',
                                    ref="'{}'".format(
                                        module.search_config.include_closed))
                            ] + [
                                QueryData(key="'{}'".format(c.property),
                                          ref="'{}'".format(c.defaultValue))
                                for c in
                                module.search_config.default_properties
                            ]),
                            prompts=[
                                QueryPrompt(
                                    key=p.name,
                                    display=Display(
                                        text=Text(locale_id=id_strings.
                                                  search_property_locale(
                                                      module, p.name)), ),
                                ) for p in module.search_config.properties
                            ])
                    ],
                    data=[
                        SessionDatum(
                            id='case_id',
                            nodeset=(CaseTypeXpath(module.case_type).case(
                                instance_name=RESULTS_INSTANCE)),
                            value='./@case_id',
                            detail_select=details_helper.get_detail_id_safe(
                                module, 'case_short'),
                            detail_confirm=details_helper.get_detail_id_safe(
                                module, 'case_long'),
                        )
                    ],
                ),
                stack=Stack(),
            )

            frame = PushFrame()
            frame.add_rewind(QuerySessionXPath('case_id').instance())
            remote_request.stack.add_frame(frame)

            return [remote_request]
        return []
Example #19
0
    def get_module_contributions(self, module):
        if module_offers_search(module):
            domain = self.app.domain

            details_helper = DetailsHelper(self.app)

            sync_request = SyncRequest(
                post=SyncRequestPost(
                    url=absolute_reverse('claim_case', args=[domain]),
                    # Check whether the case to be claimed already exists in casedb:
                    # count(
                    #   instance('casedb')/casedb/case[@case_id=instance('querysession')/session/data/case_id]
                    # ) = 0
                    relevant=XPath.count(
                        CaseIDXPath(QuerySessionXPath('case_id').instance()).case()
                    ) + ' = 0',
                    data=[
                        QueryData(
                            key='case_id',
                            ref=QuerySessionXPath('case_id').instance(),
                            # e.g. instance('querysession')/session/data/case_id
                        ),
                    ]
                ),

                command=Command(
                    id=id_strings.search_command(module),
                    display=Display(
                        text=Text(locale_id=id_strings.case_search_locale(module)),
                    ),
                ),

                instances=[Instance(
                    id=SESSION_INSTANCE,
                    src='jr://instance/session'
                )],

                session=SyncRequestSession(
                    queries=[
                        SyncRequestQuery(
                            url=absolute_reverse('sync_search', args=[domain]),
                            storage_instance=RESULTS_INSTANCE,
                            data=[
                                QueryData(
                                    key='case_type',
                                    ref="'{}'".format(module.case_type)
                                ),
                            ],
                            prompts=[
                                QueryPrompt(
                                    key=p.name,
                                    display=Display(
                                        text=Text(locale_id=id_strings.search_property_locale(module, p.name)),
                                    ),
                                ) for p in module.search_config.properties
                            ]
                        )
                    ],
                    data=[SessionDatum(
                        id='case_id',
                        nodeset=(CaseTypeXpath(module.case_type)
                                 .case(instance_name=RESULTS_INSTANCE)
                                 .select(u'@status', u'open', quote=True)),
                        value='./@case_id',
                        detail_select=details_helper.get_detail_id_safe(module, 'case_short'),
                        detail_confirm=details_helper.get_detail_id_safe(module, 'case_long'),
                    )],
                ),

                stack=Stack(),
            )

            frame = PushFrame()
            # Open first form in module
            frame.add_command(XPath.string(id_strings.menu_id(module)))
            frame.add_datum(StackDatum(id=CALCULATED_DATA, value=XPath.string(MARK_AS_CLAIMED)))
            sync_request.stack.add_frame(frame)

            return [sync_request]
        return []
Example #20
0
 def _build_stack(self):
     stack = Stack()
     frame = PushFrame()
     frame.add_rewind(QuerySessionXPath('case_id').instance())
     stack.add_frame(frame)
     return stack
Example #21
0
 def _add_claim_frame(self, stack, arg_id, endpoint_id):
     frame = PushFrame()
     stack.add_frame(frame)
     self._add_datum_for_arg(frame, arg_id)
     frame.add_command(f"'claim_command.{endpoint_id}.{arg_id}'")