Skip to content

Commit

Permalink
Added Contact-Group deletion in ContactList and database
Browse files Browse the repository at this point in the history
  • Loading branch information
ikarmus2001 committed May 9, 2024
1 parent b29c269 commit cc5ab8d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
6 changes: 6 additions & 0 deletions DataSources/dataSources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions group_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
9 changes: 6 additions & 3 deletions interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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ę")
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit cc5ab8d

Please sign in to comment.