コード例 #1
0
ファイル: entity_browser.py プロジェクト: neogeomat/stdm
    def record_feature_highlighter(self, record_ids):
        """
        Highlights a feature of a record.
        :param record_id: The id of a row
        :type record_id: Integer
        :return: None
        :rtype: NoneType
        """
        if len(record_ids) < 1:
            return

        for geom in self.geom_cols:

            geom_wkb = entity_id_to_attr(self._entity, geom.name,
                                         record_ids[0])

            if geom_wkb is not None:
                sel_lyr_name = self.sp_unit_manager. \
                    geom_col_layer_name(
                    self._entity.name, geom
                )

                self.add_spatial_unit_layer(sel_lyr_name)
                layers = QgsMapLayerRegistry.instance().\
                    mapLayersByName(
                    sel_lyr_name
                )
                if len(layers) > 0:
                    layers[0].removeSelection()
                    layers[0].select(record_ids)
                    bounding_box = layers[0].boundingBoxOfSelected()
                    iface.mapCanvas().setExtent(bounding_box)
                    iface.mapCanvas().refresh()
                    self.selection_layer = layers[0]
コード例 #2
0
ファイル: nodes.py プロジェクト: ostechman/stdm
    def delete_document_file(self, model_obj_list):
        """
        Loops through the deleted document models and delete associated files.
        :param model_obj_list: List of document model objects
        :type model_obj_list: List
        :return: None
        :rtype: NoneType
        """
        for model in model_obj_list:
            extension = model.filename[model.filename.rfind('.'):]
            # print 'Generating thumbnail'
            curr_profile = current_profile()
            doc_id = model.document_type

            doc_type_entity = curr_profile.social_tenure.\
                supporting_doc.document_type_entity
            doc_type_val = entity_id_to_attr(
                doc_type_entity, 'value', doc_id
            )
            doc_path = '{}/{}/{}/{}/{}{}'.format(
                source_document_location(),
                unicode(curr_profile.name),
                unicode(model.source_entity),
                unicode(doc_type_val),
                unicode(model.document_identifier),
                unicode(extension)
            )
            os.remove(doc_path)
コード例 #3
0
 def column_value(self, entity_dialog, column_name):
     value = entity_dialog.attribute_mapper(column_name).valueHandler().value()
     column = entity_dialog.entity.columns[column_name]
     if column.TYPE_INFO in ['LOOKUP', 'ADMIN_SPATIAL_UNIT', 'FOREIGN_KEY']:
         col_value = entity_id_to_attr(column.entity_relation.parent, 'code', value)
     else:
         col_value = value
     return col_value
コード例 #4
0
    def doc_type_value(self):
        """
        Returns the document type value.
        :return: the document type value in
        which a document is uploaded.
        :type: String
        :rtype: String
        """
        entity = self.curr_profile.entity_by_name(self._source_entity)

        doc_type_entity = entity.supporting_doc.document_type_entity
        self._doc_type = entity_id_to_attr(doc_type_entity, 'value',
                                           self._doc_type_id)
        return self._doc_type
コード例 #5
0
ファイル: entity_browser.py プロジェクト: gltn/stdm
    def record_feature_highlighter(self, record_ids):
        """
        Highlights a feature of a record.
        :param record_id: The id of a row
        :type record_id: Integer
        :return: None
        :rtype: NoneType
        """
        if len(record_ids) < 1:
            return

        for geom in self.geom_cols:

            geom_wkb = entity_id_to_attr(
                self._entity,
                geom.name,
                record_ids[0]
            )

            if geom_wkb is not None:

                sel_lyr_name = self.sp_unit_manager. \
                    geom_col_layer_name(
                    self._entity.name, geom
                )

                self.add_spatial_unit_layer(sel_lyr_name)
                layers = QgsMapLayerRegistry.instance().mapLayersByName(
                    sel_lyr_name
                )
                if len(layers) > 0:
                    layers[0].removeSelection()

                    canvas = iface.mapCanvas()

                    layers[0].blockSignals(True)
                    # Get selection and extent while disabling signals of selection
                    # especially for geometry tools.
                    layers[0].select(record_ids)
                    bounding_box = layers[0].boundingBoxOfSelected()

                    layers[0].blockSignals(False)
                    canvas.setCrsTransformEnabled(True)

                    canvas.zoomToSelected(layers[0])
                    iface.mapCanvas().setExtent(bounding_box)
                    layers[0].select(record_ids)
                    canvas.refresh()
                    self.selection_layer = layers[0]
コード例 #6
0
ファイル: sourcedocument.py プロジェクト: gltn/stdm
    def doc_type_value(self):
        """
        Returns the document type value.
        :return: the document type value in
        which a document is uploaded.
        :type: String
        :rtype: String
        """
        entity = self.curr_profile.entity_by_name(self._source_entity)

        doc_type_entity = entity.supporting_doc.document_type_entity
        self._doc_type = entity_id_to_attr(
            doc_type_entity, 'value', self._doc_type_id
        )
        return self._doc_type
コード例 #7
0
    def record_feature_highlighter(self, record_ids):
        """
        Highlights a feature of a record.
        :param record_id: The id of a row
        :type record_id: Integer
        :return: None
        :rtype: NoneType
        """
        if len(record_ids) < 1:
            return

        for geom in self.geom_cols:

            geom_wkb = entity_id_to_attr(self._entity, geom.name,
                                         record_ids[0])

            if geom_wkb is not None:

                sel_lyr_name = self.sp_unit_manager. \
                    geom_col_layer_name(
                    self._entity.name, geom
                )

                self.add_spatial_unit_layer(sel_lyr_name)
                layers = QgsMapLayerRegistry.instance().mapLayersByName(
                    sel_lyr_name)
                if len(layers) > 0:
                    layers[0].removeSelection()

                    canvas = iface.mapCanvas()

                    layers[0].blockSignals(True)
                    # Get selection and extent while disabling signals of selection
                    # especially for geometry tools.
                    layers[0].select(record_ids)
                    bounding_box = layers[0].boundingBoxOfSelected()

                    layers[0].blockSignals(False)
                    canvas.setCrsTransformEnabled(True)

                    canvas.zoomToSelected(layers[0])
                    iface.mapCanvas().setExtent(bounding_box)
                    layers[0].select(record_ids)
                    canvas.refresh()
                    self.selection_layer = layers[0]
コード例 #8
0
ファイル: relation_line_edit.py プロジェクト: PondiB/stdm
    def set_code_from_columns(self):
        """
        Creates code from a filled column values with a serial number at the end.
        .. versionadded:: 1.7.5
        """
        parent_form = self.parent().parent().parent().parent().parent().parent(
        )
        prefix_code = []

        for i, column_name in enumerate(self.column.columns):
            column = parent_form._entity.columns[column_name]

            separator = self.column.column_separators[i]
            try:
                id_value = parent_form.attribute_mapper(
                    column_name).valueHandler().value()
            except Exception:
                id_value = parent_form.entity_editor.attribute_mapper(
                    column_name).valueHandler().value()

            if column.TYPE_INFO in [
                    'LOOKUP', 'ADMIN_SPATIAL_UNIT', 'FOREIGN_KEY'
            ]:

                code = entity_id_to_attr(column.entity_relation.parent, 'code',
                                         id_value)
                prefix_code.append(u'{}{}'.format(code, separator))

            else:
                prefix_code.append(u'{}{}'.format(id_value, separator))

        self.current_item = ''
        code = u''.join(prefix_code)

        if self.column.disable_auto_increment:
            self._code = code
        else:
            # The prefix and separator should be '' for a serial.
            self._code = self.code_generator.generate(
                code, self.column.column_separators[-1],
                self.column.leading_zero)

        self.format_display()
コード例 #9
0
ファイル: sourcedocument.py プロジェクト: nyalldawson/stdm
    def insertDocumentFromFile(self, path, doc_type_id, entity, record_count=1):
        """
        Insert a new document into one of the registered containers with the
        document type id. This document is registered
        :param path: The local user path of the document
        :type path: String
        :param doc_type_id: The entity document type id
        :type doc_type_id: Integer
        :param entity: The entity in which the document is inserted into.
        :type entity: Entity class
        :param record_count: The number of records for which a
        document is uploaded. Default is 1. For instance, more
        records could be used in STR wizard in multi-party.
        :type record_count: Integer
        :return: None
        :rtype: NoneType
        """
        if len(self.containers) > 0:
            if doc_type_id in self.containers:
                container = self.containers[doc_type_id]

                #Check if the file exists
                if QFile.exists(path):

                    network_location = network_document_path()

                    if not network_location:
                        self._doc_repository_error()

                        return

                    #Check if the directory exists
                    doc_dir = QDir(network_location)

                    if not doc_dir.exists():
                        msg = QApplication.translate(
                            "sourceDocumentManager",
                            u"The root document "
                            u"repository '{0}' does "
                            u"not exist.\nPlease "
                            u"check the path settings."
                        )
                        parent = self.parent()
                        if not isinstance(parent, QWidget):
                            parent = None

                        QMessageBox.critical(
                            parent,
                            QApplication.translate(
                                "sourceDocumentManager",
                                "Document Manager"
                            ),
                            msg.format(network_location)
                        )
                        return

                    for i in range(record_count):
                        # Use the default network file manager
                        networkManager = NetworkFileManager(
                            network_location, self.parent()
                        )
                        # Add document widget
                        docWidg = DocumentWidget(
                            self.document_model,
                            networkManager,
                            parent=self.parent(),
                            view_manager=self._doc_view_manager
                        )
                        # Connect slot once the document
                        # has been successfully uploaded.
                        docWidg.fileUploadComplete.connect(
                            lambda: self.onFileUploadComplete(doc_type_id)
                        )
                        self._linkWidgetRemovedSignal(docWidg)

                        doc_type_entity = entity.supporting_doc.document_type_entity
                        doc_type_value = entity_id_to_attr(
                            doc_type_entity, 'value', doc_type_id
                        )

                        docWidg.setFile(
                            path, entity.name, doc_type_value, doc_type_id
                        )
                        container.addWidget(docWidg)
コード例 #10
0
ファイル: sourcedocument.py プロジェクト: gltn/stdm
    def insertDocumentFromFile(self, path, doc_type_id, entity, record_count=1):
        """
        Insert a new document into one of the registered containers with the
        document type id. This document is registered
        :param path: The local user path of the document
        :type path: String
        :param doc_type_id: The entity document type id
        :type doc_type_id: Integer
        :param entity: The entity in which the document is inserted into.
        :type entity: Entity class
        :param record_count: The number of records for which a
        document is uploaded. Default is 1. For instance, more
        records could be used in STR wizard in multi-party.
        :type record_count: Integer
        :return: None
        :rtype: NoneType
        """
        if len(self.containers) > 0:
            if doc_type_id in self.containers:
                container = self.containers[doc_type_id]

                #Check if the file exists
                if QFile.exists(path):

                    network_location = network_document_path()

                    if not network_location:
                        self._doc_repository_error()

                        return

                    #Check if the directory exists
                    doc_dir = QDir(network_location)

                    if not doc_dir.exists():
                        msg = QApplication.translate(
                            "sourceDocumentManager",
                            u"The root document "
                            u"repository '{0}' does "
                            u"not exist.\nPlease "
                            u"check the path settings."
                        )
                        parent = self.parent()
                        if not isinstance(parent, QWidget):
                            parent = None

                        QMessageBox.critical(
                            parent,
                            QApplication.translate(
                                "sourceDocumentManager",
                                "Document Manager"
                            ),
                            msg.format(network_location)
                        )
                        return

                    for i in range(record_count):
                        # Use the default network file manager
                        networkManager = NetworkFileManager(
                            network_location, self.parent()
                        )
                        # Add document widget
                        docWidg = DocumentWidget(
                            self.document_model,
                            networkManager,
                            parent=self.parent(),
                            view_manager=self._doc_view_manager
                        )
                        # Connect slot once the document
                        # has been successfully uploaded.
                        docWidg.fileUploadComplete.connect(
                            lambda: self.onFileUploadComplete(doc_type_id)
                        )
                        self._linkWidgetRemovedSignal(docWidg)

                        doc_type_entity = entity.supporting_doc.document_type_entity
                        doc_type_value = entity_id_to_attr(
                            doc_type_entity, 'value', doc_type_id
                        )

                        docWidg.setFile(
                            path, entity.name, doc_type_value, doc_type_id
                        )
                        container.addWidget(docWidg)