add synchronisation of bureau & extended bureau from themis (#11095)
This commit is contained in:
parent
13208b4789
commit
cecf170359
|
@ -1,5 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import re
|
||||||
import datetime
|
import datetime
|
||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
|
@ -57,7 +58,7 @@ class SyncFromThemis(UtilityView):
|
||||||
objects = self.request.form.get('objects', '').split(',')
|
objects = self.request.form.get('objects', '').split(',')
|
||||||
log.info('sync: start [%r] [%r]' % (timestamp, objects))
|
log.info('sync: start [%r] [%r]' % (timestamp, objects))
|
||||||
for object in ('deputies', 'ministries', 'commissions', 'documents',
|
for object in ('deputies', 'ministries', 'commissions', 'documents',
|
||||||
'blocked_documents', 'deleted_documents'):
|
'blocked_documents', 'deleted_documents', 'bureau'):
|
||||||
if not 'all' in objects:
|
if not 'all' in objects:
|
||||||
if not object in objects:
|
if not object in objects:
|
||||||
continue
|
continue
|
||||||
|
@ -474,6 +475,69 @@ class SyncFromThemis(UtilityView):
|
||||||
|
|
||||||
log.info('blocked documents done')
|
log.info('blocked documents done')
|
||||||
|
|
||||||
|
def sync_bureau(self, *args):
|
||||||
|
remote_bureau = json.load(self.urlopen('%s/bureau-bureau-elargi/bureau_elargi/@@json' % self.src_url))
|
||||||
|
|
||||||
|
def get_info(deputy_id):
|
||||||
|
return getattr(self.deputies_folder, deputy_id.split(':')[1])
|
||||||
|
|
||||||
|
bureau = []
|
||||||
|
pers = get_info(remote_bureau['president'])
|
||||||
|
bureau.append(([get_info(remote_bureau['president'])],
|
||||||
|
u"Président" if pers.sex == 'M' else u"Présidente"))
|
||||||
|
bureau.append(([get_info(remote_bureau['premier_vice_president'])],
|
||||||
|
u"Premier vice-président" if pers.sex == 'M' else u"Première vice-présidente"))
|
||||||
|
bureau.append(([get_info(remote_bureau['deuxieme_vice_president'])],
|
||||||
|
u"Deuxième vice-président" if pers.sex == 'M' else u"Deuxième vice-présidente"))
|
||||||
|
bureau.append(([get_info(remote_bureau['troisieme_vice_president'])],
|
||||||
|
u"Troisième vice-président" if pers.sex == 'M' else u"Troisième vice-présidente"))
|
||||||
|
bureau.append(([get_info(x) for x in remote_bureau['secretaires']],
|
||||||
|
u"Secrétaires"))
|
||||||
|
|
||||||
|
def format_pers(pers):
|
||||||
|
return '<a href="/%s/%s">%s</a> (%s)' % (
|
||||||
|
self.settings.deputiesPath,
|
||||||
|
pers.id,
|
||||||
|
pers.title,
|
||||||
|
pers.polgroup.to_object.title)
|
||||||
|
|
||||||
|
bureau_text = u"<p>%s</p>" % "<br>\n".join(
|
||||||
|
[u"%s : %s" % (x[1], " et ".join([format_pers(y) for y in x[0]])) for x in bureau])
|
||||||
|
|
||||||
|
polgroup_order = [x for x in self.polgroups_folder]
|
||||||
|
bureau_elargi = [get_info(x) for x in remote_bureau['chefs_de_groupe']]
|
||||||
|
bureau_elargi.sort(key=lambda x: polgroup_order.index(x.polgroup.to_object.id))
|
||||||
|
|
||||||
|
bureau_elargi_text = u"<p>"
|
||||||
|
for pers in bureau_elargi:
|
||||||
|
label = u"Président de groupe" if pers.sex == "M" else u"Présidente de groupe"
|
||||||
|
bureau_elargi_text += u'%s %s : <a href="/%s/%s">%s</a><br>' % (
|
||||||
|
label,
|
||||||
|
pers.polgroup.to_object.title,
|
||||||
|
self.settings.deputiesPath, pers.id,
|
||||||
|
pers.title)
|
||||||
|
bureau_elargi_text += u"</p>"
|
||||||
|
|
||||||
|
article = getattr(self.deputies_folder, 'bureau')
|
||||||
|
article.setText(u'<h5 class="compo">Composition politique du Bureau</h5>\n\n' + bureau_text)
|
||||||
|
|
||||||
|
article = getattr(self.deputies_folder, 'bureau-elargi')
|
||||||
|
article.setText(u'<h5 class="compo">Composition politique du Bureau élargi</h5>\n\n' + bureau_text + bureau_elargi_text)
|
||||||
|
|
||||||
|
le_parlement = self.get_folder_at_path('le-parlement/le-bureau-le-bureau-elargi-et-le-greffier')
|
||||||
|
bureau_article = getattr(le_parlement, 'introduction-bureau-bureau-elargi-et-greffier')
|
||||||
|
orig_text = bureau_article.getText()
|
||||||
|
if type(orig_text) is not unicode:
|
||||||
|
orig_text = unicode(orig_text, 'utf-8')
|
||||||
|
|
||||||
|
both = u'<h5 class="compo">Composition politique du Bureau</h5>\n\n' + bureau_text
|
||||||
|
both += '\n'
|
||||||
|
both += u'<h5 class="compo">Composition politique du Bureau élargi</h5>\n\n' + bureau_text + bureau_elargi_text
|
||||||
|
regex = re.compile(r'<hr.*<hr />', re.DOTALL)
|
||||||
|
bureau_article.setText(regex.sub(u'<hr />%s<hr />' % both, orig_text))
|
||||||
|
|
||||||
|
log.info('bureau done')
|
||||||
|
|
||||||
def sync_deleted_documents(self, *args):
|
def sync_deleted_documents(self, *args):
|
||||||
remote_documents = json.load(self.urlopen('%s/@@listDocuments' % self.src_url))
|
remote_documents = json.load(self.urlopen('%s/@@listDocuments' % self.src_url))
|
||||||
|
|
||||||
|
|
Reference in New Issue