From 49a1ac08d312374a101db2e9811f236ec6282015 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Messiant?= Date: Thu, 18 Jul 2013 15:23:03 +0200 Subject: [PATCH] Use adopt_user to create document and main file, get the document_id in case of documents with the same name --- .../dms/batchimport/fileimporter.py | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/collective/dms/batchimport/fileimporter.py b/src/collective/dms/batchimport/fileimporter.py index 9758f05..cadb183 100644 --- a/src/collective/dms/batchimport/fileimporter.py +++ b/src/collective/dms/batchimport/fileimporter.py @@ -9,6 +9,7 @@ from Products.CMFPlone.interfaces import IPloneSiteRoot from Products.CMFCore.utils import getToolByName import z3c.form.button +from plone import api from plone.directives import form from plone.i18n.normalizer.interfaces import IIDNormalizer @@ -53,7 +54,7 @@ class ImportFileForm(form.SchemaForm): def convertTitleToId(self, title): """Plug into plone's id-from-title machinery. """ - #title = title.decode('utf-8') + #title = title.decode('utf-8') newid = queryUtility(IIDNormalizer).normalize(title) return newid @@ -82,14 +83,13 @@ class ImportFileForm(form.SchemaForm): metadata['reception_date'] = receptionDateDefaultValue(self) log.info('creating the document for real (%s)' % document_id) - folder.invokeFactory(portal_type, id=document_id, title=document_title, - **metadata) - - document = folder[document_id] - document.invokeFactory('dmsmainfile', id='main', title=_(u'Main File'), file=data['file']) - - mt = getToolByName(self.context, 'portal_membership') - member = mt.getMemberById(owner) - document.setCreators([owner]) - document.manage_setLocalRoles(owner, ['Owner', 'Editor']) - document.reindexObjectSecurity() + with api.env.adopt_user(username=owner): + document_id = folder.invokeFactory(portal_type, + id=document_id, + title=document_title, + **metadata) + document = folder[document_id] + document.invokeFactory('dmsmainfile', + id='main', + title=_(u'Main File'), + file=data['file'])