import deputy functions

This commit is contained in:
Frédéric Péters 2011-11-24 15:27:27 +01:00
parent 51b9ce1f8f
commit 0d94a2495d
1 changed files with 81 additions and 0 deletions

View File

@ -471,6 +471,7 @@ class SyncFromPcfDbView(BrowserView):
object.birthdate = birthdate
object.polgroup = RelationValue(self.get_polgroup_intid(polgroup))
object.active = False
self.set_person_functions(object, pers_id)
notify(ObjectModifiedEvent(object))
self.publish(object)
@ -513,12 +514,92 @@ class SyncFromPcfDbView(BrowserView):
object.work_address = self.get_address(workaddr1)
object.work_address_2 = self.get_address(workaddr2)
object.active = True
self.set_person_functions(object, pers_id)
notify(ObjectModifiedEvent(object))
self.publish(object)
cursor.close()
return count
def set_person_functions(self, object, pers):
print object.title
cursor = self.db_connection.cursor()
cursor.execute('''SELECT debut, fin, type, description, t_comppol.abbr
FROM t_pershistoline LEFT JOIN t_comppol
ON (description = t_comppol.id)
WHERE pers = %(id)s
ORDER BY fin DESC, debut ASC''', {'id': pers})
current = []
past = []
while True:
row = cursor.fetchone()
if row is None:
break
debut, fin, type, description, comppol = row
if type in ('P_FONC', 'M_FONC', 'M_PREM', 'P_COMM_SE'):
title = description
elif type == 'P_PARL':
title = 'Parlementaire'
elif type == 'P_CMPL':
title = 'Membre du groupe politique %s' % comppol
elif type.startswith('P_COMM_'):
if type == 'P_COMM_TI':
title = u'Membre titulaire'
elif type == 'P_COMM_SU':
if object.sex == 'M':
title = u'Membre suppléant'
else:
title = u'Membre suppléante'
elif type == 'P_COMM_PR':
if object.sex == 'M':
title = u'Président'
else:
title = u'Présidente'
elif type == 'P_COMM_VP':
if object.sex == 'M':
title = u'Vice-président'
else:
title = u'Vice-présidente'
com = self.get_commission_title(description)
com = com[0].lower() + com[1:]
if com.lower().startswith('commission'):
title = '%s de la %s' % (title, com)
else:
title = '%s du %s' % (title, com)
elif type == 'P_PRES':
if object.sex == 'M':
title = u'Président de groupe politique'
else:
title = u'Présidente de groupe politique'
elif type == 'P_SNTR':
if object.sex == 'M':
title = u'Sénateur de Communauté'
else:
title = u'Sénatrice de Communauté'
elif type in ('M_MINT', 'M_CMPT'):
continue
else:
print 'unknown type:', type
continue
start_str = debut.strftime('%d/%m/%Y')
if fin is None:
current.append(u'<li>%s (depuis le %s)</li>' % (title, start_str))
else:
end_str = fin.strftime('%d/%m/%Y')
past.append(u'<li>%s (du %s au %s)</li>' % (title, start_str, end_str))
cursor.close()
if current:
current = ['<ul>'] + current + ['</ul>']
if past:
past = ['<ul>'] + past + ['</ul>']
object.current_functions = RichTextValue(raw='\n'.join(current),
mimeType='text/html', outputMimeType='text/x-html-safe')
object.past_functions = RichTextValue(raw='\n'.join(past),
mimeType='text/html', outputMimeType='text/x-html-safe')
def sync_ministries(self, timestamp=None):
cursor = self.db_connection.cursor()
where_ts = ''