Projects/worblehat-old
Projects
/
worblehat-old
Archived
12
0
Fork 0

added reference adding for books

This commit is contained in:
Péter Henrik Gombos 2011-10-09 15:36:08 +00:00
parent 73b4c4f2e2
commit 9746e7d1f2
1 changed files with 20 additions and 0 deletions

View File

@ -83,6 +83,9 @@ q_edit_category = \
'UPDATE category ' \ 'UPDATE category ' \
'SET name=%(name)s ' \ 'SET name=%(name)s ' \
'WHERE id=%(id)s' 'WHERE id=%(id)s'
q_add_bookreference = \
'INSERT INTO bookreference (book, reftype, value) ' \
'VALUES (%(isbn)s, %(reftype)s, %(value))'
def connect_to_db(): def connect_to_db():
connection = pgdb.connect(database='oysteini_pbb2', connection = pgdb.connect(database='oysteini_pbb2',
@ -308,6 +311,23 @@ def do_action(connection, action):
{'isbn': action['isbn'], {'isbn': action['isbn'],
'person_id': person, 'person_id': person,
'relation': relation}) '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): def commit_actions(connection, actions):
for action in actions: for action in actions: