summaryrefslogtreecommitdiffstats
path: root/tabellio
diff options
context:
space:
mode:
authorFrédéric Péters <fpeters@entrouvert.com>2011-11-08 11:48:22 (GMT)
committerFrédéric Péters <fpeters@entrouvert.com>2011-11-08 11:48:22 (GMT)
commit4bc0e196cc230dbefa43544c78aa4cbc890e0c95 (patch)
tree0b036a57184282600bf6188492558e4669a0e58b /tabellio
parent8b6cfe673668edb15a19ff843440b050fcaecea5 (diff)
downloadtabellio.pcfdb-4bc0e196cc230dbefa43544c78aa4cbc890e0c95.zip
tabellio.pcfdb-4bc0e196cc230dbefa43544c78aa4cbc890e0c95.tar.gz
tabellio.pcfdb-4bc0e196cc230dbefa43544c78aa4cbc890e0c95.tar.bz2
add synchronisation of commission events (#854)
Diffstat (limited to 'tabellio')
-rw-r--r--tabellio/pcfdb/sync.py115
1 files changed, 80 insertions, 35 deletions
diff --git a/tabellio/pcfdb/sync.py b/tabellio/pcfdb/sync.py
index c56834e..cb4586a 100644
--- a/tabellio/pcfdb/sync.py
+++ b/tabellio/pcfdb/sync.py
@@ -211,13 +211,12 @@ class SyncFromPcfDbView(BrowserView):
self.intids.register(obj)
return obj, self.intids.getId(obj)
-
- _commission_intids = None
- def get_commission_intid(self, com_id):
- if not self._commission_intids:
- self._commission_intids = {}
- if com_id in self._commission_intids:
- return self._commission_intids.get(com_id)
+ _commissions = None
+ def get_commission(self, com_id):
+ if not self._commissions:
+ self._commissions = {}
+ if com_id in self._commissions:
+ return self._commissions.get(com_id)
cursor = self.db_connection.cursor()
cursor.execute('''SELECT t_comcat.nom, code
FROM t_com JOIN t_comcat
@@ -233,6 +232,16 @@ class SyncFromPcfDbView(BrowserView):
folder = getattr(self.commissions_folder, cat_id)
code_id = self.plone_utils.normalizeString(code)
obj = getattr(folder, code_id)
+ self._commissions[com_id] = obj
+ return obj
+
+ _commission_intids = None
+ def get_commission_intid(self, com_id):
+ if not self._commission_intids:
+ self._commission_intids = {}
+ if com_id in self._commission_intids:
+ return self._commission_intids.get(com_id)
+ obj = self.get_commission(com_id)
try:
intid = self.intids.getId(obj)
except KeyError:
@@ -563,6 +572,7 @@ class SyncFromPcfDbView(BrowserView):
object = getattr(commission_folder, com_code)
object.title = title
object.active == (state == 'S_ACTIVE')
+ object.code = code
pers_cursor = self.db_connection.cursor()
pers_cursor.execute('''SELECT t_pershistoline.type, nom, prenom
@@ -894,7 +904,8 @@ class SyncFromPcfDbView(BrowserView):
if timestamp:
where_ts = cursor.mogrify('t_reunion.ts > %s', (timestamp,))
cursor.execute('''SELECT id, type, comid, sess, lieu, datedeb, heuredeb, datefin, heurefin,
- nobtr, nobtrcom, nocri, nocric, nocricom
+ nobtr, nobtrcom, nocri, nocric, nocricom,
+ debreel, finreel
FROM t_reunion
WHERE
%s''' % where_ts)
@@ -903,7 +914,6 @@ class SyncFromPcfDbView(BrowserView):
formatter = locales.getLocale('fr').dates.getFormatter('dateTime', 'medium')
formatter.setPattern(u'd MMMM yyyy à HH:mm')
- type_info = self.portal_types.getTypeInfo('tabellio.agenda.parlevent')
count = 0
while True:
row = cursor.fetchone()
@@ -911,27 +921,46 @@ class SyncFromPcfDbView(BrowserView):
break
count += 1
reu_id, type, comid, sess, lieu, datedeb, heuredeb, datefin, \
- heurefin, notr, nobtrcom, nocri, nocric, nocricom = row
+ heurefin, notr, nobtrcom, nocri, nocric, nocricom, \
+ debreel, finreel = row
- if type == 'CO':
- # XXX: skip commission events for now
- continue
+ commission = None
+ if comid:
+ commission = self.get_commission(comid)
- new_one = False
- if not hasattr(self.parlevents_folder, reu_id):
- type_info._constructInstance(self.parlevents_folder, reu_id)
- new_one = True
- object = getattr(self.parlevents_folder, reu_id)
- object.place = lieu
- object.session = sess
if datedeb:
if heuredeb:
- object.start = datetime.datetime.strptime(
+ start = datetime.datetime.strptime(
'%s %s' % (datedeb, heuredeb),
'%Y-%m-%d %H:%M:%S')
else:
- object.start = datetime.datetime.strptime(
+ start = datetime.datetime.strptime(
'%s' % datedeb, '%Y-%m-%d')
+
+ title = None
+ if type == 'SE':
+ title = u'Séance du %s' % formatter.format(start)
+ elif type == 'CP':
+ title = u'Commission plénière du %s' % formatter.format(start)
+ elif type == 'CO':
+ if not comid:
+ title = u'Commission du %s' % formatter.format(start)
+ else:
+ title = u'%s du %s' % (commission.title,
+ formatter.format(start))
+
+ if not hasattr(self.parlevents_folder, reu_id):
+ self.parlevents_folder.invokeFactory('tabellio.agenda.parlevent',
+ reu_id, title=title)
+ object = getattr(self.parlevents_folder, reu_id)
+ if not (debreel and object.title):
+ # do not set the title if it was already set and the real
+ # beginning time has been set, to keep titles with nice at
+ # the hour times.
+ object.title = title
+ object.place = lieu
+ object.session = sess
+ object.start = start
if datefin:
if heurefin:
object.end = datetime.datetime.strptime(
@@ -943,20 +972,36 @@ class SyncFromPcfDbView(BrowserView):
if object.end < object.start:
object.end = object.start
- # XXX: other attributes
-
- if type == 'SE':
- object.title = u'Séance du %s' % formatter.format(object.start)
- elif type == 'CP':
- object.title = u'Commission plénière du %s' % formatter.format(object.start)
- elif type == 'CO':
- pass # TODO: get commission name in title
-
- if new_one:
- self.intids.register(object)
- notify(ObjectAddedEvent(object))
+ if comid:
+ comid_int = self.get_commission_intid(comid)
+ if comid_int:
+ object.commission = RelationValue(comid_int)
else:
- notify(ObjectModifiedEvent(object))
+ object.commission = None
+
+ if (nocri or nocric or nocricom):
+ if nocri:
+ doctype = 'CRI'
+ docno = nocri
+ elif nocric:
+ doctype = 'CRICOM'
+ docno = '%s-%s%s' % (nocric, commission.code, nocricom)
+ doc_cursor = self.db_connection.cursor()
+ doc_cursor.execute(doc_cursor.mogrify('''SELECT id, sess
+ FROM t_document
+ WHERE sess = %s
+ AND type = %s
+ AND no = %s''', (sess, doctype, docno)))
+ row = doc_cursor.fetchone()
+ doc_cursor.close()
+ if row is None:
+ print 'failed to get document', sess, doctype, docno
+ else:
+ doc_id, docsess = row
+ doc, doc_intid = self.get_document_and_intid(doc_id)
+ object.cri = RelationValue(doc_intid)
+
+ notify(ObjectModifiedEvent(object))
self.publish(object)
cursor.close()