Example #1
0
def update_country(request):
    session = DBSession()

    id = request.json_body['id']

    country = session.query(Country).get(id)
    country.name = request.json_body['name']

    session.add(country)
    session.flush()
    try:
        transaction.commit()
    except IntegrityError:
        transaction.abort()

    return { }
Example #2
0
def create_country(request):
    session = DBSession()

    country = Country()
    country.name = request.json_body['name']

    session.add(country)
    session.flush()
    newid = country.id;

    try:
        transaction.commit()
    except IntegrityError:
        transaction.abort()

    return { "id": newid }
Example #3
0
def create_person(request):
    session = DBSession()

    person = Person()
    person.firstname = request.json_body['firstname']
    person.surname = request.json_body['surname']
    person.country_id = request.json_body['country_id']

    session.add(person)
    session.flush()
    newid = person.id;

    try:
        transaction.commit()
    except IntegrityError:
        transaction.abort()

    return { "id": newid }
Example #4
0
def update_person(request):
    session = DBSession()

    id = request.json_body['id']

    person = session.query(Person).get(id)
    person.firstname = request.json_body['firstname']
    person.surname = request.json_body['surname']
    person.country_id = request.json_body['country_id']

    session.add(person)
    session.add(country)
    session.flush()
    try:
        transaction.commit()
    except IntegrityError:
        transaction.abort()

    return { }