diff options
-rwxr-xr-x | assignment-list.py | 5 | ||||
-rw-r--r-- | db_sqlite.py | 34 | ||||
-rw-r--r-- | group.py | 3 |
3 files changed, 40 insertions, 2 deletions
diff --git a/assignment-list.py b/assignment-list.py index a09a448..7b9762c 100755 --- a/assignment-list.py +++ b/assignment-list.py @@ -98,6 +98,7 @@ class AssignmentList(QMainWindow): """ # TODO might want to add a warning # TODO might want to make part of the a destructor in the Group class + DB.removeGroup(id) Globals.entries = list(filter(lambda e: e.parent_id != id, Globals.entries)) Globals.groups = list(filter(lambda g: g.id != id, Globals.groups)) self.drawGroups() @@ -138,6 +139,10 @@ class AssignmentList(QMainWindow): column_right = QVBoxLayout() for g in Globals.groups: + # skip if this group is set to hidden + if g.hidden: + continue + # Include buttons at the bottom to edit the group g_layout = g.buildLayout() buttons_hbox = QHBoxLayout() diff --git a/db_sqlite.py b/db_sqlite.py index 2f20c91..a3620e2 100644 --- a/db_sqlite.py +++ b/db_sqlite.py @@ -79,7 +79,8 @@ def loadFromTables(): record.field("id").value(), record.field("name").value(), record.field("column").value(), - record.field("link").value())) + record.field("link").value(), + record.field("hidden").value())) # Load entries query.exec_("SELECT * FROM entries") @@ -168,3 +169,34 @@ def insertEntry(new_entry): database.close() return output + +def removeGroup(group_id): + """ + Remove a group by id from the database + (actually set hidden to true, don't permanently delete it) + """ + + database = QSqlDatabase.addDatabase("QSQLITE") # SQlite version 3 + database.setDatabaseName(Globals.db_path) + + if not database.open(): + print("Unable to open data source file.") + sys.exit(1) # Error out. TODO consider throwing a dialog instead + + query = QSqlQuery() + + # First, set entries to hidden + query.prepare(""" + UPDATE entries SET hidden = 1 WHERE parent_id = ? + """) + query.addBindValue(group_id) + query.exec_() + + # Now, set the group to hidden + query.prepare(""" + UPDATE groups SET hidden = 1 WHERE id = ? + """) + query.addBindValue(group_id) + query.exec_() + + database.close() @@ -4,11 +4,12 @@ from PyQt5.QtWidgets import QLabel, QVBoxLayout Globals = __import__("globals") class Group: - def __init__(self, id, name, column = "left", link = ""): + def __init__(self, id, name, column = "left", link = "", hidden = False): self.id = id self.name = name self.column = column self.link = link + self.hidden = hidden def buildLayout(self): output = QVBoxLayout() |