def get_all_list_entries(self): """Alle Listeneinträge der Datenbank ausgeben :return: Liste mit Listeneinträgen """ with ListEntryMapper() as mapper: return mapper.find_all()
def create_list_entry(self, name: str, amount, article_id: int, unit: str, purchasing_user_id: int, retailer_id: int, shopping_list_id: int, is_standardarticle: bool): """Listeneintrag erstellen :param name: Name :param amount: Anzahl :param article_id: ID des Artikels :param unit: Einheit :param purchasing_user_id: ID des Einkäufers :param retailer_id: ID des Retailers :param shopping_list_id: ID der Einkaufsliste :param is_standardarticle: Information, ob es ein Standardartikel ist :return: Listeneintrag-Objekt """ shopping_list = self.get_shopping_list_by_id(shopping_list_id) self.save_shopping_list(shopping_list) list_entry = ListEntry() list_entry.set_id(0), list_entry.set_name(name), list_entry.set_purchasing_user(purchasing_user_id), list_entry.set_amount(amount), list_entry.set_article(article_id), list_entry.set_unit(unit), list_entry.set_retailer(retailer_id), list_entry.set_shopping_list(shopping_list_id) list_entry.set_standardarticle(is_standardarticle) with ListEntryMapper() as mapper: return mapper.insert(list_entry)
def get_list_entries_by_article_id(self, article_id: int): """Listeneinträge anhand der ID des Artikels ausgeben :param article_id: ID des Artikels :return: Liste mit Listeneintrag-Objekten """ with ListEntryMapper() as mapper: return mapper.find_list_entries_by_article(article_id)
def get_list_entry_by_id(self, list_entry_id: int): """Listeneintrag anhand seiner ID ausgeben :param list_entry_id: ID des Listeneintrags :return: Listeneintrag-Objekt """ with ListEntryMapper() as mapper: return mapper.find_by_id(list_entry_id)
def get_list_entries_by_retailer_id(self, retailer_id: int): """Listeneinträge anhand der ID des Retailers ausgeben :param retailer_id: ID des Retailers :return: Liste mit Listeneintrag-Objekten """ with ListEntryMapper() as mapper: return mapper.find_by_retailer(retailer_id)
def get_standardarticles_by_group_id(self, group_id: int): """Standardartikel der Gruppe anhand ihrer ID ausgeben :param group_id: ID der Gruppe :return: Liste mit Standardartikeln (Listeneinträge) """ with ListEntryMapper() as mapper: return mapper.find_standardarticles_by_group_id(group_id)
def get_list_entries_by_shopping_list_id(self, shopping_list_id: int): """Listeneinträge anhand der ID der Einkaufsliste ausgeben :param shopping_list_id: ID der Einkaufsliste :return: Liste mit Listeneintrag-Objekten """ with ListEntryMapper() as mapper: return mapper.find_list_entries_by_shopping_list_id( shopping_list_id)
def delete_standardarticle(self, list_entry: ListEntry, group: Group): """Standardartikel von einer Gruppe entfernen :param list_entry: Listeneintrag-Objekt :param group: Gruppen-Objekt :return: """ with ListEntryMapper() as mapper: mapper.delete_standardarticle(list_entry, group) mapper.delete(list_entry)
def delete_list_entry(self, list_entry: ListEntry): """Listeneintrag löschen :param list_entry: Listeneintrag-Objekt :return: """ shopping_list = self.get_shopping_list_by_id( list_entry.get_shopping_list()) self.save_shopping_list(shopping_list) with ListEntryMapper() as mapper: mapper.delete(list_entry)
def delete_article(self, article_id: int): """Artikel und zugehörige Beziehungen löschen :param article_id: :return: """ article = self.get_article_by_id(article_id) # Standardartikel löschen with ListEntryMapper() as mapper: group = self.get_group_by_id(article.get_group()) mapper.delete_standardarticle_by_group(group) # Listeneinträge mit Artikel löschen with ListEntryMapper() as mapper: mapper.delete_by_article(article) # Artikel löschen with ArticleMapper() as mapper: mapper.delete(article_id)
def get_list_entries_in_time_period(self, from_date: datetime, to_date: datetime): """Listeneinträge ausgeben, die in einem Zeitintervall gekauft (checked) wurden :param from_date: Ab-Datum :param to_date: Bis-Datum :return: Liste Mit Listeneinträgen """ with ListEntryMapper() as mapper: return mapper.find_list_entries_in_time_periode(from_date, to_date)
def save_list_entry(self, list_entry: ListEntry): """Listeneintrag aktualisieren :param list_entry: Listeneintrag-Objekt :return: Aktualisiertes Listeneintrag-Objekt """ shopping_list = self.get_shopping_list_by_id( list_entry.get_shopping_list()) self.save_shopping_list(shopping_list) list_entry.set_last_updated(datetime.now()) with ListEntryMapper() as mapper: return mapper.update(list_entry)
def delete_group(self, group: Group): """Gruppe und zugehörige Beziehungen löschen :param group: Gruppen-Objekt :return: """ # User löschen with UserGroupRelationsMapper() as mapper: mapper.delete_group_relations(group) # Standardartikel löschen with ListEntryMapper() as mapper: mapper.delete_standardarticle_by_group(group) # Shoppinglists löschen with ShoppingListMapper() as shopping_list_mapper: shopping_lists = shopping_list_mapper.find_by_group(group) # Listeineinträge anhand der ShoppingLists löschen with ListEntryMapper() as mapper: for shopping_list in shopping_lists: mapper.delete_by_shopping_list(shopping_list) shopping_list_mapper.delete_by_group(group) # Artikel löschen with ArticleMapper() as article_mapper: articles = article_mapper.find_by_group(group.get_id()) # Übrige Listeneinträge nach Artikel löschen with ListEntryMapper() as mapper: for article in articles: mapper.delete_by_article(article) article_mapper.delete_by_group(group) # Gruppe löschen with GroupMapper() as mapper: mapper.delete(group)
def delete_shopping_list(self, shopping_list: ShoppingList): """Einkaufsliste und zugehörige Beziehungen löschen :param shopping_list: Einkaufslisten-Objekt :return: """ with ListEntryMapper() as mapper: group = self.get_group_by_id(shopping_list.get_group()) mapper.delete_standardarticle_by_group(group) mapper.delete_by_shopping_list(shopping_list) with ShoppingListMapper() as mapper: mapper.delete(shopping_list)
def get_list_entries_by_user_id(self, user_id: int, include_archived=False): """Listeneinträge eines Users anhand seiner ID ausgeben :param user_id: ID des Users :param include_archived: Angabe, ob Archiv auch abgefragt wird :return: Liste mit Listeneinträgen """ shopping_lists = [] if include_archived == False: shopping_lists = self.get_all_archived_shopping_lists() with ListEntryMapper() as mapper: return mapper.find_by_purchasing_user(user_id, shopping_lists)
def get_list_entries_by_group(self, group: Group, include_archived=False): """Alle Listeneinträge einer Gruppe ausgeben :param group: Gruppen-Objekt :return: Liste mit Listeneinträgen """ with ShoppingListMapper() as mapper: shopping_lists = mapper.find_by_group(group, include_archived) list_entries = [] for shopping_list in shopping_lists: with ListEntryMapper() as mapper: list_entries += mapper.find_list_entries_by_shopping_list_id( shopping_list) return list_entries
def delete_user(self, user): """User löschen :param user: User-Objekt :return: """ with UserGroupRelationsMapper() as mapper: mapper.delete_user_relations(user) with ListEntryMapper() as mapper: mapper.delete_purchasing_user(user) with GroupMapper() as mapper: mapper.delete_owner(user) with UserMapper() as mapper: mapper.delete(user)
def add_standardarticle_to_group(self, list_entry: ListEntry, group: Group): """Standardartikel zur Gruppe hinzufügen :param list_entry: Listeneintrag-Objekt :param group: Gruppen-Objekt :return: """ with ListEntryMapper() as mapper: list_entry.set_id(0) list_entry.set_standardarticle(True) list_entry.set_purchasing_user(None) list_entry.set_shopping_list(None) list_entry.set_checked(False) standardarticle = mapper.insert(list_entry) mapper.insert_standardarticle(standardarticle, group)
def add_standardarticle_to_shopping_list(self, group: Group, shopping_list: ShoppingList): """Alle Standardartikel einer Gruppe zu einer Einkaufsliste hinzufügen :param group: Gruppen-Objekt :param shopping_list: Einkaufslisten-Objekt :return: """ with ListEntryMapper() as mapper: standardarticles = mapper.find_standardarticles_by_group_id( group.get_id()) for standardarticle in standardarticles: standardarticle.set_id(0) standardarticle.set_shopping_list(shopping_list.get_id()) mapper.insert(standardarticle)
def remove_member_from_group(self, group: Group, user: User): """User von einer Gruppe entfernen und allen zugehörigen Beziehungen lösen :param group: Gruppen-Objekt :param user: User-Objekt :return: """ with GroupMapper() as mapper: mapper.delete_owner(user, group) with ShoppingListMapper() as mapper: shopping_lists = mapper.find_by_group(group) with ListEntryMapper() as mapper: for shopping_list in shopping_lists: mapper.delete_purchasing_user(user, shopping_list) with UserGroupRelationsMapper() as mapper: mapper.remove_user_from_group(group, user)