Add support for interpellations
This commit is contained in:
parent
de454ee11c
commit
2adb49a403
|
@ -73,7 +73,10 @@ class Migrate(BrowserView):
|
|||
else:
|
||||
if doc.get('meta_type') == 'PFBWriteAnswer':
|
||||
# shipper is a ministry
|
||||
shipper_id = self.get_ministry(doc.get('authors'))
|
||||
shipper_id = self.get_ministry(doc.get('authors')[0])
|
||||
elif doc.get('meta_type') == 'PFBChallenge':
|
||||
# shipper is a deputy
|
||||
shipper_id = self.get_deputy(doc.get('authors')[0])
|
||||
|
||||
if shipper_id:
|
||||
ob.expediteur.append(shipper_id)
|
||||
|
@ -84,6 +87,7 @@ class Migrate(BrowserView):
|
|||
pass
|
||||
|
||||
second_object_typename = {
|
||||
'PFBChallenge': 'interpellationD',
|
||||
'PFBWriteAnswer': 'reponse_a_question_ecriteD',
|
||||
}.get(doc.get('meta_type'))
|
||||
if second_object_typename:
|
||||
|
@ -103,22 +107,29 @@ class Migrate(BrowserView):
|
|||
ob2.session = doc.get('session')
|
||||
|
||||
if second_object_typename == 'reponse_a_question_ecriteD':
|
||||
ob2.ministre_auteur_reponse = self.get_ministry(doc.get('authors'))
|
||||
if doc.get('authors'):
|
||||
ob2.ministre_auteur_reponse = self.get_ministry(doc.get('authors')[0])
|
||||
elif second_object_typename == 'interpellationD':
|
||||
print 'authors:', doc.get('authors')
|
||||
if doc.get('authors'):
|
||||
ob2.auteur = [self.get_deputy(x) for x in doc.get('authors')]
|
||||
if doc.get('recipients'):
|
||||
ob2.ministres_concernes = [self.get_ministry(x) for x in doc.get('recipients')]
|
||||
|
||||
return u'→ OK\n'
|
||||
|
||||
def get_ministry(self, authors):
|
||||
if not authors:
|
||||
def get_ministry(self, author):
|
||||
if not author:
|
||||
return None
|
||||
plone_tool = getToolByName(self.context, 'plone_utils')
|
||||
portal = getToolByName(self.context, 'portal_url').getPortalObject()
|
||||
author = unicode(authors[0], 'utf-8')
|
||||
author = unicode(author, 'utf-8')
|
||||
author_id = plone_tool.normalizeString(author)
|
||||
if author_id == 'college':
|
||||
return 'ministry:college'
|
||||
if not portal.ministres.has_key(author_id):
|
||||
workflow_tool = getToolByName(self.context, 'portal_workflow')
|
||||
lastname, firstname = authors[0].split(',')
|
||||
lastname, firstname = author.split(',')
|
||||
portal.ministres.invokeFactory('themis.datatypes.ministry', author_id,
|
||||
firstname=firstname.strip(),
|
||||
lastname=lastname.strip())
|
||||
|
@ -129,3 +140,22 @@ class Migrate(BrowserView):
|
|||
pass
|
||||
|
||||
return 'ministry:'+author_id
|
||||
|
||||
def get_deputy(self, author):
|
||||
plone_tool = getToolByName(self.context, 'plone_utils')
|
||||
portal = getToolByName(self.context, 'portal_url').getPortalObject()
|
||||
author = unicode(author, 'utf-8')
|
||||
author_id = plone_tool.normalizeString(author)
|
||||
if not portal.deputes.has_key(author_id):
|
||||
workflow_tool = getToolByName(self.context, 'portal_workflow')
|
||||
lastname, firstname = author.split(',')
|
||||
portal.deputes.invokeFactory('themis.datatypes.deputy', author_id,
|
||||
firstname=firstname.strip(),
|
||||
lastname=lastname.strip())
|
||||
deputy = getattr(portal.deputes, author_id)
|
||||
try:
|
||||
workflow_tool.doActionFor(deputy, 'publish')
|
||||
except WorkflowException:
|
||||
pass
|
||||
|
||||
return 'deputy:'+author_id
|
||||
|
|
Reference in New Issue