def _populate_combo(self, cbo, lookup_name): """ Populates comboboxes with items from the database. :param cbo: Combobox object :param lookup_name: name of the lookup table. """ res = export_data(lookup_name) cbo.clear() cbo.addItem('') for r in res: cbo.addItem(r.value, r.id)
def __init__(self, column): ColumnWidgetRegistry.__init__(self, column) self._lookups = {} # Query all lookups on initializing so as to reduce db roundtrips lookup = self._column.value_list # lk_cls = entity_model(lookup, entity_only=True) # lk_obj = lk_cls() # res = lk_obj.queryObject().filter().all() res = export_data(lookup.name) for r in res: self._lookups[r.id] = [r.value, r.code]
def __init__(self, column): ColumnWidgetRegistry.__init__(self, column) self._aus_cache = {} # Query all admin units on initializing aus = self._column.entity.profile.administrative_spatial_unit self._aus_cls = entity_model(aus, entity_only=True) self._aus_obj = self._aus_cls() # res = self._aus_obj.queryObject().filter().all() res = export_data(aus.name) for r in res: self._aus_cache[r.id] = [r.name, r.code]
def _load_scheme_document_types(self): """ Handles Uploading and viewing of the scheme supporting documents. """ doc_type_entity = self.curr_p.entity_by_name( self._scheme_doc_type_lookup) if doc_type_entity is None: QMessageBox.critical( self, self.tr('Scheme Document Type Lookup'), self.tr('The lookup table containing the document types is ' 'missing.')) self.tbw_documents.setEnabled(False) return # No need of fetching the documents again if already done before if self._supporting_docs_loaded: return # Check Doc mapper if not self._cmis_doc_mapper: QMessageBox.critical( self, self.tr('CMIS Server Error'), self.tr( 'Document mapper could not be initialized, please check ' 'the connection to the CMIS server.')) self.tbw_documents.setEnabled(False) self.btn_upload_dir.setEnabled(False) return doc_res = export_data(self._scheme_doc_type_lookup) # Add the documents types to the view for d in doc_res: doc_type = d.value code = d.code type_id = d.id self.tbw_documents.add_document_type(doc_type) # Also add the types to the CMIS doc mapper self._cmis_doc_mapper.add_document_type(doc_type, code, type_id) self._supporting_docs_loaded = True
def _populate_schemes(self): """ Populate the schemes combobox with items from the database. """ self.cbo_scheme_number.clear() self.cbo_scheme_number.addItem('') # Get scheme table data sch_data = export_data('cb_scheme') # Check if no schemes loaded if not sch_data: msg = self.tr( 'No schemes in the database.' ) self.show_error_message(msg) else: # Loop through result proxy to get scheme number and add to # combobox for s in sch_data: self.cbo_scheme_number.addItem(s.scheme_number, s.id) # Sort region combobox items self.cbo_scheme_number.model().sort(0)
def __init__(self, column): ColumnWidgetRegistry.__init__(self, column) self._parent_entity_cache = {} # Query all parent entities. Need for optimization p_entity = self._column.entity_relation.parent if p_entity is None: msg = QCoreApplication.translate( 'RelatedEntityWidgetFactory', 'The parent entity could not be determined. The input control ' 'will not be created.') raise WidgetException(msg) self._p_entity_cls = entity_model(p_entity, entity_only=True) self._p_entity_obj = self._p_entity_cls() # res = self._p_entity_obj.queryObject().filter().all() res = export_data(p_entity.name) for r in res: self._parent_entity_cache[r.id] = r
def __init__(self, cert_info, scheme_number, cmis_mngr=None, parent=None): super(CertificateUploadHandler, self).__init__(parent) self._cert_info = cert_info self._scheme_number = scheme_number # CMIS Manager self._cmis_mngr = cmis_mngr if not self._cmis_mngr: self._cmis_mngr = CmisManager() # CMIS document object self._doc_obj = None # Initialize Certificate models variables self._cert_model = None self._cert_doc_model = None # Assign model factory cert_models = certificate_model_factory() if not cert_models: return # Assign models values self._cert_model = cert_models[0] self._cert_doc_model = cert_models[1] self._cert_doc_mapper = CmisEntityDocumentMapper( cmis_manager=self._cmis_mngr, doc_model_cls=self._cert_doc_model, entity_name=self.CERT_ENTITY_NAME ) # Error messages as to why the upload handler is not responsive self._error_msg = [] # Get current profile curr_profile = current_profile() # Check if current profile exists if not curr_profile: self._error_msgs.append( 'Current profile is None' ) return cert_entity = curr_profile.entity( self.CERT_ENTITY_NAME ) if not cert_entity: self._error_msgs.append( 'Certificate entity not found' ) return # Get the name of the lookup table containing the document types # associated with the certificate entity cert_doc_type_tbl = cert_entity.supporting_doc.document_type_entity.name # Get the primary key, name and code of the certificate document type # in the lookup. cert_doc_types = export_data(cert_doc_type_tbl) # Map the required document types to the Cmis document mapper. for doc in cert_doc_types: doc_type = doc.value code = doc.code doc_type_id = doc.id self._cert_doc_mapper.add_document_type( doc_type, code, doc_type_id ) # Flag for checking if there is an active certificate upload/removal self._has_active_operation = False