Fixed session retrieving.

This commit is contained in:
Alexis Lahouze 2013-01-25 12:53:49 +01:00
parent 26cf3610fe
commit 688755c542
2 changed files with 9 additions and 9 deletions

View File

@ -14,7 +14,7 @@ def get_accounts():
""" """
Returns accounts with their solds. Returns accounts with their solds.
""" """
session = db.create_scoped_session() session = db.session
query = session.query( query = session.query(
Account.id.label("id"), Account.id.label("id"),
@ -36,7 +36,7 @@ def get_accounts():
@app.route("/api/accounts/<account_id>/months") @app.route("/api/accounts/<account_id>/months")
def get_months(account_id): def get_months(account_id):
session = db.create_scoped_session() session = db.session
query = session.query( query = session.query(
distinct(extract("year", Entry.value_date)).label("year"), distinct(extract("year", Entry.value_date)).label("year"),
@ -50,7 +50,7 @@ def get_months(account_id):
@app.route("/api/accounts", methods=["PUT"]) @app.route("/api/accounts", methods=["PUT"])
def add_account(): def add_account():
session = db.create_scoped_session() session = db.session
try: try:
account = Account(request.json['name'], request.json['authorized_overdraft']) account = Account(request.json['name'], request.json['authorized_overdraft'])
@ -66,7 +66,7 @@ def add_account():
@app.route("/api/accounts/<account_id>", methods=["PUT"]) @app.route("/api/accounts/<account_id>", methods=["PUT"])
def update_account(account_id): def update_account(account_id):
session = db.create_scoped_session() session = db.session
try: try:
account = session.query(Account).filter(Account.id == account_id).first() account = session.query(Account).filter(Account.id == account_id).first()
@ -84,7 +84,7 @@ def update_account(account_id):
@app.route("/api/accounts/<account_id>", methods=["DELETE"]) @app.route("/api/accounts/<account_id>", methods=["DELETE"])
def delete_account(account_id): def delete_account(account_id):
session = db.create_scoped_session() session = db.session
try: try:
account = session.query(Account).filter(Account.id == account_id).first() account = session.query(Account).filter(Account.id == account_id).first()

View File

@ -17,7 +17,7 @@ def get_entries(account_id, year, month):
""" """
Return entries for an account, year, and month. Return entries for an account, year, and month.
""" """
session = db.create_scoped_session() session = db.session
query = session.query( query = session.query(
Entry Entry
@ -46,7 +46,7 @@ def get_entries(account_id, year, month):
@app.route("/api/entries", methods=["PUT"]) @app.route("/api/entries", methods=["PUT"])
def add_entry(): def add_entry():
session = db.create_scoped_session() session = db.session
try: try:
entry = Entry( entry = Entry(
@ -68,7 +68,7 @@ def add_entry():
@app.route("/api/entries/<entry_id>", methods=["PUT"]) @app.route("/api/entries/<entry_id>", methods=["PUT"])
def update_entry(entry_id): def update_entry(entry_id):
session = db.create_scoped_session() session = db.session
try: try:
entry = session.query(Entry).filter(Entry.id == entry_id).first() entry = session.query(Entry).filter(Entry.id == entry_id).first()
@ -91,7 +91,7 @@ def update_entry(entry_id):
@app.route("/api/entries/<entry_id>", methods=["DELETE"]) @app.route("/api/entries/<entry_id>", methods=["DELETE"])
def delete_entry(entry_id): def delete_entry(entry_id):
session = db.create_scoped_session() session = db.session
try: try:
entry = session.query(Entry).filter(Entry.id == entry_id).first() entry = session.query(Entry).filter(Entry.id == entry_id).first()