added reference adding for books
This commit is contained in:
parent
73b4c4f2e2
commit
9746e7d1f2
|
@ -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:
|
||||
|
|
Reference in New Issue