def str_type_set_data(self): """ Sets str type combobox items. :return: STR type id and value. :rtype: OrderedDict """ lookup_column_name = self.social_tenure.spatial_unit_tenure_column( self.spatial_unit).name str_lookup_obj = lookup_parent_entity(self.curr_profile, lookup_column_name) str_types = entity_model(str_lookup_obj, True) str_type_obj = str_types() self.str_type_data = str_type_obj.queryObject().all() str_type = [(lookup.id, lookup.value) for lookup in self.str_type_data] return OrderedDict(str_type)
def str_type_set_data(self): """ Sets str type combobox items. :return: STR type id and value. :rtype: OrderedDict """ lookup_column_name = self.social_tenure.spatial_unit_tenure_column( self.spatial_unit).name str_lookup_obj = lookup_parent_entity( self.curr_profile, lookup_column_name ) str_types = entity_model(str_lookup_obj, True) str_type_obj = str_types() self.str_type_data = str_type_obj.queryObject().all() str_type = [(lookup.id, lookup.value) for lookup in self.str_type_data] return OrderedDict(str_type)
def executeSearch(self): """ Base class override. Search for matching items for the specified entity and column. """ model_root_node = None prog_dialog = QProgressDialog(self) prog_dialog.setFixedWidth(380) prog_dialog.setWindowTitle( QApplication.translate("STRViewEntityWidget", "Searching for STR...")) prog_dialog.show() prog_dialog.setRange(0, 10) search_term = self._searchTerm() prog_dialog.setValue(2) # Try to get the corresponding search term value from the completer model if not self._completer_model is None: reg_exp = QRegExp("^%s$" % (search_term), Qt.CaseInsensitive, QRegExp.RegExp2) self._proxy_completer_model.setFilterRegExp(reg_exp) if self._proxy_completer_model.rowCount() > 0: # Get corresponding actual value from the first matching item value_model_idx = self._proxy_completer_model.index(0, 1) source_model_idx = self._proxy_completer_model.mapToSource( value_model_idx) prog_dialog.setValue(4) search_term = self._completer_model.data( source_model_idx, Qt.DisplayRole) modelInstance = self.config.STRModel() modelQueryObj = modelInstance.queryObject() queryObjProperty = getattr(self.config.STRModel, self.currentFieldName()) entity_name = modelQueryObj._primary_entity._label_name entity = self.curr_profile.entity_by_name(entity_name) prog_dialog.setValue(6) # Get property type so that the filter can # be applied according to the appropriate type propType = queryObjProperty.property.columns[0].type results = [] try: if not isinstance(propType, String): col_name = self.currentFieldName() col = entity.columns[self.currentFieldName()] if col.TYPE_INFO == 'LOOKUP': lookup_entity = lookup_parent_entity( self.curr_profile, col_name) lkp_model = entity_model(lookup_entity) lkp_obj = lkp_model() value_obj = getattr(lkp_model, 'value') result = lkp_obj.queryObject().filter( func.lower(value_obj) == func.lower( search_term)).first() if result is None: result = lkp_obj.queryObject().filter( func.lower(value_obj).like(search_term + '%')).first() if not result is None: results = modelQueryObj.filter( queryObjProperty == result.id).all() else: results = [] else: results = modelQueryObj.filter( func.lower(queryObjProperty) == func.lower( search_term)).all() if self.validity.isEnabled(): valid_str_ids = self.str_validity_period_filter(results) else: valid_str_ids = None prog_dialog.setValue(7) except exc.StatementError: return model_root_node, [], search_term # if self.formatter is not None: # self.formatter.setData(results) # model_root_node = self.formatter.root(valid_str_ids) prog_dialog.setValue(10) prog_dialog.hide() return results, search_term
def executeSearch(self): """ Base class override. Search for matching items for the specified entity and column. """ model_root_node = None prog_dialog = QProgressDialog(self) prog_dialog.setFixedWidth(380) prog_dialog.setWindowTitle( QApplication.translate( "STRViewEntityWidget", "Searching for STR..." ) ) prog_dialog.show() prog_dialog.setRange( 0, 10 ) search_term = self._searchTerm() prog_dialog.setValue(2) #Try to get the corresponding search term value from the completer model if not self._completer_model is None: reg_exp = QRegExp("^%s$"%(search_term), Qt.CaseInsensitive, QRegExp.RegExp2) self._proxy_completer_model.setFilterRegExp(reg_exp) if self._proxy_completer_model.rowCount() > 0: #Get corresponding actual value from the first matching item value_model_idx = self._proxy_completer_model.index(0, 1) source_model_idx = self._proxy_completer_model.mapToSource( value_model_idx ) prog_dialog.setValue(4) search_term = self._completer_model.data( source_model_idx, Qt.DisplayRole ) modelInstance = self.config.STRModel() modelQueryObj = modelInstance.queryObject() queryObjProperty = getattr( self.config.STRModel, self.currentFieldName() ) entity_name = modelQueryObj._primary_entity._label_name entity = self.curr_profile.entity_by_name(entity_name) prog_dialog.setValue(6) # Get property type so that the filter can # be applied according to the appropriate type propType = queryObjProperty.property.columns[0].type results = [] try: if not isinstance(propType, String): col_name = self.currentFieldName() col = entity.columns[self.currentFieldName()] if col.TYPE_INFO == 'LOOKUP': lookup_entity = lookup_parent_entity( self.curr_profile, col_name ) lkp_model = entity_model(lookup_entity) lkp_obj = lkp_model() value_obj = getattr( lkp_model, 'value' ) result = lkp_obj.queryObject().filter( func.lower(value_obj) == func.lower(search_term) ).first() if result is None: result = lkp_obj.queryObject().filter( func.lower(value_obj).like(search_term+'%') ).first() if not result is None: results = modelQueryObj.filter( queryObjProperty == result.id ).all() else: results = [] else: results = modelQueryObj.filter( func.lower(queryObjProperty) == func.lower(search_term) ).all() if self.validity.isEnabled(): valid_str_ids = self.str_validity_period_filter(results) else: valid_str_ids = None prog_dialog.setValue(7) except exc.StatementError: return model_root_node, [], search_term # if self.formatter is not None: # self.formatter.setData(results) # model_root_node = self.formatter.root(valid_str_ids) prog_dialog.setValue(10) prog_dialog.hide() return results, search_term