summaryrefslogtreecommitdiffstats
path: root/tabellio
diff options
context:
space:
mode:
authorFrédéric Péters <fpeters@entrouvert.com>2011-11-03 13:07:44 (GMT)
committerFrédéric Péters <fpeters@entrouvert.com>2011-11-03 13:07:44 (GMT)
commit3cea0cf17b74f0b81af22c8b7fe82faae43f93e8 (patch)
treec2df0131beb4b00d99e1e8ac3c62914208698bc9 /tabellio
parent54c0c1893446814da960a3d4e21499787e546c99 (diff)
downloadtabellio.pcfdb-3cea0cf17b74f0b81af22c8b7fe82faae43f93e8.zip
tabellio.pcfdb-3cea0cf17b74f0b81af22c8b7fe82faae43f93e8.tar.gz
tabellio.pcfdb-3cea0cf17b74f0b81af22c8b7fe82faae43f93e8.tar.bz2
add import of previous deputies
Diffstat (limited to 'tabellio')
-rw-r--r--tabellio/pcfdb/sync.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/tabellio/pcfdb/sync.py b/tabellio/pcfdb/sync.py
index 1a7c2c1..f7a9788 100644
--- a/tabellio/pcfdb/sync.py
+++ b/tabellio/pcfdb/sync.py
@@ -314,6 +314,43 @@ class SyncFromPcfDbView(BrowserView):
where_ts = ''
if timestamp:
where_ts = cursor.mogrify('AND t_pers.ts > %s', (timestamp,))
+
+ # previous deputies
+ cursor.execute('''SELECT t_pers.id, t_pers.nom, prenom, sexe, datenaiss,
+ t_comppol.abbr
+ FROM t_pers, t_pershistoline, t_comppol
+ WHERE (t_pers.st = 'S_CREATED' or
+ t_pers.st = 'S_DEAD') and
+ t_pers.prenom is not NULL and
+ t_pers.id = t_pershistoline.pers and
+ t_pershistoline.description = t_comppol.id and
+ t_pershistoline.type = 'P_CMPL' and
+ t_pershistoline.fin IS NOT NULL
+ %s
+ ORDER BY t_pershistoline.fin DESC''' % where_ts)
+
+ polgroup_ids = {}
+ while True:
+ row = cursor.fetchone()
+ if row is None:
+ break
+ (pers_id, lastname, firstname, sex, birthdate, polgroup) = row
+ fullname = '%s %s' % (firstname, lastname)
+ new_id = self.plone_utils.normalizeString(fullname)
+ if not hasattr(self.deputies_folder, new_id):
+ self.deputies_folder.invokeFactory('themis.datatypes.deputy', new_id,
+ firstname=firstname, lastname=lastname)
+ object = getattr(self.deputies_folder, new_id)
+ object.firstname = firstname
+ object.lastname = lastname
+ object.sex = sex
+ object.birthdate = birthdate
+ object.polgroup = RelationValue(self.get_polgroup_intid(polgroup))
+ object.active = False
+ notify(ObjectModifiedEvent(object))
+ self.publish(object)
+
+ # currently active deputies
cursor.execute('''SELECT t_pers.id, t_pers.nom, prenom, sexe, datenaiss,
t_pers.addrpriv, t_pers.addrprof1, t_pers.addrprof2,
t_comppol.abbr, t_arrond.nom
@@ -350,6 +387,7 @@ class SyncFromPcfDbView(BrowserView):
object.private_address = self.get_address(privaddr)
object.work_address = self.get_address(workaddr1)
object.work_address_2 = self.get_address(workaddr2)
+ object.active = True
notify(ObjectModifiedEvent(object))
self.publish(object)