From 9746e7d1f2259b2cc3edaaaad8faaccc3e448bf8 Mon Sep 17 00:00:00 2001 From: gombos Date: Sun, 9 Oct 2011 15:36:08 +0000 Subject: [PATCH] added reference adding for books --- cli/worblehat.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/cli/worblehat.py b/cli/worblehat.py index 305eaff..3283441 100755 --- a/cli/worblehat.py +++ b/cli/worblehat.py @@ -83,6 +83,9 @@ q_edit_category = \ 'UPDATE category ' \ 'SET name=%(name)s ' \ 'WHERE id=%(id)s' +q_add_bookreference = \ + 'INSERT INTO bookreference (book, reftype, value) ' \ + 'VALUES (%(isbn)s, %(reftype)s, %(value))' def connect_to_db(): connection = pgdb.connect(database='oysteini_pbb2', @@ -308,6 +311,23 @@ def do_action(connection, action): {'isbn': action['isbn'], 'person_id': person, 'relation': relation}) + if action['references']: + c.execute('SELECT referencetype.id FROM referencetype') + refs = c.fetchone() + for (reftype, reflist) in action['references'].items(): + for ref in reflist: + if ref in refs: + c.execute(q_add_reference, + {'isbn': action['isbn'], + 'reftype': reftype, + 'value': ref}) + else: + raise WorblehatException('%s is not in the defined references, please use a more general one' % reftype) + +class WorblehatException(Exception): + def __init__(self, msg): + Exception.__init__(self, msg) + def commit_actions(connection, actions): for action in actions: