Fixed an Issue with implications and alias editing

Fixed a crash when implications or aliases were edited the new dict format of the database caused crashes.
dev
Peery 2 years ago
parent 24feb63e5e
commit bcc39c5147
Signed by: pandro
SSH Key Fingerprint: SHA256:iBUZSuDxqYr4hYpe9U3BA9NJmXKpbGt4H0S8hUwIbrA

@ -100,7 +100,7 @@ class DBAdapter:
old_tags = [self.get_tag_by_ID(x)["name"].strip() for x in self.get_art_tags_by_ID(ID)] old_tags = [self.get_tag_by_ID(x)["name"].strip() for x in self.get_art_tags_by_ID(ID)]
for tag in tags: for tag in tags:
if tag in old_tags: # already present if tag["name"] in old_tags: # already present
continue continue
d = {"id": ID, "tag": tag["id"]} d = {"id": ID, "tag": tag["id"]}
try: try:
@ -600,14 +600,8 @@ class DBAdapter:
rows = self.db_cursor.fetchall() rows = self.db_cursor.fetchall()
new_rows = [] new_rows = []
for i in range(len(rows)): for i in range(len(rows)):
new_rows.append([]) new_rows.append({"name": rows[i][0].strip(), "description": rows[i][1].strip(),
for j in range(len(rows[i])): "category": int(rows[i][2]), "id": int(rows[i][3])})
if rows[i][j] is None:
new_rows[i].append("")
elif isinstance(rows[i][j], str):
new_rows[i].append(rows[i][j].strip())
else:
new_rows[i].append(rows[i][j])
return new_rows return new_rows
@ -662,8 +656,9 @@ class DBAdapter:
:return: :return:
""" """
name = name.strip().lower() name = name.strip().lower()
implications = [self.get_tag_ID(x) for x in implications] logging.debug(f"Editing Tag name={name}, desc={description}, aliases={aliases}, implications={implications}, category={category_id}")
aliases = [self.get_tag_ID(x) for x in aliases] #implications = [self.get_tag_ID(x) for x in implications]
#aliases = [self.get_tag_ID(x) for x in aliases]
d = { d = {
"id": tag_id, "id": tag_id,
"name": name, "name": name,
@ -681,23 +676,23 @@ class DBAdapter:
if aliases is not None: if aliases is not None:
old_aliases = self.get_tag_aliases_by_ID(tag_id) old_aliases = self.get_tag_aliases_by_ID(tag_id)
for alias in aliases: for alias in aliases:
if alias in old_aliases: # is this already set? if alias["id"] in old_aliases: # is this already set?
continue continue
self.add_alias_by_ID(tag_id, alias) self.add_alias_by_ID(tag_id, alias["id"])
for old_alias in old_aliases: for old_alias in old_aliases:
if old_alias not in aliases: # got to delete an alias? if old_alias not in [a["id"] for a in aliases]: # got to delete an alias?
self.remove_alias_by_ID(tag_id, old_alias) self.remove_alias_by_ID(tag_id, old_alias)
if implications is not None: if implications is not None:
old_implicants = self.get_tag_implications_by_ID(tag_id) old_implicants = self.get_tag_implications_by_ID(tag_id)
for implicant in implications: for implicant in implications:
if implicant in old_implicants: # is this already set? if implicant["id"] in old_implicants: # is this already set?
continue continue
self.add_implication_by_ID(tag_id, implicant) self.add_implication_by_ID(tag_id, implicant["id"])
for old_implicant in old_implicants: for old_implicant in old_implicants:
if old_implicant not in implications: # got to delete an implicant? if old_implicant not in [i["id"] for i in implications]: # got to delete an implicant?
self.remove_implication_by_ID(tag_id, old_implicant) self.remove_implication_by_ID(tag_id, old_implicant)
def add_alias_by_name(self, name: str, alias: str): def add_alias_by_name(self, name: str, alias: str):
@ -1002,7 +997,6 @@ class DBAdapter:
""" """
Search for the tag's implications Search for the tag's implications
:param name: :param name:
:param output_ID: Don't resolve the tag ids into names in the resulting list
:return: List of tag ids :return: List of tag ids
""" """
d = {"ID": self.get_tag_ID(name)} d = {"ID": self.get_tag_ID(name)}
@ -1021,11 +1015,7 @@ class DBAdapter:
result = [self.get_tag_by_ID(v) for v in r] result = [self.get_tag_by_ID(v) for v in r]
r = [] return result
for value in result:
r.append(value[0][1].strip())
return r
def get_tag_impliers_by_ID(self, ID: int): def get_tag_impliers_by_ID(self, ID: int):
""" """

@ -1,3 +1,5 @@
import logging
from typing import List
from PyQt5 import QtWidgets from PyQt5 import QtWidgets
from PyQt5.QtGui import QStandardItemModel, QStandardItem from PyQt5.QtGui import QStandardItemModel, QStandardItem
from PyQt5.QtCore import Qt from PyQt5.QtCore import Qt
@ -47,12 +49,12 @@ class TagModifyDialog(QtWidgets.QDialog):
item_model = QStandardItemModel(self.ui.tag_alias_search_list) item_model = QStandardItemModel(self.ui.tag_alias_search_list)
for tag in aliases: for tag in aliases:
tag = tag[0].strip() if tag["name"] == self.ui.tag_name_line.text():
if tag == self.ui.tag_name_line.text():
continue continue
item = QStandardItem(tag) item = QStandardItem(tag["name"])
item.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled) item.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)
item.setData(Qt.Unchecked, Qt.CheckStateRole) item.setData(Qt.Unchecked, Qt.CheckStateRole)
item.setData(tag, Qt.UserRole)
if set_checked: if set_checked:
item.setCheckState(Qt.Checked) item.setCheckState(Qt.Checked)
@ -72,12 +74,13 @@ class TagModifyDialog(QtWidgets.QDialog):
item_model = QStandardItemModel(self.ui.tag_implication_search_list) item_model = QStandardItemModel(self.ui.tag_implication_search_list)
for tag in implications: for tag in implications:
tag = tag[0].strip() if tag["name"] == self.ui.tag_name_line.text():
if tag == self.ui.tag_name_line.text():
continue continue
item = QStandardItem(tag) item = QStandardItem(tag["name"])
item.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled) item.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)
item.setData(Qt.Unchecked, Qt.CheckStateRole) item.setData(Qt.Unchecked, Qt.CheckStateRole)
item.setData(tag, Qt.UserRole)
if set_checked: if set_checked:
item.setCheckState(Qt.Checked) item.setCheckState(Qt.Checked)
@ -119,12 +122,12 @@ class TagModifyDialog(QtWidgets.QDialog):
item_model = QStandardItemModel(self.ui.tag_alias_selection_list) item_model = QStandardItemModel(self.ui.tag_alias_selection_list)
for tag in aliases: for tag in aliases:
tag = tag.strip() if tag["name"] == self.ui.tag_name_line.text():
if tag == self.ui.tag_name_line.text():
continue continue
item = QStandardItem(tag) item = QStandardItem(tag["name"])
item.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled) item.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)
item.setData(Qt.Unchecked, Qt.CheckStateRole) item.setData(Qt.Unchecked, Qt.CheckStateRole)
item.setData(tag, Qt.UserRole)
if set_checked: if set_checked:
item.setCheckState(Qt.Checked) item.setCheckState(Qt.Checked)
@ -134,7 +137,7 @@ class TagModifyDialog(QtWidgets.QDialog):
item_model.itemChanged.connect(self.on_selected_alias_tag_item_changed) item_model.itemChanged.connect(self.on_selected_alias_tag_item_changed)
self.ui.tag_alias_selection_list.setModel(item_model) self.ui.tag_alias_selection_list.setModel(item_model)
def set_selected_implicated_tags(self, implications: list, set_checked: bool=False): def set_selected_implicated_tags(self, implications: List[dict], set_checked: bool=False):
""" """
Set the tags in the search result list to tags Set the tags in the search result list to tags
:param implications: :param implications:
@ -144,12 +147,12 @@ class TagModifyDialog(QtWidgets.QDialog):
item_model = QStandardItemModel(self.ui.tag_implication_search_list) item_model = QStandardItemModel(self.ui.tag_implication_search_list)
for tag in implications: for tag in implications:
tag = tag.strip() if tag["name"] == self.ui.tag_name_line.text():
if tag == self.ui.tag_name_line.text():
continue continue
item = QStandardItem(tag) item = QStandardItem(tag["name"])
item.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled) item.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)
item.setData(Qt.Unchecked, Qt.CheckStateRole) item.setData(Qt.Unchecked, Qt.CheckStateRole)
item.setData(tag, Qt.UserRole)
if set_checked: if set_checked:
item.setCheckState(Qt.Checked) item.setCheckState(Qt.Checked)
@ -184,13 +187,14 @@ class TagModifyDialog(QtWidgets.QDialog):
self.set_search_implicated_tags(tags) self.set_search_implicated_tags(tags)
def on_search_implicated_tag_item_changed(self, item: QStandardItem): def on_search_implicated_tag_item_changed(self, item: QStandardItem):
logging.debug(f"Implication \"{item.text()}\" was clicked with data: "+str(item.data(Qt.UserRole)))
if item.checkState() == Qt.Checked: if item.checkState() == Qt.Checked:
if self.implication_selection is None: if self.implication_selection is None:
self.implication_selection = [] self.implication_selection = []
self.implication_selection.append(item.text()) self.implication_selection.append(item.data(Qt.UserRole))
elif item.checkState() == Qt.Unchecked: elif item.checkState() == Qt.Unchecked:
if item.text() in self.implication_selection: if item.text() in [x["name"] for x in self.implication_selection]:
self.implication_selection.remove(item.text()) self.implication_selection.remove(item.data(Qt.UserRole))
self.set_selected_implicated_tags(self.implication_selection, set_checked=True) self.set_selected_implicated_tags(self.implication_selection, set_checked=True)
@ -198,17 +202,17 @@ class TagModifyDialog(QtWidgets.QDialog):
if item.checkState() == Qt.Checked: if item.checkState() == Qt.Checked:
if self.alias_selection is None: if self.alias_selection is None:
self.alias_selection = [] self.alias_selection = []
self.alias_selection.append(item.text()) self.alias_selection.append(item.data(Qt.UserRole))
elif item.checkState() == Qt.Unchecked: elif item.checkState() == Qt.Unchecked:
if item.text() in self.alias_selection: if item.text() in [x["name"] for x in self.alias_selection]:
self.alias_selection.remove(item.text()) self.alias_selection.remove(item.data(Qt.UserRole))
self.set_selected_alias_tags(self.alias_selection, set_checked=True) self.set_selected_alias_tags(self.alias_selection, set_checked=True)
def on_selected_implicated_tag_item_changed(self, item: QStandardItem): def on_selected_implicated_tag_item_changed(self, item: QStandardItem):
if self.implication_selection is None: if self.implication_selection is None:
self.implication_selection = [] self.implication_selection = []
self.implication_selection.remove(item.text()) self.implication_selection.remove(item.data(Qt.UserRole))
self.set_selected_implicated_tags(self.implication_selection, set_checked=True) self.set_selected_implicated_tags(self.implication_selection, set_checked=True)
if self.tag_implication_search_result is not None: if self.tag_implication_search_result is not None:
@ -217,7 +221,7 @@ class TagModifyDialog(QtWidgets.QDialog):
def on_selected_alias_tag_item_changed(self, item: QStandardItem): def on_selected_alias_tag_item_changed(self, item: QStandardItem):
if self.alias_selection is None: if self.alias_selection is None:
self.alias_selection = [] self.alias_selection = []
self.alias_selection.remove(item.text()) self.alias_selection.remove(item.data(Qt.UserRole))
self.set_selected_alias_tags(self.alias_selection, set_checked=True) self.set_selected_alias_tags(self.alias_selection, set_checked=True)
self.set_search_alias_tags(self.tag_alias_search_result) self.set_search_alias_tags(self.tag_alias_search_result)

@ -1,3 +1,5 @@
from typing import List
from PyQt5 import QtWidgets from PyQt5 import QtWidgets
from PyQt5.QtGui import QStandardItemModel, QStandardItem from PyQt5.QtGui import QStandardItemModel, QStandardItem
from PyQt5.QtCore import Qt from PyQt5.QtCore import Qt
@ -41,7 +43,7 @@ class TagSelectDialog(QtWidgets.QDialog):
self.selected_item.setCheckState(Qt.Unchecked) self.selected_item.setCheckState(Qt.Unchecked)
self.selected_item = item self.selected_item = item
def set_search_result_list(self, tags: list): def set_search_result_list(self, tags: List[dict]):
""" """
Set the tags in the search result list to tags Set the tags in the search result list to tags
:param tags: :param tags:
@ -50,9 +52,10 @@ class TagSelectDialog(QtWidgets.QDialog):
item_model = QStandardItemModel(self.ui.search_result_list) item_model = QStandardItemModel(self.ui.search_result_list)
for tag in tags: for tag in tags:
item = QStandardItem(tag[0]) item = QStandardItem(tag["name"])
item.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled) item.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)
item.setData(Qt.Unchecked, Qt.CheckStateRole) item.setData(Qt.Unchecked, Qt.CheckStateRole)
item.setData(tag, Qt.UserRole)
item_model.appendRow(item) item_model.appendRow(item)
@ -71,14 +74,14 @@ class TagSelectDialog(QtWidgets.QDialog):
self.selection = item_data[0] self.selection = item_data[0]
elif self.selection is None: # nothing selected elif self.selection is None: # nothing selected
return None return None
tag = self.parent.get_tag(self.selection)[0] tag = self.parent.get_tag(self.selection)
tag_data = { tag_data = {
"ID": tag[3], "ID": tag["id"],
"name": tag[0], "name": tag["name"],
"description": tag[1], "description": tag["description"],
"aliases": self.parent.get_tag_aliases(tag[0]), "aliases": self.parent.get_tag_aliases(tag["name"]),
"implications": self.parent.get_tag_implications(tag[0]), "implications": self.parent.get_tag_implications(tag["name"]),
"category_id": tag[2] "category_id": tag["category"],
} }
print("TagSelectDialog selected tag:", tag_data) print("TagSelectDialog selected tag:", tag_data)
return tag_data return tag_data

@ -965,7 +965,7 @@ class ImporterWindow(ArtnetMainWindow):
if tag_data is None or len(tag_data.keys()) == 0: # got canceled? if tag_data is None or len(tag_data.keys()) == 0: # got canceled?
return return
if len(self.get_tag(tag_data["name"])) > 0: if self.get_tag(tag_data["name"]) is not None: # check if tag exists
QtWidgets.QMessageBox.information(self, "Duplicate Tag", "The tag \"{0}\" already exists in the db!" QtWidgets.QMessageBox.information(self, "Duplicate Tag", "The tag \"{0}\" already exists in the db!"
.format(tag_data["name"])) .format(tag_data["name"]))
return return
@ -1039,8 +1039,8 @@ class ImporterWindow(ArtnetMainWindow):
if tag is None or len(tag) == 0: if tag is None or len(tag) == 0:
return return
tag['aliases'] = self.main.db_connection.get_tag_aliases_by_name(tag["name"]) #tag['aliases'] = self.main.db_connection.get_tag_aliases_by_name(tag["name"])
tag['implications'] = self.main.db_connection.get_tag_implications(tag["name"]) #tag['implications'] = self.main.db_connection.get_tag_implications(tag["name"])
edit_dialog = TagModifyDialog(self, create_tag=False) edit_dialog = TagModifyDialog(self, create_tag=False)
edit_dialog.ui.tag_name_line.setText(tag["name"]) edit_dialog.ui.tag_name_line.setText(tag["name"])
@ -1125,12 +1125,7 @@ class ImporterWindow(ArtnetMainWindow):
def on_tag_search_change(self): def on_tag_search_change(self):
tags = self.main.db_connection.search_fuzzy_tag(self.ui.tag_search_bar.text(), all_if_empty=True) tags = self.main.db_connection.search_fuzzy_tag(self.ui.tag_search_bar.text(), all_if_empty=True)
self.set_tag_search_result_list(tags)
result = []
for tag_name, tag_desc, tag_category, tag_id in tags:
result.append({"name": tag_name, "description": tag_desc, "category": tag_category, "id": tag_id})
self.set_tag_search_result_list(result)
def on_category_creation_clicked(self): def on_category_creation_clicked(self):
dialog = CategoryModDialog(self, delete_category=False) dialog = CategoryModDialog(self, delete_category=False)

Loading…
Cancel
Save