def add(self) -> int: """ Dodawanie nowych użytkowników do bazy """ first_name = FirstName().get_or_create(name=input('Podaj imię: '))[ 0] # zwracana tupla, pierwszy element zawiera imie last_name = LastName().get_or_create(name=input('Podaj nazwisko: '))[0] first_name.save() last_name.save() client = LibraryClient(first_name=first_name, last_name=last_name) client.save() return client.id
def add(self) -> int: """ Dodawanie nowych użytkowników do bazy. """ print('Dodawanie nowego użytkownika') first_name = FirstName().get_or_create(name=input('Podaj imię: '))[0] last_name = LastName().get_or_create(name=input('Podaj nazwisko: '))[0] first_name.save() last_name.save() client = LibraryClient(first_name=first_name, last_name=last_name) client.save() return client.id
def find_book(search_param): def where(result, first_name, last_name): if first_name: return result.where((Book.title == search_param) | (Author.first_name == first_name)) if last_name: return result.where((Book.title == search_param) | (Author.last_name == last_name)) return result.where((Book.title == search_param) | (Book.id == int(search_param))) BookAuthor = Book.authors.get_through_model() # 1. zapytanie o nazwisko try: last_name = LastName.get(LastName.name == search_param) except LastName.DoesNotExist: last_name = None # 2. zapytanie o imię try: first_name = FirstName.get(FirstName.name == search_param) except FirstName.DoesNotExist: first_name = None # 3. zapytanie o książkę o tytule lub autorze result = Book.select().join(BookAuthor, JOIN.LEFT_OUTER).join(Author, JOIN.LEFT_OUTER) result = where(result, first_name, last_name) return result
def find(self) -> LibraryClient: print('Znajdź użytkownika') username = input(' imię i nazwisko: ') first_name, last_name = username.split(' ') user = LibraryClient().get_or_create( first_name=FirstName().get_or_create(name=first_name)[0], last_name=LastName().get_or_create(name=last_name)[0])[0] return user
def get(self): email = input(" email: ") phone = input(" phone: ") first_name = input(" first name: ") last_name = input(" last name: ") first_name = FirstName.get_or_create(name=first_name)[0] last_name = LastName.get_or_create(name=last_name)[0] User.create(email=email, phone=phone, first_name=first_name, last_name=last_name)
def add_authors(self, authors: List[str]) -> List[Author] or None: # List wymusza na nas typowanie result = [] for author_name in authors: try: first_name, last_name= author_name.split(' ') except ValueError: first_name, last_name = author_name, None author = Author().get_or_create( first_name = FirstName().get_or_create(name=first_name)[0], last_name = LastName().get_or_create(name=last_name)[0] if last_name else None )[0] result.append(author) return result
def add_authors(self, authors: List[str]) -> List[Author]: """Dodawanie nowych autorów.""" result = [] for author_name in authors: try: first_name, last_name = author_name.split(' ') except ValueError: first_name, last_name = author_name, None author = Author().get_or_create( first_name=FirstName().get_or_create(name=first_name)[0], last_name=LastName().get_or_create(name=last_name)[0] if last_name else None )[0] result.append(author) return result
def find_user(search_param): # 1. zapytanie o nazwisko try: last_name = LastName.get(LastName.name == search_param) return User.select().where(User.last_name == last_name) except LastName.DoesNotExist: pass # 2. zapytanie o imię try: first_name = FirstName.get(FirstName.name == search_param) return User.select().where(User.first_name == first_name) except FirstName.DoesNotExist: pass return User.select().where( (User.email == search_param) | (User.card_number == search_param) | (User.phone == search_param) )