예제 #1
0
    def form_requires_case(form, case_type=None, parent_case_type=None, update=None, preload=None):
        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)
예제 #2
0
    def form_requires_case(form, case_type=None, parent_case_type=None, update=None, preload=None):
        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)