[billreminder] Make the add/edit db call more robust and trully do the right thing.
- From: Og B. Maciel <ogmaciel src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [billreminder] Make the add/edit db call more robust and trully do the right thing.
- Date: Fri, 20 Nov 2009 17:02:56 +0000 (UTC)
commit 06c5112cf016491de087f6afc4faf2b48b7a3348
Author: Og B. Maciel <ogmaciel gnome org>
Date: Fri Nov 20 12:00:01 2009 -0500
Make the add/edit db call more robust and trully do the right thing.
src/lib/dal.py | 17 ++++++++++-------
1 files changed, 10 insertions(+), 7 deletions(-)
---
diff --git a/src/lib/dal.py b/src/lib/dal.py
index a320933..9d90e19 100644
--- a/src/lib/dal.py
+++ b/src/lib/dal.py
@@ -4,9 +4,9 @@ import os
import sys
try:
- from sqlalchemy.orm import sessionmaker, eagerload
from sqlalchemy import create_engine
- from sqlalchemy.orm import sessionmaker
+ from sqlalchemy.orm import sessionmaker, eagerload
+ from sqlalchemy.orm.exc import NoResultFound
except ImportError:
print "Please install SQLAlchemy!"
raise SystemExit
@@ -44,7 +44,7 @@ class DAL(object):
bill.dueDate = dbobject.dueDate
bill.notes = dbobject.notes
bill.paid = dbobject.paid
- if dbobject.category and bill.category[0].name != dbobject.category[0].name:
+ if dbobject.category:
bill.category = []
try:
category = session.query(Category).filter_by(name=dbobject.category[0].name).one()
@@ -52,12 +52,14 @@ class DAL(object):
except Exception, e:
print "Failed to retrieve category \"%s\" for bill \"%s\": %s" \
% (dbobject.name, dbobject.category[0].name, str(e))
- else:
- session.add(dbobject)
if session.dirty:
session.commit()
+ except NoResultFound, e:
+ session.add(dbobject)
+ session.commit()
+
except Exception, e:
session.rollback()
print str(e)
@@ -70,12 +72,13 @@ class DAL(object):
if category:
category.name = dbobject.name
category.color = dbobject.color
- else:
- session.add(dbobject)
if session.dirty:
session.commit()
+ except NoResultFound, e:
+ session.add(dbobject)
+ session.commit()
except Exception, e:
session.rollback()
print str(e)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]