summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLouie S <louie@example.com>2023-09-16 09:36:14 -0400
committerLouie S <louie@example.com>2023-09-16 09:36:14 -0400
commit11db353ea4cac33caccb005be7d4b72671f20ad9 (patch)
tree18b89d43ff41ef823404844f09bf06aee0f4b2ed
parentf2ca02a9230621d0968b8df129051e332339b768 (diff)
removing (hiding) groups working
-rwxr-xr-xassignment-list.py5
-rw-r--r--db_sqlite.py34
-rw-r--r--group.py3
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()
diff --git a/group.py b/group.py
index 07206eb..df194b8 100644
--- a/group.py
+++ b/group.py
@@ -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()