From 263a1593f686ed8943256953b3726738d7b188e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Fri, 29 Jul 2011 21:57:33 +0200 Subject: [PATCH] consider more than the first shipper --- themis/libellioimport/migration.py | 39 +++++++++++++++++++----------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/themis/libellioimport/migration.py b/themis/libellioimport/migration.py index 71fba2a..8f89813 100644 --- a/themis/libellioimport/migration.py +++ b/themis/libellioimport/migration.py @@ -87,16 +87,20 @@ class Migrate(BrowserView): ob.expediteur = [] 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) - shipper_id = 'contact:' + shipper_id + for shipper in doc.get('shippers'): + shipper = unicode(shipper, '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) + shipper_id = 'contact:' + shipper_id + ob.expediteur.append(shipper_id) else: if doc.get('meta_type') in ('PFBWriteAnswer', 'PFBProject'): # shipper is a ministry if doc.get('authors'): - shipper_id = self.get_ministry(doc.get('authors')[0]) + for author in doc.get('authors'): + shipper_id = self.get_ministry(author) + ob.expediteur.append(shipper_id) else: print >> self.logfile, 'W: document without an author' elif doc.get('meta_type') in ('PFBChallenge', @@ -104,13 +108,12 @@ class Migrate(BrowserView): 'PFBProposal', 'PFBWriteRequest'): # shipper is a deputy if doc.get('authors'): - shipper_id = self.get_deputy(doc.get('authors')[0]) + for author in doc.get('authors'): + shipper_id = self.get_deputy(author) + ob.expediteur.append(shipper_id) else: print >> self.logfile, 'W: document without an author' - if shipper_id: - ob.expediteur.append(shipper_id) - if doc.get('type'): ob.sous_categorie_de_courrier = { 'proj_decret': u'Projet de décret', @@ -150,6 +153,10 @@ class Migrate(BrowserView): if second_object_typename is None: print >> self.logfile, 'W: proposal of unknown type' + if not doc.get('authors') and doc.get('state') == 'initial': + # this document was not completed, do not create a secondary object + second_object_typename = None + if second_object_typename: # XXX: this is a temporary location, no decision has been taken yet # on the location of those documents @@ -159,8 +166,8 @@ class Migrate(BrowserView): 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 = 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 @@ -168,6 +175,8 @@ class Migrate(BrowserView): if second_object_typename == 'reponse_a_question_ecriteD': if doc.get('authors'): + if len(doc.get('authors')) > 1: + print >> self.logfile, 'W: answer to written question with more than one author' ob2.ministre_auteur_reponse = self.get_ministry(doc.get('authors')[0]) elif second_object_typename in ('interpellationD', 'questionactualiteD', 'QuestionoraleD'): @@ -178,12 +187,14 @@ class Migrate(BrowserView): elif second_object_typename == 'ProjetD': ob2.type_de_projet = ob.sous_categorie_de_courrier if doc.get('authors'): - ob2.auteur = [self.get_ministry(x) for x in doc.get('authors')] + if len(doc.get('authors')) > 1: + print >> self.logfile, 'W: project with more than one author' + ob2.auteur = [self.get_ministry(x) for x in doc.get('authors')][0] elif second_object_typename in ('proposition_decret_reglementD', 'proposition_resolution_modificationD'): ob2.type_de_proposition = ob.sous_categorie_de_courrier if doc.get('authors'): - ob2.auteur = [self.get_deputy(x) for x in doc.get('authors')] + ob2.auteurs = [self.get_deputy(x) for x in doc.get('authors')] if doc.get('state') in ('filed', 'preDocumented'): try: