summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/collective/dms/batchimport/fileimporter.py50
-rw-r--r--src/collective/dms/batchimport/utils.py2
2 files changed, 43 insertions, 9 deletions
diff --git a/src/collective/dms/batchimport/fileimporter.py b/src/collective/dms/batchimport/fileimporter.py
index 558f75d..df6fee8 100644
--- a/src/collective/dms/batchimport/fileimporter.py
+++ b/src/collective/dms/batchimport/fileimporter.py
@@ -1,7 +1,13 @@
+# -*- coding: utf8 -*-
+
import logging
import os
import os.path
+from email.mime.base import MIMEBase
+from email.mime.multipart import MIMEMultipart
+from email.mime.text import MIMEText
+
from zope import schema
from zope.component import queryUtility
@@ -24,16 +30,20 @@ log = logging.getLogger('collective.dms.batchimport')
class IImportFileFormSchema(form.Schema):
file = NamedBlobFile(title=_(u"File"))
- title = schema.Text(required=False)
- portal_type = schema.Text(required=False)
- location = schema.Text(required=False)
- owner = schema.Text(required=False)
- treating_groups = schema.Text(required=False) # new, comme separated identifiers
- recipient_groups = schema.Text(required=False) # new, comme separated identifiers
- keywords = schema.Text(required=False) # comma separated identifiers
+ title = schema.Text(title=_(u"title"), required=False)
+ portal_type = schema.Text(title=_(u"portal_type"), required=False)
+ location = schema.Text(title=_(u"location"), required=False)
+ owner = schema.Text(title=_(u"owner"), required=False)
+ treating_groups = schema.Text(title=_(u"treating_groups"), required=False) # new, comme separated identifiers
+ recipient_groups = schema.Text(title=_(u"recipient_groups"), required=False) # new, comme separated identifiers
+ keywords = schema.Text(title=_(u"keywords"), required=False) # comma separated identifiers
+
+ notification_recipients = schema.Text(title=_(u"notification_recipients"), required=False) # comma separated emails
+
+ transitions_to_apply = schema.Text(title=_(u"transitions_to_apply"), required=False)
# legacy
- treating_group = schema.Text(required=False)
+ treating_group = schema.Text(title=_(u"treating_group"), required=False)
class ImportFileForm(form.SchemaForm):
@@ -87,7 +97,7 @@ class ImportFileForm(form.SchemaForm):
document_id = self.convertTitleToId(data.get('title') or os.path.splitext(filename)[0])
- utils.createDocument(self, folder, portal_type, document_id,
+ document = utils.createDocument(self, folder, portal_type, document_id,
filename, data['file'], owner,
treating_groups=treating_groups,
recipient_groups=recipient_groups,
@@ -95,3 +105,25 @@ class ImportFileForm(form.SchemaForm):
'title': data.get('title'),
'keywords': keywords,
})
+
+ if data.get('transitions_to_apply'):
+ transitions = data.get('transitions_to_apply').split(",")
+ for transition in transitions:
+ api.content.transition(document, transition)
+ document.reindexObject(idxs=['review_state', 'allowedRolesAndUsers'])
+
+ if data.get('notification_recipients'):
+ document_location = self.request.response.headers['location']
+ subject = 'Nouveau document, %s' % data.get('title')
+ message = 'Ouvrir dans la GED :\n %s\n' % document_location
+ recipients = data.get('notification_recipients').split(',')
+ self.send_message(subject, message, recipients)
+
+ def send_message(self, subject, message, recipients):
+ msg = MIMEMultipart()
+ msg['Subject'] = subject
+ msg['To'] = ', '.join(recipients)
+ msg['From'] = api.portal.get().getProperty('email_from_address') or 'admin@localhost'
+
+ msg.attach(MIMEText(message, _charset='utf-8'))
+ self.context.MailHost.send(msg.as_string())
diff --git a/src/collective/dms/batchimport/utils.py b/src/collective/dms/batchimport/utils.py
index e3a9a1c..fdb1be1 100644
--- a/src/collective/dms/batchimport/utils.py
+++ b/src/collective/dms/batchimport/utils.py
@@ -66,3 +66,5 @@ def createDocument(context, folder, portal_type, document_id, filename,
version = createContentInContainer(document, 'dmsmainfile',
title=_('Scanned Document'),
file=file_object)
+
+ return document