コード例 #1
0
ファイル: views.py プロジェクト: pdwerryhouse/spinedemo
def get_countries(request):
    session = DBSession()

    countries = session.query(Country).order_by(Country.name)
    entries = []
    for country in countries:
        entry = { }
        entry['id'] = country.id    
        entry['name'] = country.name
        entries.append(entry)

    return entries
コード例 #2
0
ファイル: views.py プロジェクト: pdwerryhouse/spinedemo
def get_persons(request):
    session = DBSession()

    persons = session.query(Person).order_by(Person.firstname)
    entries = []
    for person in persons:
        entry = { }
        entry['id'] = person.id    
        entry['firstname'] = person.firstname
        entry['surname'] = person.surname
        entry['country_id'] = person.country_id
        entries.append(entry)

    return entries
コード例 #3
0
ファイル: views.py プロジェクト: pdwerryhouse/spinedemo
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 { }
コード例 #4
0
ファイル: views.py プロジェクト: pdwerryhouse/spinedemo
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 { }