Add support for importing the legislative part of written answers

This commit is contained in:
Frédéric Péters 2011-07-27 18:13:01 +02:00
parent f87dc75c98
commit de454ee11c
1 changed files with 59 additions and 3 deletions

View File

@ -27,7 +27,7 @@ class Migrate(BrowserView):
workflow_tool = getToolByName(self.context, 'portal_workflow')
plone_tool = getToolByName(self.context, 'plone_utils')
if doc.get('state') not in ('filed',):
if doc.get('state') not in ('filed', 'preDocumented'):
return 'Unhandled state (%s)\n' % (doc.get('state'))
if doc.get('meta_type') == 'PFBArbitralCourt' and doc.get('id').startswith('cour-d-arbitrage'):
@ -58,18 +58,74 @@ class Migrate(BrowserView):
'PFBMeetingExcuses': u'Excusés',
'PFBAuditingCommitteeCommunication': u'Communication gouvernementale',
'PFBGeneralCommission': u'Commissions divers',
'PFBChallenge': u'Interpellation',
'PFBWriteAnswer': u'Réponse écrite',
}.get(doc.get('meta_type'))]
ob.expediteur = []
for shipper in doc.get('shippers')[:1]:
shipper_id = None
if doc.get('shippers'):
shipper = unicode(doc.get('shippers')[0], 'utf-8')
shipper_id = plone_tool.normalizeString(shipper)
if not portal.contacts.has_key(shipper_id):
portal.contacts.invokeFactory('themis.datatypes.contact', shipper_id, title=shipper)
ob.expediteur.append('contact:%s' % shipper_id)
shipper_id = 'contact:' + shipper_id
else:
if doc.get('meta_type') == 'PFBWriteAnswer':
# shipper is a ministry
shipper_id = self.get_ministry(doc.get('authors'))
if shipper_id:
ob.expediteur.append(shipper_id)
try:
workflow_tool.doActionFor(ob, 'publish')
except WorkflowException:
pass
second_object_typename = {
'PFBWriteAnswer': 'reponse_a_question_ecriteD',
}.get(doc.get('meta_type'))
if second_object_typename:
# XXX: this is a temporary location, no decision has been taken yet
# on the location of those documents
docdir = getattr(self.context.aq_parent, 'documents-diffusables')
if not hasattr(docdir, doc.get('id')):
factory = DexterityFactory(portal_type=second_object_typename)
ob2 = factory(id=doc.get('id'), title=doc.get('title'))
docdir._setObject(ob2.id, ob2)
else:
ob2 = getattr(docdir, doc.get('id'))
ob2.date_reception = datetime.datetime.strptime(doc.get('deliverydate'), '%Y-%m-%d').date()
ob2.mail_ref_id = ob.numero_courrier
ob2.session = doc.get('session')
if second_object_typename == 'reponse_a_question_ecriteD':
ob2.ministre_auteur_reponse = self.get_ministry(doc.get('authors'))
return u'→ OK\n'
def get_ministry(self, authors):
if not authors:
return None
plone_tool = getToolByName(self.context, 'plone_utils')
portal = getToolByName(self.context, 'portal_url').getPortalObject()
author = unicode(authors[0], '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(',')
portal.ministres.invokeFactory('themis.datatypes.ministry', author_id,
firstname=firstname.strip(),
lastname=lastname.strip())
ministry = getattr(portal.ministres, author_id)
try:
workflow_tool.doActionFor(ministry, 'publish')
except WorkflowException:
pass
return 'ministry:'+author_id