Completed conversion code for simple mails
This commit is contained in:
parent
a48e8eb708
commit
b774c84e25
|
@ -1,34 +1,75 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import cPickle
|
||||
import os
|
||||
import datetime
|
||||
import cStringIO
|
||||
|
||||
from Products.Five.browser import BrowserView
|
||||
from Products.CMFCore.utils import getToolByName
|
||||
from plone.dexterity.factory import DexterityFactory
|
||||
from plone.dexterity.utils import addContentToContainer
|
||||
from plone.namedfile.file import NamedFile
|
||||
from Products.CMFCore.WorkflowCore import WorkflowException
|
||||
|
||||
class Migrate(BrowserView):
|
||||
def __call__(self):
|
||||
filename = self.request.form.get('filename')
|
||||
if not filename:
|
||||
print 'Exiting, missing filename'
|
||||
return
|
||||
if self.request['REQUEST_METHOD'] == 'GET':
|
||||
filename = self.request.form.get('filename')
|
||||
if not filename:
|
||||
return 'Missing filename\n'
|
||||
fd = file(os.path.join('/tmp/', filename))
|
||||
else:
|
||||
fd = cStringIO.StringIO(self.request.form['data'])
|
||||
|
||||
portal = getToolByName(self.context, 'portal_url').getPortalObject()
|
||||
workflowTool = getToolByName(self.context, 'portal_workflow')
|
||||
|
||||
fd = file(os.path.join('/tmp/', filename))
|
||||
doc = cPickle.load(fd)
|
||||
portal = getToolByName(self.context, 'portal_url').getPortalObject()
|
||||
workflow_tool = getToolByName(self.context, 'portal_workflow')
|
||||
plone_tool = getToolByName(self.context, 'plone_utils')
|
||||
|
||||
typename = {
|
||||
'PFBCurrentEventsQuestion': 'testplop'
|
||||
}.get(doc.get('meta_type'))
|
||||
if not typename:
|
||||
print 'Unknown type:', doc.get('meta_type')
|
||||
return
|
||||
if doc.get('state') not in ('filed',):
|
||||
return 'Unhandled state (%s)\n' % (doc.get('state'))
|
||||
|
||||
if doc.get('meta_type') == 'PFBArbitralCourt' and doc.get('id').startswith('cour-d-arbitrage'):
|
||||
return 'Arbitral Court documents are not to be imported\n'
|
||||
|
||||
# first step is to create a "courrier entrant" object
|
||||
typename = 'courrier_entrant'
|
||||
factory = DexterityFactory(portal_type=typename)
|
||||
ob = factory(id=doc.get('id'), title=doc.get('title'))
|
||||
addContentToContainer(portal.documents, ob)
|
||||
ob.date = datetime.datetime.strptime(doc.get('deliverydate'), '%Y-%m-%d').date()
|
||||
ob.file = NamedFile(fd.read(), filename=unicode(doc.get('filename')))
|
||||
if hasattr(self.context, doc.get('id')):
|
||||
ob = getattr(self.context, doc.get('id'))
|
||||
else:
|
||||
ob = factory(id=doc.get('id'), title=doc.get('title'))
|
||||
addContentToContainer(self.context, ob)
|
||||
|
||||
ob.date_reception = datetime.datetime.strptime(doc.get('deliverydate'), '%Y-%m-%d').date()
|
||||
ob.numero_courrier = doc.get('mailnumber')
|
||||
|
||||
ob.fichier = NamedFile(fd.read(), filename=unicode(doc.get('filename')))
|
||||
|
||||
ob.categorie_de_courrier = [{
|
||||
'PFBAddressChange': u'Changement de coordonnées',
|
||||
'PFBGeneralMail': u'Courrier général divers',
|
||||
'PFBArbitralCourt': u'Relations publiques',
|
||||
'PFBSubventionRequest': u'Demande de subvention',
|
||||
'PFBActivityAndExpertReport': u'''Rapport d'activités/d'experts''',
|
||||
'PFBCollegialNotification': u'Notifications du Collège',
|
||||
'PFBMeetingExcuses': u'Excusés',
|
||||
'PFBAuditingCommitteeCommunication': u'Communication gouvernementale',
|
||||
'PFBGeneralCommission': u'Commissions divers',
|
||||
}.get(doc.get('meta_type'))]
|
||||
|
||||
ob.expediteur = []
|
||||
for shipper in doc.get('shippers')[:1]:
|
||||
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)
|
||||
ob.expediteur.append(shipper)
|
||||
|
||||
try:
|
||||
workflow_tool.doActionFor(ob, 'publish')
|
||||
except WorkflowException:
|
||||
pass
|
||||
|
||||
return u'→ OK\n'
|
||||
|
|
Reference in New Issue