diff --git a/DataSources/dataSources.py b/DataSources/dataSources.py index 3ff5d25..3a5a436 100644 --- a/DataSources/dataSources.py +++ b/DataSources/dataSources.py @@ -124,6 +124,12 @@ def Save(self, obj: IModel | GroupContacts): session.refresh(obj) self.dbEngineInstance.dispose() + def DeleteEntry(self, obj: IModel | GroupContacts): + Session = orm.sessionmaker(bind=self.dbEngineInstance) + with Session() as session: + session.delete(obj) + session.commit() + class XLSXHandler(IDataSource): def __init__(self, path: str) -> None: self.file_path = path diff --git a/group_controller.py b/group_controller.py index 28f00bb..9749a12 100644 --- a/group_controller.py +++ b/group_controller.py @@ -13,8 +13,13 @@ def add_contact(cls, g: Group, c: Contact) -> None: if g._add_contact(c): gc = GroupContacts(group_id=g.id, contact_id=c.email) cls.dbh.Save(gc) - - # TODO delete contact binding? + + @classmethod + def delete_connection(cls, g: Group, c: Contact) -> None: + connections :list[GroupContacts] = cls.dbh.GetData(GroupContacts, group_id=g.id, contact_id=c.email) + for con in connections: + cls.dbh.DeleteEntry(con) + del con @classmethod def get_contacts(cls, g: Group) -> list[Contact]: diff --git a/interface.py b/interface.py index 6735945..40efef1 100644 --- a/interface.py +++ b/interface.py @@ -481,8 +481,10 @@ def prepareInterface(self): def update(self): if self.currentGroup: self.title(f"Edytuj grupÄ™ {self.currentGroup.name}") - self.name_entry.insert(INSERT, self.currentGroup.name) + self.name_entry.delete(0, END) + self.name_entry.insert(0, self.currentGroup.name) self.currentGroup.contacts = GroupController.get_contacts(self.currentGroup) + self.email_text.delete('1.0', END) # Clear current content [self.add_contact(c) for c in self.currentGroup.contacts] else: self.title("Dodaj grupÄ™") @@ -594,8 +596,9 @@ def add_contact_to_group(self, c: Contact): pass def remove_contact_from_group(self, c: Contact): - # TODO usuwanie kontaktu z okienka grup odznaczajac chekboxa - pass + GroupController.delete_connection(self.group, c) + if isinstance(self.parent, GroupEditor): + self.parent.update() def search_contact(self): search_criteria = self.search_entry.get().strip()