Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace custom delete_basket method by a call to Ili2dbUtils in Model Baker lib #977

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 7 additions & 57 deletions QgisModelBaker/gui/basket_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,11 @@ def _delete_basket(self) -> None:
== QMessageBox.Yes
):
basket_config = self.baskets_panel.selected_basket_settings()
res, msg = self._do_delete_basket(basket_config)
ili2db_utils = Ili2DbUtils()
ili2db_utils.log_on_error.connect(self._log_on_delete_baskets_error)
res, msg = ili2db_utils.delete_baskets(
basket_config["bid_value"], self.configuration
)

if res:
# After deletion, make sure canvas is refreshed
Expand All @@ -169,59 +173,5 @@ def _refresh_map_layers(self):
layer.dataProvider().reloadData()
layer_tree_view.refreshLayerSymbology(layer.id())

def _do_delete_basket(self, basket_config):
# Keep original values just in case we need to go back to them
original_dataset_id = basket_config["dataset_t_id"]
original_dataset_name = basket_config["datasetname"]

# Create temporary dataset
tmp_dataset_id, tmp_dataset_name = "", "_tmp_dataset_tmp_"
res, msg = self.db_connector.create_dataset(tmp_dataset_name)
for _dataset in self.db_connector.get_datasets_info():
if _dataset["datasetname"] == tmp_dataset_name:
tmp_dataset_id = _dataset["t_id"]
break

if tmp_dataset_id == "":
return False, self.tr(
"Delete basket failed! Internal error modifying dataset/basket tables."
)

# Move basket to temporary dataset
basket_config["dataset_t_id"] = tmp_dataset_id
basket_config["datasetname"] = tmp_dataset_name

res, msg = self.db_connector.edit_basket(basket_config)
if not res:
return False, self.tr(
"Delete basket failed! Internal error modifying basket."
)

# Remove temporary dataset
ili2db_utils = Ili2DbUtils()
ili2db_utils.log_on_error.connect(self._log_on_delete_dataset_error)
res, msg = ili2db_utils.delete_dataset(tmp_dataset_name, self.configuration)

# If anything went bad, leave everything as the original status,
# i.e., move the basket to its original dataset
if not res:
msg = self.tr(
"Delete basket failed! Internal error deleting dataset/basket records."
)
basket_config["dataset_t_id"] = original_dataset_id
basket_config["datasetname"] = original_dataset_name
_res, _msg = self.db_connector.edit_basket(basket_config)
if not _res:
# We shouldn't reach this, the basket is in another dataset!
msg = self.tr("The basket (t_id: {}) couldn't be deleted!").format(
basket_config["basket_t_id"]
)
else:
msg = self.tr("Basket (t_id: {}) successfully deleted!").format(
basket_config["basket_t_id"]
)

return res, msg

def _log_on_delete_dataset_error(self, log):
QgsMessageLog.logMessage(log, self.tr("Delete dataset from DB"), Qgis.Critical)
def _log_on_delete_baskets_error(self, log):
QgsMessageLog.logMessage(log, self.tr("Delete basket from DB"), Qgis.Critical)
2 changes: 1 addition & 1 deletion QgisModelBaker/gui/panel/summary_basket_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def data(self, index, role):
return None

def basket_config_by_index(self, index: QModelIndex) -> dict:
# Return the basket config for the row corrsponding to the given index.
# Return the basket config for the row corresponding to the given index.
# This includes the whole basket configuration (t_id, dataset_id,
# topic, etc.)
return list(self.basket_settings.values())[index.row()]
Expand Down