diff --git a/tabellio/pcfdb/sync.py b/tabellio/pcfdb/sync.py index b05b27d..0334de2 100644 --- a/tabellio/pcfdb/sync.py +++ b/tabellio/pcfdb/sync.py @@ -938,6 +938,44 @@ class SyncFromPcfDbView(BrowserView): notify(ObjectModifiedEvent(object)) self.publish(object) + if doctype in ('CRI', 'CRICOM'): + # we eventually have a meeting to update + meeting_cursor = self.db_connection.cursor() + if doctype == 'CRICOM': + nocric = object.no.split('-')[0] + try: + nocric, com_code, nocricom = re.match(r'(\d+)-(.*)(\d+)', object.no).groups() + except AttributeError: + # make sure we do not get anything afterwards + nocric, com_code, nocricom = '999', 'XXX', '999' + meeting_query = meeting_cursor.mogrify( + '''SELECT t_reunion.id FROM t_reunion + LEFT JOIN t_com ON (t_reunion.comid = t_com.id) + WHERE t_reunion.sess = %s + AND t_reunion.type = 'CO' + AND nocric = %s + AND nocricom = %s + AND t_com.code = %s''', + (sess, nocric, nocricom, com_code)) + else: + meeting_query = meeting_cursor.mogrify( + '''SELECT t_reunion.id FROM t_reunion + WHERE sess = %s + AND type = 'SE' + AND nocri = %s''', + (sess, object.no)) + meeting_cursor.execute(meeting_query) + row = meeting_cursor.fetchone() + if row: + meeting_id = row[0] + print ' going to update meeting:', meeting_id + if hasattr(self.parlevents_folder, meeting_id): + meeting = getattr(self.parlevents_folder, meeting_id) + if meeting.cri is None: + doc_intid = self.intids.getId(object) + meeting.cri = RelationValue(doc_intid) + meeting_cursor.close() + if count % 100 == 0: transaction.commit()