Exemplo n.º 1
0
        def generate_additional_columns(requires_case):
            ret = []
            case_name_col = CustomColumn(slug='case_name',
                                         index=FORM_CASE_ID_PATH,
                                         display='info.case_name',
                                         transform=CASENAME_TRANSFORM,
                                         show=True,
                                         selected=True)
            if not requires_case:
                case_name_col.show, case_name_col.selected, case_name_col.tag = False, False, 'deleted'
            matches = filter(case_name_col.match, column_conf)
            if matches:
                # hack/annoying - also might have to re-add the case id column which can get
                # overwritten by case name if only that is set.
                case_id_cols = filter(
                    lambda col: col['index'] == FORM_CASE_ID_PATH, column_conf)
                if len(case_id_cols) <= 1:
                    ret.append(
                        ExportColumn(
                            index=FORM_CASE_ID_PATH,
                            display='info.case_id',
                            show=True,
                        ).to_config_format(selected=False))

                for match in matches:
                    case_name_col.format_for_javascript(match)

            elif filter(lambda col: col["index"] == case_name_col.index,
                        column_conf):
                ret.append(case_name_col.default_column())
            return ret
Exemplo n.º 2
0
    def update_table_conf(self, table_conf):
        column_conf = table_conf[0].get("column_configuration", [])
        current_properties = set(self.custom_export.case_properties)
        remaining_properties = current_properties.copy()

        def is_special_type(p):
            return any([
                p in self.meta_properties, p in self.server_properties, p
                in self.row_properties
            ])

        for col in column_conf:
            prop = col["index"]
            display = col.get('display') or prop
            if prop in remaining_properties:
                remaining_properties.discard(prop)
                col["show"] = True
            if not is_special_type(prop) and prop not in current_properties:
                col["tag"] = "deleted"
                col["show"] = False
            if prop in self.default_properties + list(current_properties) or \
                            display in self.default_transformed_properties:
                col["show"] = True
                if self.creating_new_export:
                    col["selected"] = True

        column_conf.extend([
            ExportColumn(
                index=prop,
                display='',
                show=True,
            ).to_config_format(selected=self.creating_new_export)
            for prop in filter(lambda prop: not prop.startswith("parent/"),
                               remaining_properties)
        ])

        table_conf[0]["column_configuration"] = column_conf

        for table in table_conf:
            for col in table.get("column_configuration", []):
                if col["index"] in self.properties_to_show:
                    col["show"] = True

        # Show most of the Case History rows by default
        dont_show_cols = {"sync_log_id"}
        for table in table_conf:
            if table.get("index", "") == "#.actions.#":
                for col in table.get("column_configuration", []):
                    index = col.get("index", "")
                    if index not in dont_show_cols:
                        col["show"] = True
                    else:
                        dont_show_cols.discard(index)
                break

        return table_conf
Exemplo n.º 3
0
        def get_remainder_column(question):
            col = ExportColumn(
                index=question,
                display='',
                show=True,
            ).to_config_format(selected=self.creating_new_export)

            update_multi_select_column(question, col)

            return col
Exemplo n.º 4
0
        def generate_additional_columns(requires_case):
            ret = []
            # the default of the case_name_col MUST have selected = false, because
            # there is no way to store selected = false in the current export schema
            # as it only stores selected columns, not the selected states for all columns
            case_name_col = CustomColumn(slug='case_name',
                                         index=FORM_CASE_ID_PATH,
                                         display='info.case_name',
                                         transform=CASENAME_TRANSFORM,
                                         show=True,
                                         selected=False)
            if not requires_case:
                case_name_col.show, case_name_col.selected, case_name_col.tag = False, False, 'deleted'
            matches = list(filter(case_name_col.match, column_conf))
            if matches:
                # hack/annoying - also might have to re-add the case id column which can get
                # overwritten by case name if only that is set.
                case_id_cols = [
                    col for col in column_conf
                    if col['index'] == FORM_CASE_ID_PATH
                ]
                if len(case_id_cols) <= 1:
                    ret.append(
                        ExportColumn(
                            index=FORM_CASE_ID_PATH,
                            display='info.case_id',
                            show=True,
                        ).to_config_format(selected=False))

                for match in matches:
                    case_name_col.format_for_javascript(match)

            elif [
                    col for col in column_conf
                    if col["index"] == case_name_col.index
            ]:
                ret.append(case_name_col.default_column())
            return ret
Exemplo n.º 5
0
    def update_table_conf_with_questions(self, table_conf):
        column_conf = table_conf[0].get("column_configuration", [])

        current_questions = set(self.custom_export.question_order)
        remaining_questions = current_questions.copy()

        def is_special_type(q):
            return any([q.startswith('form.#'), q.startswith('form.@'), q.startswith('form.case.'),
                        q.startswith('form.meta.'), q.startswith('form.subcase_')])

        def generate_additional_columns(requires_case):
            ret = []
            case_name_col = CustomColumn(slug='case_name', index=FORM_CASE_ID_PATH, display='info.case_name',
                                         transform=CASENAME_TRANSFORM, show=True, selected=True)
            if not requires_case:
                case_name_col.show, case_name_col.selected, case_name_col.tag = False, False, 'deleted'
            matches = filter(case_name_col.match, column_conf)
            if matches:
                # hack/annoying - also might have to re-add the case id column which can get
                # overwritten by case name if only that is set.
                case_id_cols = filter(lambda col: col['index'] == FORM_CASE_ID_PATH, column_conf)
                if len(case_id_cols) <= 1:
                    ret.append(ExportColumn(
                        index=FORM_CASE_ID_PATH,
                        display='info.case_id',
                        show=True,
                    ).to_config_format(selected=False))

                for match in matches:
                    case_name_col.format_for_javascript(match)

            elif filter(lambda col: col["index"] == case_name_col.index, column_conf):
                ret.append(case_name_col.default_column())
            return ret

        for col in column_conf:
            question = col["index"]
            if question in remaining_questions:
                remaining_questions.discard(question)
                col["show"] = True
            if question.startswith("form.") and not is_special_type(question) and question not in current_questions:
                col["tag"] = "deleted"
                col["show"] = False
            if question in self.questions_to_show:
                col["show"] = True
            if self.creating_new_export and (question in self.default_questions or question in current_questions):
                col["selected"] = True

        requires_case = self.custom_export.uses_cases()

        case_cols = filter(lambda col: col["index"] == FORM_CASE_ID_PATH, column_conf)
        if not requires_case:
            for col in case_cols:
                if col['index'] == FORM_CASE_ID_PATH:
                    col['tag'], col['show'], col['selected'] = 'deleted', False, False
        elif not case_cols:
            column_conf.append({
                'index': FORM_CASE_ID_PATH,
                'show': True,
                'is_sensitive': False,
                'selected': True,
                'transform': None,
                'tag': None,
                'display': ''
            })

        column_conf.extend(generate_additional_columns(requires_case))
        column_conf.extend([
            ExportColumn(
                index=q,
                display='',
                show=True,
            ).to_config_format(selected=self.creating_new_export)
            for q in remaining_questions
        ])

        # show all questions in repeat groups by default
        for conf in table_conf:
            if conf["index"].startswith('#.form.'):
                for col in conf.get("column_configuration", []):
                    col["show"] = True


        table_conf[0]["column_configuration"] = column_conf
        return table_conf