|
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 |
| 5 | +from collective.dms.mailcontent.dmsmail import internalReferenceOutgoingMailDefaultValue |
4 | 6 | from datetime import datetime
|
| 7 | +from DateTime import DateTime |
5 | 8 | from eea.faceted.vocabularies.autocomplete import IAutocompleteSuggest
|
6 | 9 | from imio.dms.mail import _
|
7 | 10 | from imio.dms.mail import _tr
|
8 | 11 | from imio.dms.mail import PMH_ENABLED
|
| 12 | +from imio.dms.mail.browser.settings import IImioDmsMailConfig |
9 | 13 | from imio.dms.mail.browser.table import CKTemplatesTable
|
10 | 14 | from imio.dms.mail.browser.table import PersonnelTable
|
11 | 15 | from imio.dms.mail.dmsfile import IImioDmsFile
|
|
20 | 24 | from imio.helpers.workflow import do_transitions
|
21 | 25 | from imio.helpers.xhtml import object_link
|
22 | 26 | from plone import api
|
| 27 | +from plone.supermodel import model |
| 28 | +from Products.CMFCore.utils import getToolByName |
23 | 29 | from Products.CMFPlone.utils import safe_unicode
|
24 | 30 | from Products.Five import BrowserView
|
25 | 31 | from Products.PageTemplates.Expressions import SecureModuleImporter
|
26 | 32 | from unidecode import unidecode # unidecode_expect_nonascii not yet available in used version
|
| 33 | +from z3c.form import button |
| 34 | +from z3c.form.field import Fields |
| 35 | +from z3c.form.form import Form |
| 36 | +from z3c.relationfield import RelationValue |
| 37 | +from zope import schema |
27 | 38 | from zope.annotation import IAnnotations
|
28 | 39 | from zope.component import getMultiAdapter
|
| 40 | +from zope.component import getUtility |
29 | 41 | from zope.i18n import translate
|
30 | 42 | from zope.interface import implements
|
| 43 | +from zope.intid.interfaces import IIntIds |
31 | 44 | from zope.lifecycleevent import modified
|
32 | 45 | from zope.pagetemplate.pagetemplate import PageTemplate
|
33 | 46 |
|
@@ -70,6 +83,117 @@ def redirect_url(self, uid):
|
70 | 83 | return "{}/persistent-document-generation?{}".format(url, "&".join(params))
|
71 | 84 |
|
72 | 85 |
|
| 86 | +class IDuplicateFormSchema(model.Schema): |
| 87 | + |
| 88 | + keep_category = schema.Bool( |
| 89 | + title=_(u"Keep classification category"), |
| 90 | + description=u'', |
| 91 | + default=True, |
| 92 | + ) |
| 93 | + |
| 94 | + keep_folder = schema.Bool( |
| 95 | + title=_(u"Keep classification folder"), |
| 96 | + description=u'', |
| 97 | + default=True, |
| 98 | + ) |
| 99 | + |
| 100 | + keep_linked_mails = schema.Bool( |
| 101 | + title=_(u"Keep linked mails"), |
| 102 | + description=u'', |
| 103 | + default=True, |
| 104 | + ) |
| 105 | + |
| 106 | + keep_dms_files = schema.Bool( |
| 107 | + title=_(u"Keep DMS files"), |
| 108 | + description=u'', |
| 109 | + default=True, |
| 110 | + ) |
| 111 | + |
| 112 | + keep_annexes = schema.Bool( |
| 113 | + title=_(u"Keep annexes"), |
| 114 | + description=u'', |
| 115 | + default=True, |
| 116 | + ) |
| 117 | + |
| 118 | + link_to_original = schema.Bool( |
| 119 | + title=_(u"Link to original"), |
| 120 | + description=u'', |
| 121 | + default=True, |
| 122 | + ) |
| 123 | + |
| 124 | + |
| 125 | +class DuplicateForm(Form): |
| 126 | + |
| 127 | + """Duplicate an outgoing mail.""" |
| 128 | + label = _(u"Duplicate mail") |
| 129 | + fields = Fields(IDuplicateFormSchema) |
| 130 | + ignoreContext = True |
| 131 | + |
| 132 | + @button.buttonAndHandler(_('Duplicate'), name='duplicate') |
| 133 | + def handleApply(self, action): |
| 134 | + data, errors = self.extractData() |
| 135 | + |
| 136 | + if errors: |
| 137 | + self.status = self.formErrorsMessage |
| 138 | + return |
| 139 | + |
| 140 | + # Duplicate the mail |
| 141 | + parent = self.context.aq_parent |
| 142 | + clipboard = parent.manage_copyObjects([self.context.getId()]) |
| 143 | + result = parent.manage_pasteObjects(clipboard) |
| 144 | + duplicated_mail = parent[result[0]['new_id']] |
| 145 | + duplicated_mail.creation_date = DateTime() |
| 146 | + duplicated_mail.reindexObject(idxs=['created']) |
| 147 | + duplicated_mail.internal_reference_no = internalReferenceOutgoingMailDefaultValue(self) |
| 148 | + duplicated_mail.due_date = None |
| 149 | + duplicated_mail.outgoing_date = None |
| 150 | + duplicated_mail.mail_date = None |
| 151 | + |
| 152 | + if not data['keep_category']: |
| 153 | + duplicated_mail.classification_categories = None |
| 154 | + |
| 155 | + if not data['keep_folder']: |
| 156 | + duplicated_mail.classification_folders = None |
| 157 | + |
| 158 | + if not data['keep_linked_mails']: |
| 159 | + duplicated_mail.reply_to = None |
| 160 | + |
| 161 | + if not data['keep_dms_files']: |
| 162 | + dms_files = [sub_content.getId() for sub_content in duplicated_mail.values() if IImioDmsFile.providedBy(sub_content)] |
| 163 | + if dms_files: |
| 164 | + duplicated_mail.manage_delObjects(dms_files) |
| 165 | + |
| 166 | + if not data['keep_annexes']: |
| 167 | + annexes = [sub_content.getId() for sub_content in duplicated_mail.values() if IDmsAppendixFile.providedBy(sub_content)] |
| 168 | + if annexes: |
| 169 | + duplicated_mail.manage_delObjects(annexes) |
| 170 | + |
| 171 | + if data['link_to_original']: |
| 172 | + intids = getUtility(IIntIds) |
| 173 | + rel_id = intids.getId(self.context) |
| 174 | + if duplicated_mail.reply_to is None: |
| 175 | + duplicated_mail.reply_to = [] |
| 176 | + duplicated_mail.reply_to.append(RelationValue(rel_id)) |
| 177 | + |
| 178 | + self.request.response.redirect(duplicated_mail.absolute_url()+"/edit") |
| 179 | + |
| 180 | + def updateWidgets(self): |
| 181 | + super(DuplicateForm, self).updateWidgets() |
| 182 | + self.widgets["keep_category"].value = ['selected'] if api.portal.get_registry_record("omail_duplicate_default_keep_category", IImioDmsMailConfig, True) else [] |
| 183 | + self.widgets["keep_folder"].value = ['selected'] if api.portal.get_registry_record("omail_duplicate_default_keep_folder", IImioDmsMailConfig, True) else [] |
| 184 | + self.widgets["keep_linked_mails"].value = ['selected'] if api.portal.get_registry_record("omail_duplicate_default_keep_linked_mails", IImioDmsMailConfig, True) else [] |
| 185 | + self.widgets["keep_dms_files"].value = ['selected'] if api.portal.get_registry_record("omail_duplicate_default_keep_dms_files", IImioDmsMailConfig, True) else [] |
| 186 | + self.widgets["keep_annexes"].value = ['selected'] if api.portal.get_registry_record("omail_duplicate_default_keep_annexes", IImioDmsMailConfig, True) else [] |
| 187 | + self.widgets["link_to_original"].value = ['selected'] if api.portal.get_registry_record("omail_duplicate_default_link_to_original", IImioDmsMailConfig, True) else [] |
| 188 | + |
| 189 | + navtree_props = getToolByName(api.portal.get(), 'portal_properties').navtree_properties |
| 190 | + excluded_types = navtree_props.getProperty('metaTypesNotToList', ()) |
| 191 | + if 'ClassificationContainer' in excluded_types: |
| 192 | + self.widgets["keep_category"].mode = "hidden" |
| 193 | + if 'ClassificationFolders' in excluded_types: |
| 194 | + self.widgets["keep_folder"].mode = "hidden" |
| 195 | + |
| 196 | + |
73 | 197 | def parse_query(text):
|
74 | 198 | """Copied from plone.app.vocabularies.catalog.parse_query but cleaned."""
|
75 | 199 | for char in "?-+*()":
|
|
0 commit comments