Beispiel #1
0
    def add_str_type_headers(self):
        """
        Adds headers data for QTableView columns. The
        headers comes from the selected entity.
        :param entity: The entity for which the table
        header is created for.
        :return: List of Table headers
        :rtype: List
        """
        if not self.selected_party is None:
            self.party_1 = self.selected_party
        db_model = entity_model(self.party_1, True)
        headers = []
        #Load headers
        if db_model is not None:
            entity_display_columns(self.party_1)
            # Append str type if the method
            # is used for str_type
            str_type_header = QApplication.translate('STRType',
                                                     'Social Tenure Type')
            share_header = QApplication.translate('STRType', 'Share         ')
            #First (ID) column will always be hidden
            headers.append(str_type_header)
            headers.append(share_header)

            for col in entity_display_columns(self.party_1):
                headers.append(format_name(col))
            return headers
Beispiel #2
0
    def _entity_config_from_profile(self, table_name, short_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 = format_name(short_name)

        entity = self.curr_profile.entity_by_name(table_name)
        model = entity_model(entity)

        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
            searchable_columns = entity_searchable_columns(entity)
            display_columns = entity_display_columns(entity)
            for c in searchable_columns:
                if c != 'id':
                    entity_cfg.filterColumns[c] = format_name(c)
            for c in display_columns:
                if c != 'id':
                    entity_cfg.displayColumns[c] = format_name(c)
            return entity_cfg
        else:
            return None
Beispiel #3
0
    def add_str_type_headers(self):
        """
        Adds headers data for QTableView columns. The
        headers comes from the selected entity.
        :param entity: The entity for which the table
        header is created for.
        :return: List of Table headers
        :rtype: List
        """
        if not self.selected_party is None:
            self.party_1 = self.selected_party
        db_model = entity_model(self.party_1, True)
        headers = []
        # Load headers
        if db_model is not None:

            # Append str type if the method
            # is used for str_type
            str_type_header = QApplication.translate(
                'STRType', 'Social Tenure Type'
            )
            share_header = QApplication.translate(
                'STRType', 'Share         '
            )
            # First (ID) column will always be hidden
            headers.append(str_type_header)
            headers.append(share_header)
            display_columns = entity_display_columns(self.party_1, True)
            for col in display_columns.values():
                headers.append(col)
            return headers
Beispiel #4
0
    def __init__(self, config, treeview, parent=None):


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

        prefix = self.curr_profile.prefix
        self._str_ref = str(prefix)+"_social_tenure_relationship"

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

        self._str_model, self._str_doc_model = entity_model(
            self.curr_profile.social_tenure,
            False,
            True
        )
        # Cache for entity supporting document tables.
        # [table_name]:[list of supporting document tables]
        self._entity_supporting_doc_tables = {}

        self._str_model_disp_mapping = {}
        if not self._str_model is None:
            self._str_model_disp_mapping = entity_display_columns(
                self.curr_profile.social_tenure, True
            )

        self._fk_references = [
            (
                e.entity_relation.child_column,
                e.entity_relation.parent.name,
                e.entity_relation.parent_column
            )
                for e in
                self.curr_profile.social_tenure.columns.values()
                if e.TYPE_INFO == 'FOREIGN_KEY'
        ]

        self._str_num_char_cols = entity_display_columns(
            self.curr_profile.social_tenure
        )

        self._current_data_source_fk_ref = self._current_data_source_foreign_key_reference()
        #numeric_char_cols for entities - party and sp_unit
        self._numeric_char_cols = entity_display_columns(
            self.curr_profile.entity_by_name(config.data_source_name)
        )
        self._spatial_data_sources = profile_spatial_tables(self.curr_profile).keys()
Beispiel #5
0
    def _set_ds_columns(self):
        if not self._data_source:
            self._ds_columns = []

        else:
            self._ds_columns = entity_display_columns(
                self.ds_entity
            )
Beispiel #6
0
    def _set_ds_columns(self):
        """
        Sets the data source columns.
        """
        if not self._data_source:
            self._ds_columns = []

        else:
            self._ds_columns = entity_display_columns(self.ds_entity)
Beispiel #7
0
    def _set_ds_columns(self):
        """
        Sets the data source columns.
        """
        if not self._data_source:
            self._ds_columns = []

        else:
            self._ds_columns = entity_display_columns(
                self.ds_entity
            )
Beispiel #8
0
 def reset(self):
     """
     Resets the dialog back to an empty/no filter status
     """
     for column in self._entity.columns.values():
         if column.name in entity_display_columns(self._entity):
             if column.name == 'id':
                 continue
             handler = self.attribute_mappers[
                 column.name].valueHandler()
             handler.setValue(handler.default())
Beispiel #9
0
    def _load_data_source_columns(self, entity):
        """
        Load the columns of a data source for use in the file naming.
        """
        table_cols = entity_display_columns(entity)

        attr_mapping = OrderedDict()

        for c in table_cols:
            attr_mapping[c] = format_name(c)

        self.lstDocNaming.load_mapping(attr_mapping)
Beispiel #10
0
 def textual_display_columns(self, party_entity):
     """
     Returns the only textual columns.
     :param party_entity: The entity object
     :type party_entity: Object
     :return: Textual columns
     :rtype: List
     """
     return entity_display_columns(party_entity, False, [
         'SERIAL', 'INT', 'DOUBLE', 'DATE', 'DATETIME', 'BOOL', 'LOOKUP',
         'FOREIGN_KEY', 'ADMIN_SPATIAL_UNIT', 'MULTIPLE_SELECT', 'PERCENT'
     ])
Beispiel #11
0
    def _load_data_source_columns(self, entity):
        """
        Load the columns of a data source for use in the file naming.
        """
        table_cols = entity_display_columns(entity, True)

        attr_mapping = OrderedDict()

        for c, header in table_cols.iteritems():
            attr_mapping[c] = header

        self.lstDocNaming.load_mapping(attr_mapping)
Beispiel #12
0
    def _load_data_source_columns(self, entity):
        """
        Load the columns of a data source for use in the file naming.
        """
        table_cols = entity_display_columns(entity, True)

        attr_mapping = OrderedDict()

        for c, header in table_cols.iteritems():
            attr_mapping[c] = header

        self.lstDocNaming.load_mapping(attr_mapping)
Beispiel #13
0
    def __init__(self, config, treeview, parent=None):

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

        prefix = self.curr_profile.prefix
        self._str_ref = str(prefix) + "_social_tenure_relationship"

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

        self._str_model, self._str_doc_model = entity_model(
            self.curr_profile.social_tenure, False, True)
        # Cache for entity supporting document tables.
        # [table_name]:[list of supporting document tables]
        self._entity_supporting_doc_tables = {}

        self._str_model_disp_mapping = {}
        if not self._str_model is None:
            self._str_model_disp_mapping = model_display_mapping(
                self._str_model, self.curr_profile.social_tenure)

        self._fk_references = [
            (e.entity_relation.child_column, e.entity_relation.parent.name,
             e.entity_relation.parent_column)
            for e in self.curr_profile.social_tenure.columns.values()
            if e.TYPE_INFO == 'FOREIGN_KEY'
        ]

        self._str_num_char_cols = entity_display_columns(
            self.curr_profile.social_tenure)

        self._current_data_source_fk_ref = self._current_data_source_foreign_key_reference(
        )
        #numeric_char_cols for entities - party and sp_unit

        self._numeric_char_cols = entity_display_columns(
            self.curr_profile.entity_by_name(config.data_source_name))

        self._spatial_data_sources = profile_spatial_tables(
            self.curr_profile).keys()
Beispiel #14
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
        """

        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)
                curr_entity = self.curr_profile.entity_by_name(mod_table)

                col_name_header = entity_display_columns(curr_entity, True)

                for r in r_entities:

                    dm = self._format_display_mapping(r, col_name_header,
                                                      col_name_header.keys())

                    node = self._spatial_textual_node(mod_table)

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

        return str_node
Beispiel #15
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
        """

        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)
                curr_entity = self.curr_profile.entity_by_name(mod_table)

                col_name_header = entity_display_columns(curr_entity, True)

                for r in r_entities:

                    dm = self._format_display_mapping(r,
                                                      col_name_header,
                                                      col_name_header.keys())

                    node = self._spatial_textual_node(mod_table)

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

        return str_node
Beispiel #16
0
 def current_search_data(self) -> dict:
     """
     Returns a dictionary representing the current search data
     """
     search_data = {}
     for column in self._entity.columns.values():
         if column.name in entity_display_columns(self._entity):
             if column.name == 'id':
                 continue
             handler = self.attribute_mappers[
                 column.name].valueHandler()
             value = handler.value()
             if value != handler.default() and bool(value):
                 search_data[column.name] = value
     return search_data
Beispiel #17
0
 def textual_display_columns(self, party_entity):
     """
     Returns the only textual columns.
     :param party_entity: The entity object
     :type party_entity: Object
     :return: Textual columns
     :rtype: List
     """
     return entity_display_columns(party_entity, False, [
         'SERIAL',
         'INT',
         'DOUBLE',
         'DATE',
         'DATETIME',
         'BOOL',
         'LOOKUP',
         'FOREIGN_KEY',
         'ADMIN_SPATIAL_UNIT',
         'MULTIPLE_SELECT',
         'PERCENT'
     ])
Beispiel #18
0
    def on_search(self):
        search_data = {}
        for column in self._entity.columns.values():
            if column.name in entity_display_columns(self._entity):
                if column.name == 'id':
                    continue
                handler = self.attribute_mappers[
                    column.name].valueHandler()
                value = handler.value()
                if value != handler.default() and bool(value):
                    search_data[column.name] = value
        # self.search_db(search_data)
        result = self.search_db_raw(search_data)
        self.parent._tableModel.removeRows(0, self.parent._tableModel.rowCount())
        if result is not None:
            found = QApplication.translate('AdvancedSearch', 'records found')
            new_title = '{} - {} {}'.format(self.title, result.rowcount, found)
            if result.rowcount > 3000:
                title = QApplication.translate(
                        'AdvancedSearch',
                        'Advanced Search'
                )
                message = QApplication.translate(
                    'AdvancedSearch',
                    'The search result returned {0} records, which is above the '
                    'search result limit. <br>Would you like to see the first 3000 '
                    'records?'.format("{:,}".format(result.rowcount ))
                )

                res, chk_result = simple_dialog(self, title, message)
                if res:
                    self.setWindowTitle(new_title)
                    self.parent._initializeData(result)
                else:
                    return

            else:
                self.setWindowTitle(new_title)
                self.parent._initializeData(result)
Beispiel #19
0
    def on_search(self):
        search_data = {}
        for column in self._entity.columns.values():
            if column.name in entity_display_columns(self._entity):
                if column.name == 'id':
                    continue
                handler = self.attribute_mappers[column.name].valueHandler()
                value = handler.value()
                if value != handler.default() and bool(value):
                    search_data[column.name] = value
        # self.search_db(search_data)
        result = self.search_db_raw(search_data)
        self.parent._tableModel.removeRows(0,
                                           self.parent._tableModel.rowCount())
        if result is not None:
            found = QApplication.translate('AdvancedSearch', 'records found')
            new_title = '{} - {} {}'.format(self.title, result.rowcount, found)
            if result.rowcount > 3000:
                title = QApplication.translate('AdvancedSearch',
                                               'Advanced Search')
                message = QApplication.translate(
                    'AdvancedSearch',
                    'The search result returned {0} records, which is above the '
                    'search result limit. <br>Would you like to see the first 3000 '
                    'records?'.format("{:,}".format(result.rowcount)))

                res, chk_result = simple_dialog(self, title, message)
                if res:
                    self.setWindowTitle(new_title)
                    self.parent._initializeData(result)
                else:
                    return

            else:
                self.setWindowTitle(new_title)
                self.parent._initializeData(result)
Beispiel #20
0
    def _entity_config_from_profile(self, table_name, short_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 = format_name(short_name)

        entity = self.curr_profile.entity_by_name(table_name)
        model = entity_model(entity)

        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
            for col, factory in self._get_widget_factory(entity):
                entity_cfg.LookupFormatters[col.name] = factory

            # Load filter and display columns
            # using only those which are of
            # numeric/varchar type
            searchable_columns = entity_searchable_columns(entity)
            display_columns = entity_display_columns(entity)
            for c in searchable_columns:
                if c != 'id':
                    entity_cfg.filterColumns[c] = format_name(c)
            for c in display_columns:
                if c != 'id':
                    entity_cfg.displayColumns[c] = format_name(c)
            return entity_cfg
        else:
            return None