예제 #1
0
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))
예제 #2
0
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))
예제 #3
0
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))
예제 #4
0
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))
예제 #5
0
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))
예제 #6
0
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))
예제 #7
0
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))
예제 #8
0
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))
예제 #9
0
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))