def update_telephone_by_id(address_book_id, contact_id, telephone_id): session = Session() telephone = session.query(Telephone) \ .filter(Telephone.id == telephone_id) \ .first() telephone.number = request.form.get('number') session.commit() return redirect('/addressBooks/{}/contacts/{}'.format(address_book_id, contact_id))
def update_address_by_id(address_book_id, contact_id, address_id): session = Session() address = session.query(Address) \ .filter(Address.id == address_id) \ .first() address.name = request.form.get('name') session.commit() return redirect('/addressBooks/{}/contacts/{}'.format( address_book_id, contact_id))
def update_contact_by_id(address_book_id, id): session = Session() contact = session.query(Contact) \ .join(AddressBook) \ .filter(AddressBook.id == address_book_id) \ .filter(Contact.id == id) \ .first() contact.name = request.form.get('name') contact.birthday = datetime.strptime(request.form.get('birthday'), '%Y-%m-%d').date() session.commit() return redirect('/addressBooks/{}'.format(address_book_id))
def add_address(address_book_id, contact_id): session = Session() contact = session.query(Contact) \ .filter(Contact.id == contact_id) \ .first() address = Address(request.form.get('name'), AddressType.HOME) contact.addresses.append(address) session.commit() return redirect('/addressBooks/{}/contacts/{}'.format( address_book_id, contact_id))
def add_contact(address_book_id): session = Session() address_book = session.query(AddressBook) \ .filter(AddressBook.id == address_book_id) \ .first() contact = Contact( request.form.get('name'), datetime.strptime(request.form.get('birthday'), '%Y-%m-%d').date() ) address_book.contacts.append(contact) session.commit() return redirect('/addressBooks/{}'.format(address_book_id))
def add_telephone(address_book_id, contact_id): session = Session() contact = session.query(Contact) \ .filter(Contact.id == contact_id) \ .first() telephone = Telephone( request.form.get('number'), TelephoneType.LANDLINE ) contact.telephones.append(telephone) session.commit() return redirect('/addressBooks/{}/contacts/{}'.format(address_book_id, contact_id))
def get(): result_set = Session().query(AddressBook) \ .all() return render_template('addressBooks.html', address_books=result_set, static_path='')
def get_telephone_by_id(address_book_id, contact_id, telephone_id): telephone = Session().query(Telephone) \ .filter(Telephone.id == telephone_id) \ .first() return render_template('telephoneById.html', address_book_id=address_book_id, contact_id=contact_id, telephone=telephone, static_path='../../../../')
def get_address_book_by_id(id): result_set = Session().query(AddressBook) \ .filter(AddressBook.id == id) \ .first() return render_template('addressBookById.html', address_book=result_set, static_path='')
def get_contact_by_id(address_book_id, id): result_set = Session().query(Contact) \ .join(AddressBook) \ .filter(AddressBook.id == address_book_id) \ .filter(Contact.id == id) \ .first() return render_template('contactById.html', contact=result_set, static_path='../../')
def get_address_by_id(address_book_id, contact_id, address_id): address = Session().query(Address) \ .filter(Address.id == address_id) \ .first() return render_template('addressById.html', address_book_id=address_book_id, contact_id=contact_id, address=address, static_path='../../../../')
def delete_telephone_by_id(address_book_id, contact_id, telephone_id): session = Session() telephone = session.query(Telephone) \ .filter(Telephone.id == telephone_id) \ .first() session.delete(telephone) session.commit() return redirect('/addressBooks/{}/contacts/{}'.format(address_book_id, contact_id))
def delete_address_by_id(address_book_id, contact_id, address_id): session = Session() address = session.query(Address) \ .filter(Address.id == address_id) \ .first() session.delete(address) session.commit() return redirect('/addressBooks/{}/contacts/{}'.format( address_book_id, contact_id))
def delete_contact_by_id(address_book_id, id): session = Session() contact = session.query(Contact) \ .join(AddressBook) \ .filter(AddressBook.id == address_book_id) \ .filter(Contact.id == id) \ .first() session.delete(contact) session.commit() return redirect('/addressBooks/{}'.format(address_book_id))
def get(): return ResponseUtil.parse_collection(Session().query(AddressBook).all())
def get(address_book_id): return ResponseUtil.parse_collection( Session().query(Contact).join(AddressBook).filter( AddressBook.id == address_book_id).all())
def get_contact_by_id(address_book_id, id): return ResponseUtil.parse( Session().query(Contact).join(AddressBook).filter( AddressBook.id == address_book_id).filter( Contact.id == id).first(), True)
def get_contacts_by_name(address_book_id, name): return ResponseUtil.parse_collection( Session().query(Contact).join(AddressBook).filter( AddressBook.id == address_book_id).filter( Contact.name.like('%' + name + '%')).all())
def get_contacts_by_birthday_day(address_book_id, day): return ResponseUtil.parse_collection( Session().query(Contact).join(AddressBook).filter( AddressBook.id == address_book_id).filter( extract('day', Contact.birthday) == day).all())
def get_address_book_by_id(id): return ResponseUtil.parse( Session().query(AddressBook).filter(AddressBook.id == id).first())