Exemplo n.º 1
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))
Exemplo n.º 2
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))
Exemplo n.º 3
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))
Exemplo n.º 4
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))
Exemplo n.º 5
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))
Exemplo n.º 6
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))
Exemplo n.º 7
0
def get():
    result_set = Session().query(AddressBook) \
        .all()

    return render_template('addressBooks.html',
                           address_books=result_set,
                           static_path='')
Exemplo n.º 8
0
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='../../../../')
Exemplo n.º 9
0
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='')
Exemplo n.º 10
0
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='../../')
Exemplo n.º 11
0
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='../../../../')
Exemplo n.º 12
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))
Exemplo n.º 13
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))
Exemplo n.º 14
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))
Exemplo n.º 15
0
def get():
    return ResponseUtil.parse_collection(Session().query(AddressBook).all())
Exemplo n.º 16
0
def get(address_book_id):
    return ResponseUtil.parse_collection(
        Session().query(Contact).join(AddressBook).filter(
            AddressBook.id == address_book_id).all())
Exemplo n.º 17
0
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)
Exemplo n.º 18
0
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())
Exemplo n.º 19
0
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())
Exemplo n.º 20
0
def get_address_book_by_id(id):
    return ResponseUtil.parse(
        Session().query(AddressBook).filter(AddressBook.id == id).first())