def save_to_db(self): """ Format object attribute data from entity and save them into database :return: """ try: if self.parents_ids is not None and self.entity.short_name == 'social_tenure_relationship': str_tables = current_profile().social_tenure prefix = current_profile().prefix + '_' full_party_ref_column = str_tables.parties[0].name party_ref_column = str_tables.parties[0].name.lower().replace( prefix, '') + '_id' setattr(self.model, party_ref_column, self.parents_ids.get(full_party_ref_column)[0]) full_spatial_ref_column = str_tables.spatial_units[0].name spatial_ref_column = str_tables.spatial_units[0].name.lower( ).replace(prefix, '') + '_id' setattr(self.model, spatial_ref_column, self.parents_ids.get(full_spatial_ref_column)[0]) except: pass for k, v in self.attributes.iteritems(): if hasattr(self.model, k): col_type = self.column_info().get(k) col_prop = self.entity.columns[k] var = self.attribute_formatter(col_type, col_prop, v) setattr(self.model, k, var) if self.entity_has_supporting_docs(): self.model.documents = self._doc_manager.model_objects() self.model.save() return self.model.id
def __init__(self, parent, notification_bar): self.notification = notification_bar self.social_tenure = current_profile().social_tenure self.parties = current_profile().social_tenure.parties self.parent = parent self.entity_editors = OrderedDict()
def __init__(self, parent, notification_bar): self.notification = notification_bar self.social_tenure = current_profile().social_tenure self.parties = current_profile().social_tenure.parties self.parent = parent self.entity_editors = OrderedDict()
def save_to_db(self): """ Format object attribute data from entity and save them into database :return: """ self.column_info() attributes = self.attributes try: if self.entity.short_name == 'social_tenure_relationship': #try: prefix = current_profile().prefix + '_' if self.attributes.has_key('party'): full_party_ref_column = self.attributes.get('party') party_ref_column = full_party_ref_column + '_id' self.attributes.pop('party') else: full_party_ref_column = current_profile( ).social_tenure.parties[0].name party_ref_column = full_party_ref_column.replace( prefix, '') + '_id' setattr(self.model, party_ref_column, self.parents_ids.get(full_party_ref_column)[0]) if self.attributes.has_key('spatial_unit'): full_spatial_ref_column = self.attributes.get( 'spatial_unit') spatial_ref_column = full_spatial_ref_column + '_id' self.attributes.pop('spatial_unit') else: full_spatial_ref_column = current_profile( ).social_tenure.spatial_units[0].name spatial_ref_column = full_spatial_ref_column.replace( prefix, '') + '_id' setattr(self.model, spatial_ref_column, self.parents_ids.get(full_spatial_ref_column)[0]) attributes = self.attributes['social_tenure'] except: pass for k, v in attributes.iteritems(): if hasattr(self.model, k): col_type = self.entity_mapping.get(k) col_prop = self.entity.columns[k] var = self.attribute_formatter(col_type, col_prop, v) setattr(self.model, k, var) if self.entity_has_supporting_docs(): self.model.documents = self._doc_manager.model_objects() self.model.save() return self.model.id
def object_from_entity_name(self, entity): """ :return: """ if entity == 'social_tenure': return current_profile().social_tenure else: user_entity = current_profile().entity_by_name(entity) return user_entity
def object_from_entity_name(self, entity): """ :return: """ if entity == 'social_tenure': return current_profile().social_tenure else: user_entity = current_profile().entity_by_name(entity) return user_entity
def instance_entities(self): """ Enumerate the entities that are in the current profile and also that are captured in the form so that we are only importing relevant entities to database :return: entities """ current_entities = [] entity_collections = [] instance_collections = self.instance_collection() if len(instance_collections) > 0: for entity_name in self.profile_entities_names(current_profile()): if current_profile().entity_by_name(entity_name) is not None: current_entities.append(entity_name) return current_entities
def instance_entities(self): """ Enumerate the entities that are in the current profile and also that are captured in the form so that we are only importing relevant entities to database :return: entities """ current_entities = [] entity_collections = [] instance_collections = self.instance_collection() if len(instance_collections) > 0: for entity_name in self.profile_entities_names(current_profile()): if current_profile().entity_by_name(entity_name) is not None: current_entities.append(entity_name) return current_entities
def has_foreign_keys_parent(self, select_entities): """ Ensure we check that the table is not parent else import parent table first Revised in version 1.7. It explicitly assumes str is captured. before it was optional. :return: """ has_relations = False str_tables = current_profile().social_tenure party_tbls = str_tables.parties sp_tbls = str_tables.spatial_units self.relations = OrderedDict() if len(self.instance_list) > 0: if self.uuid_extractor.has_str_captured_in_instance( self.instance_list[0]): for party_tbl in party_tbls: self.relations[party_tbl.name] = [ 'social_tenure_relationship', party_tbl.short_name.lower() + '_id' ] for sp_tbl in sp_tbls: self.relations[sp_tbl.name] = [ 'social_tenure_relationship', sp_tbl.short_name.lower() + '_id' ] # print self.relations for table in select_entities: table_object = current_profile().entity_by_name(table) cols = table_object.columns.values() for col in cols: if col.TYPE_INFO == 'FOREIGN_KEY': parent_object = table_object.columns[col.name] if parent_object.parent: if parent_object.parent.name in self.relations: self.relations[parent_object.parent.name].append( [table, col.name]) else: self.relations[parent_object.parent.name] = [ table, col.name ] #self.relations[parent_object.parent.name].append([table, col.name]) has_relations = True else: continue return has_relations
def __init__(self, parent=None, iface=None): QTabWidget.__init__(self, parent) self.setupUi(self) self._notif_bar = None self._ol_loaded = False self._overlay_layer = None self.sel_highlight = None self.memory_layer = None self._db_session = STDMDb.instance().session self.curr_profile = current_profile() self.spatial_unit = self.curr_profile.social_tenure.spatial_unit self.set_iface(iface) #Web config self._web_spatial_loader = WebSpatialLoader(self.spatial_web_view, self) #Connect signals self._web_spatial_loader.loadError.connect( self.on_spatial_browser_error) self._web_spatial_loader.loadProgress.connect( self.on_spatial_browser_loading) self._web_spatial_loader.loadFinished.connect( self.on_spatial_browser_finished) self._web_spatial_loader.zoomChanged.connect( self.on_map_zoom_level_changed) self.rbGMaps.toggled.connect(self.on_load_GMaps) self.rbOSM.toggled.connect(self.on_load_OSM) self.zoomSlider.sliderReleased.connect(self.on_zoom_changed) self.btnResetMap.clicked.connect(self.on_reset_web_map) self.btnSync.clicked.connect(self.on_sync_extents) QgsMapLayerRegistry.instance().layersWillBeRemoved.connect( self._on_overlay_to_be_removed)
def __init__(self, str_editor): """ Handles the validity period component logic. :param str_editor: The STREditor object. :type str_editor: Object """ self.str_editor = str_editor self.from_date = self.str_editor.validity_from_date self.to_date = self.str_editor.validity_to_date self.current_profile = current_profile() self.social_tenure = self.current_profile.social_tenure self.init_dates() str_editor.tenure_duration.valueChanged.connect( self.bind_to_date_by_year_month ) str_editor.in_years.clicked.connect( self.adjust_to_year ) str_editor.in_months.clicked.connect( self.adjust_to_month ) self.to_date.dateChanged.connect( self.bind_year_month_by_dates_range ) self.from_date.dateChanged.connect( self.bind_year_month_by_dates_range ) self.from_date.dateChanged.connect( self.set_minimum_to_date ) self.set_minimum_to_date() self.set_range_from_date() self.set_range_to_date()
def __init__(self, iface, plugin=None): """Constructor.""" QDockWidget.__init__(self, iface.mainWindow()) # Set up the user interface from Designer. self.setupUi(self) self.iface = iface self._plugin = plugin self.gps_tool_dialog = None self.curr_lyr_table = None self.curr_lyr_sp_col = None self.curr_layer = None self.setMaximumHeight(300) self._curr_profile = current_profile() self._profile_spatial_layers = [] self.stdm_fields = STDMFieldWidget() self._populate_layers() self.feature_details = DetailsTreeView(iface, self) self.spatial_unit = None self.iface.currentLayerChanged.connect(self.control_digitize_toolbar) self.onLayerAdded.connect(self.init_spatial_form) self.add_to_canvas_button.clicked.connect( self.on_add_to_canvas_button_clicked) self.feature_details_btn.clicked.connect( self.feature_details.activate_feature_details) self.iface.currentLayerChanged.connect( lambda: self.feature_details.activate_feature_details(False))
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)
def profile(self): """ :return:profile object :rtype: Object """ return current_profile()
def __init__(self): """ Initialize the STR component class. """ super(ComponentUtility, self).__init__() self.current_profile = current_profile() self.social_tenure = self.current_profile.social_tenure self.parties = self.social_tenure.parties self.spatial_units = self.social_tenure.spatial_units self.str_model = None self.str_doc_model = None if len(self.parties) > 0: self.party_1 = self.parties[0] if len(self.spatial_units) > 0: self.spatial_unit_1 = self.spatial_units[0] try: self.str_model, self.str_doc_model = entity_model( self.social_tenure, False, True ) except Exception as ex: QMessageBox.critical( iface.mainWindow(), QApplication.translate('ComponentUtility', 'Database Error'), str(ex) )
def __init__(self, composer_wrapper, parent=None): QWidget.__init__(self, parent) self.setupUi(self) self._composer_wrapper = composer_wrapper self._notif_bar = NotificationBar(self.vl_notification) self._curr_profile = current_profile() #Load fields if the data source has been specified ds_name = self._composer_wrapper.selectedDataSource() self.ref_table.load_data_source_fields(ds_name) #Base document table in the current profile self._base_document_table = self._curr_profile.supporting_document.name #Add it to the list of tables to omit self.ref_table.add_omit_table(self._base_document_table) ''' Load referenced table list and filter so to only load supporting doc tables. ''' self.ref_table.load_link_tables(supporting_doc_tables_regexp()) #Connect signals self._composer_wrapper.dataSourceSelected.connect(self.ref_table.on_data_source_changed) self.ref_table.cbo_ref_table.currentIndexChanged[str].connect( self.update_document_types )
def init_gui(self): #Set integer validator for the port number int_validator = QIntValidator(1024, 49151) self.txtPort.setValidator(int_validator) #Load profiles self.load_profiles() #Set current profile in the combobox curr_profile = current_profile() if not curr_profile is None: setComboCurrentIndexWithText(self.cbo_profiles, curr_profile.name) #Load current database connection properties self._load_db_conn_properties() #Load existing PostgreSQL connections self._load_qgis_pg_connections() #Load directory paths self._load_directory_paths() self.edtEntityRecords.setMaximum(MAX_LIMIT) self.edtEntityRecords.setValue(get_entity_browser_record_limit()) # Debug logging lvl = debug_logging() if lvl: self.chk_logging.setCheckState(Qt.Checked) else: self.chk_logging.setCheckState(Qt.Unchecked)
def profile_entity_attribute(self): """ :param entity: :return: """ cols = current_profile().entity_by_name(self.entity_name).columns return cols
def profile(self): """ :return:profile object :rtype: Object """ return current_profile()
def __init__(self, parent, lookup_entity_name, profile=None): """ Initializes LookupValueSelector. :param parent: The parent of the dialog. :type parent: QWidget :param lookup_entity_name: The lookup entity name :type lookup_entity_name: String :param profile: The current profile object :type profile: Object """ QDialog.__init__(self, parent, Qt.WindowTitleHint | Qt.WindowCloseButtonHint) self.setupUi(self) self.value_and_code = None if profile is None: self._profile = current_profile() else: self._profile = profile self.lookup_entity = self._profile.entity_by_name( '{}_{}'.format(self._profile.prefix, lookup_entity_name) ) self.notice = NotificationBar(self.notice_bar) self._view_model = QStandardItemModel() self.value_list_box.setModel(self._view_model) header_item = QStandardItem(lookup_entity_name) self._view_model.setHorizontalHeaderItem(0, header_item) self.populate_value_list_view() self.selected_code = None self.selected_value_code = None self.value_list_box.clicked.connect(self.validate_selected_code)
def __init__(self, entity_document, document_model, parent=None): QObject.__init__(self, parent) self.containers = OrderedDict() self._canEdit = True self.document_model = document_model self.curr_profile = current_profile() self.entity_supporting_doc = entity_document.document_type_entity check_doc_type_model = entity_model(self.entity_supporting_doc) doc_type_obj = check_doc_type_model() doc_type_list = doc_type_obj.queryObject().all() self.doc_types = [(doc.id, doc.value) for doc in doc_type_list] self.doc_types = dict(self.doc_types) for id in self.doc_types.keys(): document_type_class[id] = self.document_model #Container for document references based on their unique IDs self._docRefs = [] #Set default manager for document viewing self._doc_view_manager = DocumentViewManager(self.parent_widget()) self.doc_type_mapping = OrderedDict() for id, value in self.doc_types.iteritems(): self.doc_type_mapping[id] = value
def __init__( self, document_model=None, fileManager=None, mode=UPLOAD_MODE, parent=None, canRemove=True, view_manager=None ): QWidget.__init__(self, parent) self.setupUi(self) self.initGui() self.fileInfo = None self.fileUUID = None self.document_model = document_model self.fileManager = fileManager self._mode = mode self._displayName = "" self._docSize = 0 self._srcDoc = None self._fileName = "" self._canRemove = canRemove self._view_manager = view_manager self.curr_profile = current_profile() self.removed_doc = [] self.lblClose.installEventFilter(self) self.lblName.installEventFilter(self) self._source_entity = "" self._doc_type = "" self._doc_type_id = None #Set defaults self.fileNameColor = "#5555ff" self.fileMetaColor = "#8f8f8f"
def active_profile(self): """ get the user selected profile :return:p """ self.profile = current_profile().name return self.profile
def __init__(self,parent=None): QWizard.__init__(self,parent) self.setupUi(self) self.curr_profile = current_profile() #Event Handlers self.btnDestFile.clicked.connect(self.setDestFile) self.lstSrcTab.itemSelectionChanged.connect(self.srcSelectChanged) self.btnUniqueVals.clicked.connect(self.colUniqueValues) #Query Builder signals self.lstQueryCols.itemDoubleClicked.connect(self.filter_insertField) self.lstUniqueVals.itemDoubleClicked.connect(self.filter_insertField) self.btnOpEq.clicked.connect(self.filter_insertEq) self.btnOpNotEq.clicked.connect(self.filter_insertNotEq) self.btnOpLike.clicked.connect(self.filter_insertLike) self.btnOpGreater.clicked.connect(self.filter_greaterThan) self.btnOpGreaterEq.clicked.connect(self.filter_greaterEq) self.btnOpAnd.clicked.connect(self.filter_insertAnd) self.btnOpLess.clicked.connect(self.filter_insertLess) self.btnOpLessEq.clicked.connect(self.filter_insertLessEq) self.btnOpOr.clicked.connect(self.filter_insertOR) self.btnClearQuery.clicked.connect(self.filter_clearQuery) self.btnQueryVerify.clicked.connect(self.filter_verifyQuery) self.select_all.clicked.connect(self.select_all_columns) self.select_none.clicked.connect(self.select_none_columns) #Init controls self.initControls() #Register fields self.registerFields()
def profile_entity_attribute(self): """ :param entity: :return: """ cols = current_profile().entity_by_name(self.entity_name).columns return cols
def __init__(self): """ Initialize the STR component class. """ super(ComponentUtility, self).__init__() self.current_profile = current_profile() self.social_tenure = self.current_profile.social_tenure self.parties = self.social_tenure.parties self.spatial_units = self.social_tenure.spatial_units self.str_model = None self.str_doc_model = None if len(self.parties) > 0: self.party_1 = self.parties[0] if len(self.spatial_units) > 0: self.spatial_unit_1 = self.spatial_units[0] try: self.str_model, self.str_doc_model = entity_model( self.social_tenure, False, True ) except Exception as ex: QMessageBox.critical( iface.mainWindow(), QApplication.translate('ComponentUtility', 'Database Error'), str(ex) )
def __init__(self, iface, parent=None): QObject.__init__(self, parent) self._iface = iface self._map_renderer = self._iface.mapCanvas().mapRenderer() self._dbSession = STDMDb.instance().session self._attr_value_formatters = {} self._current_profile = current_profile() if self._current_profile is None: raise Exception('Current data profile has not been set.') #For cleanup after document compositions have been created self._map_memory_layers = [] self.map_registry = QgsMapLayerRegistry.instance() self._table_mem_layers = [] self._feature_ids = [] self._link_field = "" self._base_photo_table = "supporting_document" #Value formatter for output files self._file_name_value_formatter = None
def __init__(self, str_editor): """ Handles the validity period component logic. :param str_editor: The STREditor object. :type str_editor: Object """ self.str_editor = str_editor self.from_date = self.str_editor.validity_from_date self.to_date = self.str_editor.validity_to_date self.current_profile = current_profile() self.social_tenure = self.current_profile.social_tenure self.init_dates() str_editor.tenure_duration.valueChanged.connect( self.bind_to_date_by_year_month ) str_editor.in_years.clicked.connect( self.adjust_to_year ) str_editor.in_months.clicked.connect( self.adjust_to_month ) self.to_date.dateChanged.connect( self.bind_year_month_by_dates_range ) self.from_date.dateChanged.connect( self.bind_year_month_by_dates_range ) self.from_date.dateChanged.connect( self.set_minimum_to_date ) self.set_minimum_to_date() self.set_range_from_date() self.set_range_to_date()
def init_gui(self): #Set integer validator for the port number int_validator = QIntValidator(1024, 49151) self.txtPort.setValidator(int_validator) #Load profiles self.load_profiles() #Set current profile in the combobox curr_profile = current_profile() if not curr_profile is None: setComboCurrentIndexWithText(self.cbo_profiles, curr_profile.name) #Load current database connection properties self._load_db_conn_properties() #Load existing PostgreSQL connections self._load_qgis_pg_connections() #Load directory paths self._load_directory_paths() # Debug logging lvl = debug_logging() if lvl: self.chk_logging.setCheckState(Qt.Checked) else: self.chk_logging.setCheckState(Qt.Unchecked)
def __init__(self, parent=None): QWizard.__init__(self, parent) self.setupUi(self) self.curr_profile = current_profile() #Event Handlers self.btnDestFile.clicked.connect(self.setDestFile) self.lstSrcTab.itemSelectionChanged.connect(self.srcSelectChanged) self.btnUniqueVals.clicked.connect(self.colUniqueValues) #Query Builder signals self.lstQueryCols.itemDoubleClicked.connect(self.filter_insertField) self.lstUniqueVals.itemDoubleClicked.connect(self.filter_insertField) self.btnOpEq.clicked.connect(self.filter_insertEq) self.btnOpNotEq.clicked.connect(self.filter_insertNotEq) self.btnOpLike.clicked.connect(self.filter_insertLike) self.btnOpGreater.clicked.connect(self.filter_greaterThan) self.btnOpGreaterEq.clicked.connect(self.filter_greaterEq) self.btnOpAnd.clicked.connect(self.filter_insertAnd) self.btnOpLess.clicked.connect(self.filter_insertLess) self.btnOpLessEq.clicked.connect(self.filter_insertLessEq) self.btnOpOr.clicked.connect(self.filter_insertOR) self.btnClearQuery.clicked.connect(self.filter_clearQuery) self.btnQueryVerify.clicked.connect(self.filter_verifyQuery) self.select_all.clicked.connect(self.select_all_columns) self.select_none.clicked.connect(self.select_none_columns) #Init controls self.initControls() #Register fields self.registerFields()
def __init__(self, item: StdmPhotoLayoutItem, parent=None): QWidget.__init__(self, parent) self.setupUi(self) self._layout = item.layout() self._item = item self._notif_bar = NotificationBar(self.vl_notification) self._curr_profile = current_profile() # Load fields if the data source has been specified ds_name = LayoutUtils.get_stdm_data_source_for_layout(self._layout) self.ref_table.load_data_source_fields(ds_name) # Base document table in the current profile self._base_document_table = self._curr_profile.supporting_document.name # Add it to the list of tables to omit self.ref_table.add_omit_table(self._base_document_table) ''' Load referenced table list and filter so to only load supporting doc tables. ''' self.ref_table.load_link_tables(supporting_doc_tables_regexp()) self.ref_table.set_layout(self._layout) self.ref_table.cbo_ref_table.currentIndexChanged[str].connect( self.update_document_types) self.set_from_item() self.ref_table.changed.connect(self._item_changed) self.cbo_document_type.currentTextChanged.connect(self._item_changed)
def active_profile(self): """ get the user selected profile :return:p """ self.profile = current_profile().name return self.profile
def absolute_document_path(self, document_widget): """ Build the absolute document path using info from the document widget. :param document_widget: Instance of document widget. :return: Absolute path of the supporting document. :rtype: str """ abs_path = '' file_manager = document_widget.fileManager if not file_manager is None: network_repository = file_manager.networkPath file_id = document_widget.file_identifier() source_entity = document_widget.doc_source_entity() profile_name = current_profile().name doc_type = document_widget.doc_type_value().lower().replace( ' ', '_' ) file_name, file_extension = guess_extension( document_widget.displayName() ) abs_path = network_repository + "/" +profile_name + '/' +\ unicode(source_entity) + "/" + unicode(doc_type) + "/" +\ unicode(file_id) + unicode(file_extension) return abs_path
def __init__(self, entity_document, document_model, parent=None): QObject.__init__(self, parent) self.containers = OrderedDict() self._canEdit = True self.document_model = document_model self.curr_profile = current_profile() self.entity_supporting_doc = entity_document.document_type_entity check_doc_type_model = entity_model(self.entity_supporting_doc) doc_type_obj = check_doc_type_model() doc_type_list = doc_type_obj.queryObject().all() self.doc_types = [(doc.id, doc.value) for doc in doc_type_list] self.doc_types = dict(self.doc_types) for id in self.doc_types.keys(): document_type_class[id] = self.document_model #Container for document references based on their unique IDs self._docRefs = [] #Set default manager for document viewing self._doc_view_manager = DocumentViewManager(self.parent_widget()) self.doc_type_mapping = OrderedDict() for id, value in self.doc_types.iteritems(): self.doc_type_mapping[id] = value
def __init__( self, document_model=None, fileManager=None, mode=UPLOAD_MODE, parent=None, canRemove=True, view_manager=None ): QWidget.__init__(self, parent) self.setupUi(self) self.initGui() self.fileInfo = None self.fileUUID = None self.document_model = document_model self.fileManager = fileManager self._mode = mode self._displayName = "" self._docSize = 0 self._srcDoc = None self._fileName = "" self._canRemove = canRemove self._view_manager = view_manager self.curr_profile = current_profile() self.removed_doc = [] self.lblClose.installEventFilter(self) self.lblName.installEventFilter(self) self._source_entity = "" self._doc_type = "" self._doc_type_id = None #Set defaults self.fileNameColor = "#5555ff" self.fileMetaColor = "#8f8f8f"
def __init__(self,parent=None): QWizard.__init__(self,parent) self.setupUi(self) self.curr_profile = current_profile() #Connect signals self.btnBrowseSource.clicked.connect(self.setSourceFile) self.lstDestTables.itemClicked.connect(self.destSelectChanged) self.btnSrcUp.clicked.connect(self.srcItemUp) self.btnSrcDown.clicked.connect(self.srcItemDown) self.btnSrcAll.clicked.connect(self.checkSrcItems) self.btnSrcNone.clicked.connect(self.uncheckSrcItems) self.btnDestUp.clicked.connect(self.targetItemUp) self.btnDestDown.clicked.connect(self.targetItemDown) self.lstSrcFields.currentRowChanged[int].connect(self.sourceRowChanged) self.lstTargetFields.currentRowChanged[int].connect(self.destRowChanged) self.lstTargetFields.currentRowChanged[int].connect(self._enable_disable_trans_tools) self.chk_virtual.toggled.connect(self._on_load_virtual_columns) #Data Reader self.dataReader = None #Init self.registerFields() #Geometry columns self.geomcols = [] #Initialize value translators from definitions self._init_translators()
def __init__(self, iface, plugin=None): """Constructor.""" QDockWidget.__init__(self, iface.mainWindow()) # Set up the user interface from Designer. self.setupUi(self) self.iface = iface self._plugin = plugin self.gps_tool_dialog = None # properties of last added layer self.curr_lyr_table = None self.curr_lyr_sp_col = None # properties of the active layer self.active_entity = None self.active_table = None self.active_sp_col = None self.style_updated = None self.setMaximumHeight(300) self._curr_profile = current_profile() self._profile_spatial_layers = [] self.stdm_fields = STDMFieldWidget() self._populate_layers() self._adjust_layer_drop_down_width() self.spatial_unit = None self.iface.currentLayerChanged.connect(self.control_digitize_toolbar) self.onLayerAdded.connect(self.init_spatial_form) self.add_to_canvas_button.clicked.connect( self.on_add_to_canvas_button_clicked) self.iface.projectRead.connect(self.on_project_opened)
def __init__(self, parent, lookup_entity_name, profile=None): """ """ QDialog.__init__(self, parent, Qt.WindowTitleHint|Qt.WindowCloseButtonHint) self.setupUi(self) self.value_and_code = None if profile is None: self._profile = current_profile() else: self._profile = profile self.lookup_entity = self._profile.entity_by_name( '{}_{}'.format(self._profile.prefix, lookup_entity_name) ) self.notice = NotificationBar(self.notice_bar) self._view_model = QStandardItemModel() self.value_list_box.setModel(self._view_model) header_item = QStandardItem(lookup_entity_name) self._view_model.setHorizontalHeaderItem(0, header_item) self.populate_value_list_view() self.selected_code = None self.selected_value_code = None self.value_list_box.clicked.connect(self.validate_selected_code)
def __init__(self,parent=None): QWizard.__init__(self,parent) self.setupUi(self) self.curr_profile = current_profile() #Connect signals self.btnBrowseSource.clicked.connect(self.setSourceFile) self.lstDestTables.itemClicked.connect(self.destSelectChanged) self.btnSrcUp.clicked.connect(self.srcItemUp) self.btnSrcDown.clicked.connect(self.srcItemDown) self.btnSrcAll.clicked.connect(self.checkSrcItems) self.btnSrcNone.clicked.connect(self.uncheckSrcItems) self.btnDestUp.clicked.connect(self.targetItemUp) self.btnDestDown.clicked.connect(self.targetItemDown) self.lstSrcFields.currentRowChanged[int].connect(self.sourceRowChanged) self.lstTargetFields.currentRowChanged[int].connect(self.destRowChanged) self.lstTargetFields.currentRowChanged[int].connect(self._enable_disable_trans_tools) self.chk_virtual.toggled.connect(self._on_load_virtual_columns) #Data Reader self.dataReader = None #Init self.registerFields() #Geometry columns self.geomcols = [] #Initialize value translators from definitions self._init_translators()
def __init__(self, composer_wrapper, parent=None): QWidget.__init__(self, parent) self.setupUi(self) self._composer_wrapper = composer_wrapper self._notif_bar = NotificationBar(self.vl_notification) self._curr_profile = current_profile() # Load fields if the data source has been specified ds_name = self._composer_wrapper.selectedDataSource() self.ref_table.load_data_source_fields(ds_name) # Base document table in the current profile self._base_document_table = self._curr_profile.supporting_document.name # Add it to the list of tables to omit self.ref_table.add_omit_table(self._base_document_table) ''' Load referenced table list and filter so to only load supporting doc tables. ''' self.ref_table.load_link_tables(supporting_doc_tables_regexp()) # Connect signals self._composer_wrapper.dataSourceSelected.connect(self.ref_table.on_data_source_changed) self.ref_table.cbo_ref_table.currentIndexChanged[str].connect( self.update_document_types )
def certificate_postprocess(plot, plots): """ Updates the certificate details and removes the layers after generation of the certificate. """ cert_number = pg_certificate_number() user_name = stdm.data.app_dbconn.User.UserName curr_datetime = QDateTime.currentDateTime().toPyDateTime() curr_profile = current_profile() if not current_profile: return cert_entity = curr_profile.entity('Certificate') if not cert_entity: return cert_model = entity_model(cert_entity) cert_obj = cert_model() cert_obj.plot_id = plot.id cert_obj.scheme_id = plot.scheme_id cert_obj.certificate_number = cert_number cert_obj.production_date = curr_datetime cert_obj.prod_user = user_name cert_obj.save() # Remove certificate plot layer layers = QgsMapLayerRegistry.instance().mapLayersByName(CERTIFICATE_PLOT) if len(layers) > 0: QgsMapLayerRegistry.instance().removeMapLayer(layers[0])
def __init__( self, data_store, str_model, str_edit_node=None ): """ Initializes the saving of STRDBHandler. :param data_store: The data store containing STR record. :type data_store: Object :param str_model: The model of STR :type str_model: SQLAlchemy Model :param str_edit_node: The STR Edit node data containing STR model and supporting document models when in edit mode. :type str_edit_node: Tuple or STRNode """ self.str_model = str_model self.data_store = data_store self.progress = STDMProgressDialog(iface.mainWindow()) self.social_tenure = current_profile().social_tenure self.str_edit_node = [] if str_edit_node is not None: if isinstance(str_edit_node, tuple): self.str_edit_node.append((str_edit_node[0], str_edit_node[1])) elif isinstance(str_edit_node, list): self.str_edit_node = str_edit_node else: self.str_edit_node.append((str_edit_node.model(), str_edit_node.documents()))
def __init__(self, parent=None): QWidget.__init__(self, parent) self.setupUi(self) self.cboDataSource.setInsertPolicy(QComboBox.InsertAlphabetically) self.cboReferencedTable.setInsertPolicy(QComboBox.InsertAlphabetically) self.curr_profile = current_profile() self.rbTables.toggled.connect(self.onShowTables) self.rbViews.toggled.connect(self.onShowViews) # Load reference tables self._ref_tables = profile_entities(self.curr_profile) # Load all tables self._tables = profile_user_tables(self.curr_profile, False) # Populate referenced tables self._populate_referenced_tables() # Flag for synchronizing data source item change to referenced table self._sync_data_source = False # Force views to be loaded self.rbViews.toggle() # Connect signal self.cboDataSource.currentIndexChanged[str].connect( self.onDataSourceSelected) self.cboReferencedTable.setEnabled(False)
def __init__(self, config, formatter=None, parent=None): QWidget.__init__(self, parent) EntitySearchItem.__init__(self, formatter) self.setupUi(self) self.tbSTRViewEntity.setTabIcon(0, GuiUtils.get_icon('filter.png')) self.tbSTRViewEntity.setTabIcon(1, GuiUtils.get_icon('period_blue.png')) self.config = config self.setConfigOptions() self.curr_profile = current_profile() self.social_tenure = self.curr_profile.social_tenure self.str_model = entity_model(self.social_tenure) # Model for storing display and actual mapping values self._completer_model = None self._proxy_completer_model = None # Hook up signals self.cboFilterCol.currentIndexChanged.connect( self._on_column_index_changed) self.init_validity_dates() self.validity_from_date.dateChanged.connect(self.set_minimum_to_date) self.validity.setDisabled(True) self.init_validity_checkbox()
def init_gui(self): # Set integer validator for the port number int_validator = QIntValidator(1024, 49151) self.txtPort.setValidator(int_validator) # Load profiles self.load_profiles() # Set current profile in the combobox curr_profile = current_profile() if not curr_profile is None: setComboCurrentIndexWithText(self.cbo_profiles, curr_profile.name) # Load current database connection properties self._load_db_conn_properties() # Load existing PostgreSQL connections self._load_qgis_pg_connections() # Load directory paths self._load_directory_paths() self.edtEntityRecords.setMaximum(MAX_LIMIT) self.edtEntityRecords.setValue(get_entity_browser_record_limit()) # Sorting order self.populate_sort_order() self.set_current_sort_order(get_entity_sort_order()) # Debug logging lvl = debug_logging() if lvl: self.chk_logging.setCheckState(Qt.Checked) else: self.chk_logging.setCheckState(Qt.Unchecked)
def read_instance_data(self): """Read all instance data once and store them in a dict :rtype: dict """ mobile_data = OrderedDict() social_tenure_info = OrderedDict() for instance in self.instance_list: self.uuid_extractor.set_file_path(instance) field_data_nodes = self.uuid_extractor.document_entities_with_data(current_profile().name.replace(' ', '_'), self.user_selected_entities()) str_data_nodes = self.uuid_extractor.document_entities_with_data(current_profile().name.replace(' ', '_'), ['social_tenure']) mobile_data[instance] = [field_data_nodes, str_data_nodes] self.uuid_extractor.close_document() return mobile_data
def onContentClicked(self,index): ''' Slot activated when a content item is selected to load the roles for the specified content items ''' self.lstRoles.setEnabled(True) contentName = index.data() self.loadRoles(contentName) self.privilege_provider = SinglePrivilegeProvider(contentName, current_profile() )
def __init__(self, iface, parent=None, plugin=None): self._iface = iface self._doc_gen_dlg = DocumentGeneratorDialog(self._iface, parent, plugin=plugin) self._notif_bar = self._doc_gen_dlg.notification_bar() self.curr_profile = current_profile() #Load entity configurations self._load_entity_configurations()
def __init__(self, network_repository ,parent = None): QObject.__init__(self,parent) self.networkPath = network_repository self.fileID = None self.sourcePath = None self.destinationPath = None self.curr_profile = current_profile() self._entity_source = '' self._doc_type = ''
def populate_spatial_units(self): """ Populates the spatial unit entities in the entities combobox. """ self.spatial_units = current_profile().social_tenure.spatial_units for entity in self.spatial_units: self.entity_combo.addItem( entity.short_name, entity.name )
def populate_parties(self): """ Populates the party entities in the entities combobox. """ self.parties = current_profile().social_tenure.parties for entity in self.parties: self.entity_combo.addItem( entity.short_name, entity.name )
def save_to_db(self): """ Format object attribute data from entity and save them into database :return: """ self.column_info() try: if self.entity.short_name == 'social_tenure_relationship': #try: prefix = current_profile().prefix + '_' if self.attributes.has_key('party'): full_party_ref_column = self.attributes.get('party') party_ref_column = full_party_ref_column + '_id' self.attributes.pop('party') else: full_party_ref_column = current_profile().social_tenure.parties[0].name party_ref_column = full_party_ref_column + '_id' setattr(self.model, party_ref_column, self.parents_ids.get(prefix + full_party_ref_column)[0]) if self.attributes.has_key('spatial_unit'): full_spatial_ref_column = self.attributes.get('spatial_unit') spatial_ref_column = full_spatial_ref_column + '_id' self.attributes.pop('spatial_unit') else: full_spatial_ref_column = current_profile().social_tenure.spatial_units[0].name spatial_ref_column = full_spatial_ref_column + '_id' setattr(self.model, spatial_ref_column, self.parents_ids.get(prefix + full_spatial_ref_column)[0]) except: pass for k, v in self.attributes.iteritems(): if hasattr(self.model, k): col_type = self.entity_mapping.get(k) col_prop = self.entity.columns[k] var = self.attribute_formatter(col_type, col_prop, v) setattr(self.model, k, var) if self.entity_has_supporting_docs(): self.model.documents = self._doc_manager.model_objects() self.model.save() return self.model.id
def populate_entities_widget(self): """ Add entities in the instance file into a list view widget """ self.lst_widget.clear() entities = self.instance_entities() if len(entities) > 0: for entity in entities: list_widget = QListWidgetItem( current_profile().entity_by_name(entity).short_name, self.lst_widget) list_widget.setCheckState(Qt.Checked)
def _valid_entity(self): """ Checks if the current active layer in the layer panel represents a valid entity in the current profile :return: Error object :rtype: Object """ entity_profile = current_profile() entity_obj = entity_profile.entity_by_name(self.curr_lyr_table) if entity_obj is None: return None return entity_obj
def user_selected_entities(self): """ :rtype: list """ entities= [] count = self.lst_widget.count() if count > 0: for i in range(count): item = self.lst_widget.item(i) if item.checkState() == Qt.Checked: entities.append(current_profile().entity(item.text()).name) return entities
def entity(self): """ Returns the current entity. :return: Entity Object :rtype: Object """ curr_profile = current_profile() entity = curr_profile.entity_by_name( self.get_layer_source() ) return entity
def has_foreign_keys_parent(self, select_entities): """ Ensure we check that the table is not parent else import parent table first Revised in version 1.7. It explicitly assumes str is captured. before it was optional. :return: """ has_relations = False str_tables = current_profile().social_tenure party_tbls = str_tables.parties sp_tbls = str_tables.spatial_units self.relations = OrderedDict() if len(self.instance_list) > 0: if self.uuid_extractor.has_str_captured_in_instance(self.instance_list[0]): for party_tbl in party_tbls: self.relations[party_tbl.name] = ['social_tenure_relationship', party_tbl.short_name.lower() + '_id'] for sp_tbl in sp_tbls: self.relations[sp_tbl.name] = ['social_tenure_relationship', sp_tbl.short_name.lower() + '_id'] # print self.relations for table in select_entities: table_object = current_profile().entity_by_name(table) cols = table_object.columns.values() for col in cols: if col.TYPE_INFO == 'FOREIGN_KEY': parent_object = table_object.columns[col.name] if parent_object.parent: if parent_object.parent.name in self.relations: self.relations[parent_object.parent.name].append([table, col.name]) else: self.relations[parent_object.parent.name] = [table, col.name] #self.relations[parent_object.parent.name].append([table, col.name]) has_relations = True else: continue return has_relations
def db_tables(self): """ Returns both textual and spatial table names. """ curr_profile = current_profile() tables = profile_user_tables( self._current_profile, False, True ).keys() return tables