Пример #1
0
    def __init__(self, config, treeview, parent=None):
        from stdm.data import (
            foreign_key_parent_tables,
            numeric_varchar_columns,
            spatial_tables
        )

        super(EntityNodeFormatter, self).__init__(config, treeview, parent)

        self._str_ref = "social_tenure_relationship"
        self._str_title = QApplication.translate("STRFormatterBase",
                                                 "Social Tenure Relationship")

        self._str_model = DeclareMapping.instance().tableMapping(self._str_ref)

        '''
        Set STR display mapping due to a bug in the 'displayMapping'
        function
        '''
        self._str_model_disp_mapping = {}
        if not self._str_model is None:
            self._str_model_disp_mapping = self._str_model.displayMapping()

        self._str_num_char_cols = numeric_varchar_columns(self._str_ref)
        self._fk_references = foreign_key_parent_tables(self._str_ref)
        self._current_data_source_fk_ref = self._current_data_source_foreign_key_reference()
        self._numeric_char_cols = numeric_varchar_columns(config.data_source_name)
        self._spatial_data_sources = spatial_tables()
Пример #2
0
    def initialize(self):
        """
        Configure the mapper based on the user settings.
        """
        from stdm.data import numeric_varchar_columns

        #Load headers
        if not self._dbModel is None:
            headers = []

            display_cols = numeric_varchar_columns(self._ds_name)

            #Ensure only displayable values are included
            for c, dc in self._dbModel.displayMapping().iteritems():
                if c in display_cols:
                    headers.append(dc)

            self._tableModel = BaseSTDMTableModel([],headers,self)
            self._tbFKEntity.setModel(self._tableModel)
            
            #First (ID) column will always be hidden
            self._tbFKEntity.hideColumn(0)
            
            self._tbFKEntity.horizontalHeader().setResizeMode(QHeaderView.Interactive)
            self._tbFKEntity.verticalHeader().setVisible(True)

            '''
            If expression builder is enabled then disable edit button since
            mapper cannot work in both selection and editing mode.
            '''
            if self._use_expression_builder:
                self._filter_entity_btn.setVisible(True)
                self._edit_entity_btn.setVisible(False)
Пример #3
0
    def _create_str_node(self, parent_node, str_model, **kwargs):
        """
        Creates an STR Node and corresponding child nodes (from related
        entities).
        :param parent_node: Parent node
        :param str_model: STR model
        :param kwargs: Optional arguments to be passed to the STR node.
        :return: STR Node
        :rtype: STRNode
        """
        from stdm.data import (
            numeric_varchar_columns
        )

        display_mapping = self._format_display_mapping(str_model,
                                                      self._str_model_disp_mapping,
                                                      self._str_num_char_cols)

        doc_models = self._supporting_doc_models(self._str_ref, str_model)

        str_node = STRNode(display_mapping, parent=parent_node,
                           document_models=doc_models,
                           model=str_model, **kwargs)

        #Get related entities and create their corresponding nodes
        for fkr in self._fk_references:
            str_col, mod_table, mod_col = fkr[0], fkr[1], fkr[2]

            if mod_table != self._config.data_source_name:
                mod_fk_ref = mod_col, mod_table, str_col

                r_entities = self._models_from_fk_reference(str_model, str_col,
                                                            mod_table, mod_col)

                entity_display_cols = numeric_varchar_columns(mod_table)

                for r in r_entities:
                    dm = self._format_display_mapping(r,
                                                      r.__class__.displayMapping(),
                                                      entity_display_cols)

                    node = self._spatial_textual_node(mod_table)

                    entity_node = node(dm, parent=str_node,
                                             header=mod_table.replace('_',
                                                                      ' ').title(),
                                             isChild=True,
                                             model=r)

        return str_node
Пример #4
0
    def _entity_config_from_table(self, table_name):
        """
        Creates an EntityConfig object from the table name.
        :param table_name: Name of the database table.
        :type table_name: str
        :return: Entity configuration object.
        :rtype: EntityConfig
        """
        table_display_name = display_name(table_name)
        model = DeclareMapping.instance().tableMapping(table_name)

        if model is not None:
            # Entity configuration
            entity_cfg = EntityConfiguration()
            entity_cfg.Title = table_display_name
            entity_cfg.STRModel = model
            entity_cfg.data_source_name = table_name

            """
            Load filter and display columns using only those which are of
            numeric/varchar type
            """
            cols = numeric_varchar_columns(table_name)
            search_cols = self._config_table_reader.table_searchable_columns(table_name)
            disp_cols = self._config_table_reader.table_columns(table_name)

            for c in search_cols:
                # Ensure it is a numeric or text type column
                if c in cols:
                    entity_cfg.filterColumns[c] = display_name(c)

            if len(disp_cols) == 0:
                entity_cfg.displayColumns = entity_cfg.displayColumns

            else:
                for dc in disp_cols:
                    if dc in cols:
                        entity_cfg.displayColumns[dc] = display_name(dc)

            return entity_cfg

        else:
            return None