diff options
author | Louie S <louie@example.com> | 2023-09-16 09:36:14 -0400 |
---|---|---|
committer | Louie S <louie@example.com> | 2023-09-16 09:36:14 -0400 |
commit | 7b680d73f75dfc0f0c057e948994159ed055073a (patch) | |
tree | c8b0ec1bb61f7be97cef715681d6343fee872743 | |
parent | 11db353ea4cac33caccb005be7d4b72671f20ad9 (diff) |
Edit/update group information
-rw-r--r-- | db_sqlite.py | 24 | ||||
-rw-r--r-- | edit_group_form.py | 10 |
2 files changed, 33 insertions, 1 deletions
diff --git a/db_sqlite.py b/db_sqlite.py index a3620e2..deef984 100644 --- a/db_sqlite.py +++ b/db_sqlite.py @@ -170,6 +170,30 @@ def insertEntry(new_entry): return output +def updateGroup(group): + """ + Update group by group_id + """ + 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() + + query.prepare(""" + UPDATE groups SET name = ?, column = ?, link = ? WHERE id = ? + """) + query.addBindValue(group.name) + query.addBindValue(group.column) + query.addBindValue(group.link) + query.addBindValue(group.id) + query.exec_() + + database.close() + def removeGroup(group_id): """ Remove a group by id from the database diff --git a/edit_group_form.py b/edit_group_form.py index d5df4c8..aba5559 100644 --- a/edit_group_form.py +++ b/edit_group_form.py @@ -5,6 +5,7 @@ from PyQt5.QtCore import Qt from add_entry_form import Globals from group import Group +DB = __import__("db_sqlite") class editGroupForm(QDialog): """ @@ -70,7 +71,14 @@ class editGroupForm(QDialog): QMessageBox.Close) return - # TODO do the database stuff (this will allow us to get the id) + # Update DB + group = list(filter(lambda g: g.id == self.id, Globals.groups))[0] + group.name = name_text + group.column = column_text + group.link = link_text + DB.updateGroup(group) + + # Update global variables Globals.groups = list(filter(lambda g: g.id != self.id, Globals.groups)) Globals.groups.append(Group(self.id, name_text, column_text, link_text)) self.close() |