|
1 | 1 | # -*- coding: utf-8 -*-
|
2 | 2 | from AccessControl import getSecurityManager
|
3 | 3 | from collective.ckeditortemplates.cktemplate import ICKTemplate
|
| 4 | +from collective.dms.basecontent.dmsfile import IDmsAppendixFile |
4 | 5 | from datetime import datetime
|
| 6 | +from DateTime import DateTime |
5 | 7 | from eea.faceted.vocabularies.autocomplete import IAutocompleteSuggest
|
6 | 8 | from imio.dms.mail import _
|
7 | 9 | from imio.dms.mail import _tr
|
|
20 | 22 | from imio.helpers.workflow import do_transitions
|
21 | 23 | from imio.helpers.xhtml import object_link
|
22 | 24 | from plone import api
|
| 25 | +from plone.supermodel import model |
23 | 26 | from Products.CMFPlone.utils import safe_unicode
|
24 | 27 | from Products.Five import BrowserView
|
25 | 28 | from Products.PageTemplates.Expressions import SecureModuleImporter
|
26 | 29 | from unidecode import unidecode # unidecode_expect_nonascii not yet available in used version
|
| 30 | +from z3c.form import button |
| 31 | +from z3c.form.field import Fields |
| 32 | +from z3c.form.form import Form |
| 33 | +from z3c.relationfield import RelationValue |
| 34 | +from zope import schema |
27 | 35 | from zope.annotation import IAnnotations
|
28 | 36 | from zope.component import getMultiAdapter
|
| 37 | +from zope.component import getUtility |
29 | 38 | from zope.i18n import translate
|
30 | 39 | from zope.interface import implements
|
| 40 | +from zope.intid.interfaces import IIntIds |
31 | 41 | from zope.lifecycleevent import modified
|
32 | 42 | from zope.pagetemplate.pagetemplate import PageTemplate
|
33 | 43 |
|
@@ -70,6 +80,90 @@ def redirect_url(self, uid):
|
70 | 80 | return "{}/persistent-document-generation?{}".format(url, "&".join(params))
|
71 | 81 |
|
72 | 82 |
|
| 83 | +class IDuplicateFormSchema(model.Schema): |
| 84 | + |
| 85 | + keep_category = schema.Bool( |
| 86 | + title=u"Keep classification category", |
| 87 | + description=u'', |
| 88 | + ) |
| 89 | + |
| 90 | + keep_folder = schema.Bool( |
| 91 | + title=u"Keep classification folder", |
| 92 | + description=u'', |
| 93 | + ) |
| 94 | + |
| 95 | + keep_linked_mails = schema.Bool( |
| 96 | + title=u"Keep linked mails", |
| 97 | + description=u'', |
| 98 | + ) |
| 99 | + |
| 100 | + keep_dms_files = schema.Bool( |
| 101 | + title=u"Keep DMS files", |
| 102 | + description=u'', |
| 103 | + ) |
| 104 | + |
| 105 | + keep_annexes = schema.Bool( |
| 106 | + title=u"Keep annexes", |
| 107 | + description=u'', |
| 108 | + ) |
| 109 | + |
| 110 | + link_to_original = schema.Bool( |
| 111 | + title=u"Link to original", |
| 112 | + description=u'', |
| 113 | + ) |
| 114 | + |
| 115 | + |
| 116 | +class DuplicateForm(Form): |
| 117 | + |
| 118 | + """Duplicate an outgoing mail.""" |
| 119 | + label = _(u"Duplicate mail") |
| 120 | + fields = Fields(IDuplicateFormSchema) |
| 121 | + ignoreContext = True |
| 122 | + |
| 123 | + @button.buttonAndHandler(_('Duplicate'), name='duplicate') |
| 124 | + def handleApply(self, action): |
| 125 | + data, errors = self.extractData() |
| 126 | + |
| 127 | + if errors: |
| 128 | + self.status = self.formErrorsMessage |
| 129 | + return |
| 130 | + |
| 131 | + # Duplicate the mail |
| 132 | + parent = self.context.aq_parent |
| 133 | + clipboard = parent.manage_copyObjects([self.context.getId()]) |
| 134 | + result = parent.manage_pasteObjects(clipboard) |
| 135 | + duplicated_mail = parent[result[0]['new_id']] |
| 136 | + duplicated_mail.creation_date = DateTime() |
| 137 | + duplicated_mail.reindexObject(idxs=['created']) |
| 138 | + # TODO fix internal reference |
| 139 | + |
| 140 | + if not data['keep_category']: |
| 141 | + pass |
| 142 | + |
| 143 | + if not data['keep_folder']: |
| 144 | + pass |
| 145 | + |
| 146 | + if not data['keep_linked_mails']: |
| 147 | + pass |
| 148 | + |
| 149 | + if not data['keep_dms_files']: |
| 150 | + dms_files = [sub_content.getId() for sub_content in duplicated_mail.values() if IImioDmsFile.providedBy(sub_content)] |
| 151 | + if dms_files: |
| 152 | + duplicated_mail.manage_delObjects(dms_files) |
| 153 | + |
| 154 | + if not data['keep_annexes']: |
| 155 | + annexes = [sub_content.getId() for sub_content in duplicated_mail.values() if IDmsAppendixFile.providedBy(sub_content)] |
| 156 | + if annexes: |
| 157 | + duplicated_mail.manage_delObjects(annexes) |
| 158 | + |
| 159 | + if data['link_to_original']: |
| 160 | + intids = getUtility(IIntIds) |
| 161 | + rel_id = intids.getId(self.context) |
| 162 | + duplicated_mail.reply_to.append(RelationValue(rel_id)) |
| 163 | + |
| 164 | + self.request.response.redirect(duplicated_mail.absolute_url()) |
| 165 | + |
| 166 | + |
73 | 167 | def parse_query(text):
|
74 | 168 | """Copied from plone.app.vocabularies.catalog.parse_query but cleaned."""
|
75 | 169 | for char in "?-+*()":
|
|
0 commit comments