collective.documentgenerator 3.46__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- collective/documentgenerator/AT_renderer.py +98 -0
- collective/documentgenerator/DX_renderer.py +52 -0
- collective/documentgenerator/__init__.py +17 -0
- collective/documentgenerator/adapters.py +23 -0
- collective/documentgenerator/browser/__init__.py +0 -0
- collective/documentgenerator/browser/actionspanel.py +19 -0
- collective/documentgenerator/browser/check_pod_templates.pt +63 -0
- collective/documentgenerator/browser/children_pod_template.pt +16 -0
- collective/documentgenerator/browser/configure.zcml +220 -0
- collective/documentgenerator/browser/controlpanel.py +159 -0
- collective/documentgenerator/browser/converter.py +43 -0
- collective/documentgenerator/browser/generation_view.py +532 -0
- collective/documentgenerator/browser/overrides.py +9 -0
- collective/documentgenerator/browser/resources/css/documentgenerator.css +133 -0
- collective/documentgenerator/browser/static/.gitkeep +0 -0
- collective/documentgenerator/browser/static/configurable.svg +1232 -0
- collective/documentgenerator/browser/static/csv.svg +521 -0
- collective/documentgenerator/browser/static/doc.svg +23 -0
- collective/documentgenerator/browser/static/docx.svg +20 -0
- collective/documentgenerator/browser/static/download_icon.svg +54 -0
- collective/documentgenerator/browser/static/libreoffice-blanck.svg +481 -0
- collective/documentgenerator/browser/static/mailinglooptemplate.svg +1207 -0
- collective/documentgenerator/browser/static/missing_use.svg +42 -0
- collective/documentgenerator/browser/static/nok.svg +38 -0
- collective/documentgenerator/browser/static/nok_use.svg +38 -0
- collective/documentgenerator/browser/static/nok_used.svg +38 -0
- collective/documentgenerator/browser/static/odp.svg +1264 -0
- collective/documentgenerator/browser/static/ods.svg +1354 -0
- collective/documentgenerator/browser/static/odt.svg +1347 -0
- collective/documentgenerator/browser/static/ok.svg +38 -0
- collective/documentgenerator/browser/static/ok_use.svg +38 -0
- collective/documentgenerator/browser/static/ok_used.svg +38 -0
- collective/documentgenerator/browser/static/pdf.svg +557 -0
- collective/documentgenerator/browser/static/podtemplate.svg +1197 -0
- collective/documentgenerator/browser/static/rtf.svg +521 -0
- collective/documentgenerator/browser/static/style.svg +1207 -0
- collective/documentgenerator/browser/static/subtemplate.svg +1250 -0
- collective/documentgenerator/browser/static/xls.svg +159 -0
- collective/documentgenerator/browser/static/xlsx.svg +48 -0
- collective/documentgenerator/browser/table.py +277 -0
- collective/documentgenerator/browser/templates_listing.pt +23 -0
- collective/documentgenerator/browser/views.py +365 -0
- collective/documentgenerator/config.py +162 -0
- collective/documentgenerator/configure.zcml +41 -0
- collective/documentgenerator/content/__init__.py +0 -0
- collective/documentgenerator/content/condition.py +60 -0
- collective/documentgenerator/content/conditions.zcml +29 -0
- collective/documentgenerator/content/configure.zcml +25 -0
- collective/documentgenerator/content/document_factory.py +73 -0
- collective/documentgenerator/content/file_representation.py +73 -0
- collective/documentgenerator/content/file_representation.zcml +28 -0
- collective/documentgenerator/content/merge_templates.py +15 -0
- collective/documentgenerator/content/merge_templates.zcml +10 -0
- collective/documentgenerator/content/pod_template.py +547 -0
- collective/documentgenerator/content/style_template.py +52 -0
- collective/documentgenerator/content/vocabulary.py +315 -0
- collective/documentgenerator/content/vocabulary.zcml +104 -0
- collective/documentgenerator/demo/__init__.py +0 -0
- collective/documentgenerator/demo/archetypes.zcml +10 -0
- collective/documentgenerator/demo/configure.zcml +19 -0
- collective/documentgenerator/demo/helper.py +198 -0
- collective/documentgenerator/events/__init__.py +0 -0
- collective/documentgenerator/events/configure.zcml +30 -0
- collective/documentgenerator/events/pod_templates_events.py +66 -0
- collective/documentgenerator/events/styles_events.py +122 -0
- collective/documentgenerator/helper/__init__.py +9 -0
- collective/documentgenerator/helper/archetypes-adapter.zcml +10 -0
- collective/documentgenerator/helper/archetypes-page.zcml +9 -0
- collective/documentgenerator/helper/archetypes.py +67 -0
- collective/documentgenerator/helper/base.py +266 -0
- collective/documentgenerator/helper/configure.zcml +38 -0
- collective/documentgenerator/helper/dexterity.py +174 -0
- collective/documentgenerator/interfaces.py +165 -0
- collective/documentgenerator/locales/collective.documentgenerator.pot +564 -0
- collective/documentgenerator/locales/es/LC_MESSAGES/collective.documentgenerator.po +572 -0
- collective/documentgenerator/locales/es/LC_MESSAGES/plone.po +32 -0
- collective/documentgenerator/locales/fr/LC_MESSAGES/collective.documentgenerator.po +566 -0
- collective/documentgenerator/locales/fr/LC_MESSAGES/plone.po +27 -0
- collective/documentgenerator/locales/manual.pot +30 -0
- collective/documentgenerator/locales/plone-manual.pot +22 -0
- collective/documentgenerator/locales/plone.pot +30 -0
- collective/documentgenerator/locales/update.sh +22 -0
- collective/documentgenerator/migrations/__init__.py +0 -0
- collective/documentgenerator/migrations/migrate_to_11.py +53 -0
- collective/documentgenerator/migrations/migrate_to_12.py +30 -0
- collective/documentgenerator/migrations/migrate_to_13.py +37 -0
- collective/documentgenerator/migrations/migrate_to_3.py +36 -0
- collective/documentgenerator/migrations/migrate_to_5.py +30 -0
- collective/documentgenerator/migrations/migrate_to_6.py +27 -0
- collective/documentgenerator/migrations/migrate_to_7.py +32 -0
- collective/documentgenerator/migrations/migrate_to_8.py +34 -0
- collective/documentgenerator/migrations/migrate_to_9.py +48 -0
- collective/documentgenerator/profiles/base/browserlayer.xml +7 -0
- collective/documentgenerator/profiles/base/controlpanel.xml +20 -0
- collective/documentgenerator/profiles/base/metadata.xml +7 -0
- collective/documentgenerator/profiles/base/types/ConfigurablePODTemplate.xml +43 -0
- collective/documentgenerator/profiles/base/types/MailingLoopTemplate.xml +42 -0
- collective/documentgenerator/profiles/base/types/PODTemplate.xml +42 -0
- collective/documentgenerator/profiles/base/types/StyleTemplate.xml +42 -0
- collective/documentgenerator/profiles/base/types/SubTemplate.xml +42 -0
- collective/documentgenerator/profiles/base/types.xml +10 -0
- collective/documentgenerator/profiles/base/viewlets.xml +6 -0
- collective/documentgenerator/profiles/demo/browserlayer.xml +7 -0
- collective/documentgenerator/profiles/demo/collectivedocumentgenerator_demo_marker.txt +0 -0
- collective/documentgenerator/profiles/demo/import_steps.xml +11 -0
- collective/documentgenerator/profiles/demo/metadata.xml +7 -0
- collective/documentgenerator/profiles/demo/registry.xml +13 -0
- collective/documentgenerator/profiles/demo/templates/mailing.odt +0 -0
- collective/documentgenerator/profiles/demo/templates/modele_general.ods +0 -0
- collective/documentgenerator/profiles/demo/templates/modele_general.odt +0 -0
- collective/documentgenerator/profiles/demo/templates/mod/303/250le_collection.odt +0 -0
- collective/documentgenerator/profiles/demo/templates/possibly_mailed_model.odt +0 -0
- collective/documentgenerator/profiles/demo/templates/styles.odt +0 -0
- collective/documentgenerator/profiles/demo/templates/styles_2.odt +0 -0
- collective/documentgenerator/profiles/demo/templates/sub_template.odt +0 -0
- collective/documentgenerator/profiles/demo/viewlets.xml +3 -0
- collective/documentgenerator/profiles/plone4/collectivedocumentgenerator_marker.txt +0 -0
- collective/documentgenerator/profiles/plone4/cssregistry.xml +11 -0
- collective/documentgenerator/profiles/plone4/metadata.xml +7 -0
- collective/documentgenerator/profiles/plone4/registry.xml +6 -0
- collective/documentgenerator/profiles/plone5/metadata.xml +7 -0
- collective/documentgenerator/profiles/plone5/registry.xml +15 -0
- collective/documentgenerator/profiles/testing/metadata.xml +7 -0
- collective/documentgenerator/profiles/testing/propertiestool.xml +5 -0
- collective/documentgenerator/profiles/testing/types/member.xml +85 -0
- collective/documentgenerator/profiles/testing/types.xml +5 -0
- collective/documentgenerator/profiles.zcml +186 -0
- collective/documentgenerator/renderer.zcml +145 -0
- collective/documentgenerator/search_replace/__init__.py +0 -0
- collective/documentgenerator/search_replace/configure.zcml +19 -0
- collective/documentgenerator/search_replace/pod_template.py +146 -0
- collective/documentgenerator/search_replace/search_result_form.pt +48 -0
- collective/documentgenerator/search_replace/searchreplace_panel.pt +22 -0
- collective/documentgenerator/search_replace/searchreplace_panel.py +261 -0
- collective/documentgenerator/setuphandlers.py +287 -0
- collective/documentgenerator/testing.py +324 -0
- collective/documentgenerator/testing.zcml +16 -0
- collective/documentgenerator/tests/__init__.py +0 -0
- collective/documentgenerator/tests/failing_template.odt +0 -0
- collective/documentgenerator/tests/robot/.gitkeep +0 -0
- collective/documentgenerator/tests/template_to_clean.odt +0 -0
- collective/documentgenerator/tests/template_without_style_page.odt +0 -0
- collective/documentgenerator/tests/test_AT_helper_view.py +276 -0
- collective/documentgenerator/tests/test_DX_helper_view.py +355 -0
- collective/documentgenerator/tests/test_base_helper_view.py +128 -0
- collective/documentgenerator/tests/test_check_podtemplates_view.py +138 -0
- collective/documentgenerator/tests/test_config.py +106 -0
- collective/documentgenerator/tests/test_configurable_pod_template.py +383 -0
- collective/documentgenerator/tests/test_demo_profile.py +115 -0
- collective/documentgenerator/tests/test_events.py +169 -0
- collective/documentgenerator/tests/test_file.odt +0 -0
- collective/documentgenerator/tests/test_generation_view.py +652 -0
- collective/documentgenerator/tests/test_mailing.odt +0 -0
- collective/documentgenerator/tests/test_mailing_loop_template.py +48 -0
- collective/documentgenerator/tests/test_pod_template.py +178 -0
- collective/documentgenerator/tests/test_robot.py +26 -0
- collective/documentgenerator/tests/test_search_replace.py +419 -0
- collective/documentgenerator/tests/test_setup.py +49 -0
- collective/documentgenerator/tests/test_style_template.py +19 -0
- collective/documentgenerator/tests/test_sub_template.py +49 -0
- collective/documentgenerator/tests/test_templates_listing_view.py +91 -0
- collective/documentgenerator/tests/test_utils.py +244 -0
- collective/documentgenerator/tests/test_vocabulary.py +154 -0
- collective/documentgenerator/utils.py +396 -0
- collective/documentgenerator/viewlets/__init__.py +0 -0
- collective/documentgenerator/viewlets/batchactions.py +14 -0
- collective/documentgenerator/viewlets/configure.zcml +16 -0
- collective/documentgenerator/viewlets/generationlinks.pt +28 -0
- collective/documentgenerator/viewlets/generationlinks.py +58 -0
- collective.documentgenerator-3.46-py3.13-nspkg.pth +1 -0
- collective_documentgenerator-3.46.dist-info/METADATA +1142 -0
- collective_documentgenerator-3.46.dist-info/RECORD +176 -0
- collective_documentgenerator-3.46.dist-info/WHEEL +5 -0
- collective_documentgenerator-3.46.dist-info/entry_points.txt +5 -0
- collective_documentgenerator-3.46.dist-info/namespace_packages.txt +1 -0
- collective_documentgenerator-3.46.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,547 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
from collective.documentgenerator import _
|
|
3
|
+
from collective.documentgenerator.browser.controlpanel import COLUMN_MODIFIER_DESCR
|
|
4
|
+
from collective.documentgenerator.config import NEUTRAL_FORMATS
|
|
5
|
+
from collective.documentgenerator.config import ODS_FORMATS
|
|
6
|
+
from collective.documentgenerator.config import ODT_FORMATS
|
|
7
|
+
from collective.documentgenerator.config import POD_FORMATS
|
|
8
|
+
from collective.documentgenerator.content.style_template import StyleTemplate
|
|
9
|
+
from collective.documentgenerator.interfaces import IPODTemplateCondition
|
|
10
|
+
from collective.documentgenerator.interfaces import ITemplatesToMerge
|
|
11
|
+
from collective.documentgenerator.utils import compute_md5
|
|
12
|
+
from imio.helpers.content import add_to_annotation
|
|
13
|
+
from imio.helpers.content import del_from_annotation
|
|
14
|
+
from imio.helpers.content import get_from_annotation
|
|
15
|
+
from imio.helpers import HAS_PLONE_5_AND_MORE
|
|
16
|
+
from plone import api
|
|
17
|
+
from plone.autoform import directives as form
|
|
18
|
+
from plone.autoform.interfaces import IFormFieldProvider
|
|
19
|
+
from plone.dexterity.content import Item
|
|
20
|
+
from plone.formwidget.namedfile import NamedFileWidget
|
|
21
|
+
from plone.namedfile.field import NamedBlobFile
|
|
22
|
+
from plone.supermodel import model
|
|
23
|
+
from Products.CMFPlone.utils import safe_unicode
|
|
24
|
+
from z3c.form import validator
|
|
25
|
+
from z3c.form.browser.checkbox import CheckBoxFieldWidget
|
|
26
|
+
from z3c.form.browser.orderedselect import OrderedSelectFieldWidget
|
|
27
|
+
from z3c.form.browser.radio import RadioFieldWidget
|
|
28
|
+
from z3c.form.browser.select import SelectWidget
|
|
29
|
+
from zope import schema
|
|
30
|
+
from zope.component import provideAdapter
|
|
31
|
+
from zope.component import queryAdapter
|
|
32
|
+
from zope.component import queryMultiAdapter
|
|
33
|
+
from zope.interface import implementer
|
|
34
|
+
from zope.interface import Interface
|
|
35
|
+
from zope.interface import Invalid
|
|
36
|
+
from zope.interface import invariant
|
|
37
|
+
from zope.interface import provider
|
|
38
|
+
|
|
39
|
+
import copy
|
|
40
|
+
import logging
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
if HAS_PLONE_5_AND_MORE:
|
|
44
|
+
from collective.z3cform.datagridfield.datagridfield import DataGridFieldFactory
|
|
45
|
+
from collective.z3cform.datagridfield.row import DictRow
|
|
46
|
+
else:
|
|
47
|
+
from collective.z3cform.datagridfield import DataGridFieldFactory
|
|
48
|
+
from collective.z3cform.datagridfield import DictRow
|
|
49
|
+
|
|
50
|
+
logger = logging.getLogger('collective.documentgenerator: PODTemplate')
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class IPODTemplate(model.Schema):
|
|
54
|
+
"""
|
|
55
|
+
PODTemplate dexterity schema.
|
|
56
|
+
"""
|
|
57
|
+
|
|
58
|
+
model.primary('odt_file')
|
|
59
|
+
form.widget('odt_file', NamedFileWidget)
|
|
60
|
+
odt_file = NamedBlobFile(
|
|
61
|
+
title=_(u'ODT File'),
|
|
62
|
+
required=False,
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
form.omitted('initial_md5')
|
|
66
|
+
initial_md5 = schema.TextLine(description=u'Initially loaded file md5. Will be compared with os file md5.')
|
|
67
|
+
|
|
68
|
+
form.omitted('style_modification_md5')
|
|
69
|
+
style_modification_md5 = schema.TextLine(description=u'Working md5, stored when styles only update.')
|
|
70
|
+
|
|
71
|
+
form.widget('enabled', RadioFieldWidget)
|
|
72
|
+
enabled = schema.Bool(
|
|
73
|
+
title=_(u'Enabled'),
|
|
74
|
+
default=True,
|
|
75
|
+
required=False,
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
form.widget('style_template', SelectWidget)
|
|
79
|
+
style_template = schema.List(
|
|
80
|
+
title=_(u'Style template'),
|
|
81
|
+
description=_(u'Choose the style template to apply for this template.'),
|
|
82
|
+
value_type=schema.Choice(source='collective.documentgenerator.StyleTemplates'),
|
|
83
|
+
required=False,
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
@implementer(IPODTemplate)
|
|
88
|
+
class PODTemplate(Item):
|
|
89
|
+
"""
|
|
90
|
+
PODTemplate dexterity class.
|
|
91
|
+
"""
|
|
92
|
+
|
|
93
|
+
def get_file(self):
|
|
94
|
+
"""
|
|
95
|
+
Method used in renderer in order to retrieve the odt_file to be used.
|
|
96
|
+
:return: an odt_file field.
|
|
97
|
+
"""
|
|
98
|
+
return self.odt_file
|
|
99
|
+
|
|
100
|
+
def can_be_generated(self, context):
|
|
101
|
+
"""
|
|
102
|
+
Evaluate if the template can be generated on a given context.
|
|
103
|
+
"""
|
|
104
|
+
condition_obj = queryMultiAdapter((self, context), IPODTemplateCondition)
|
|
105
|
+
if condition_obj:
|
|
106
|
+
can_be_generated = condition_obj.evaluate()
|
|
107
|
+
return can_be_generated
|
|
108
|
+
|
|
109
|
+
def get_style_template(self):
|
|
110
|
+
"""
|
|
111
|
+
Return associated StylesTemplate from which styles will be imported
|
|
112
|
+
to the current PODTemplate.
|
|
113
|
+
"""
|
|
114
|
+
if not self.style_template:
|
|
115
|
+
return
|
|
116
|
+
|
|
117
|
+
catalog = api.portal.get_tool('portal_catalog')
|
|
118
|
+
style_template_brain = catalog(UID=self.style_template)
|
|
119
|
+
|
|
120
|
+
if style_template_brain:
|
|
121
|
+
return style_template_brain[0].getObject()
|
|
122
|
+
|
|
123
|
+
return None
|
|
124
|
+
|
|
125
|
+
def get_templates_to_merge(self):
|
|
126
|
+
"""
|
|
127
|
+
Return associated PODTemplates merged into the current PODTemplate
|
|
128
|
+
when it is rendered.
|
|
129
|
+
"""
|
|
130
|
+
templates_to_merge = queryAdapter(self, ITemplatesToMerge)
|
|
131
|
+
if templates_to_merge:
|
|
132
|
+
return templates_to_merge.get()
|
|
133
|
+
return {}
|
|
134
|
+
|
|
135
|
+
def get_available_formats(self):
|
|
136
|
+
"""
|
|
137
|
+
Returns formats in which current template may be generated.
|
|
138
|
+
"""
|
|
139
|
+
return ['odt', ]
|
|
140
|
+
|
|
141
|
+
@property
|
|
142
|
+
def current_md5(self):
|
|
143
|
+
md5 = u''
|
|
144
|
+
if self.odt_file:
|
|
145
|
+
md5 = safe_unicode(compute_md5(self.odt_file.data))
|
|
146
|
+
return md5
|
|
147
|
+
|
|
148
|
+
def has_been_modified(self):
|
|
149
|
+
"""
|
|
150
|
+
Current md5 will also be different from initial_md5 without user modification but if style modification.
|
|
151
|
+
Current_md5 will be equal to style_modification_md5 if style only update.
|
|
152
|
+
This last one will be updated after style modification only. See events
|
|
153
|
+
"""
|
|
154
|
+
return self.current_md5 != self.style_modification_md5
|
|
155
|
+
|
|
156
|
+
def get_column_modifier(self):
|
|
157
|
+
"""By default, return -1 meaning use global config value."""
|
|
158
|
+
return -1
|
|
159
|
+
|
|
160
|
+
def add_parent_pod_annotation(self):
|
|
161
|
+
return None
|
|
162
|
+
|
|
163
|
+
def del_parent_pod_annotation(self):
|
|
164
|
+
return None
|
|
165
|
+
|
|
166
|
+
def has_linked_template(self):
|
|
167
|
+
return False
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
class IMergeTemplatesRowSchema(Interface):
|
|
171
|
+
"""
|
|
172
|
+
Schema for DataGridField widget's row of field 'merge_templates'
|
|
173
|
+
"""
|
|
174
|
+
template = schema.Choice(
|
|
175
|
+
title=_(u'Template'),
|
|
176
|
+
vocabulary='collective.documentgenerator.MergeTemplates',
|
|
177
|
+
required=True,
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
pod_context_name = schema.TextLine(
|
|
181
|
+
title=_(u'POD context name'),
|
|
182
|
+
required=True,
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
form.widget('do_rendering', RadioFieldWidget)
|
|
186
|
+
do_rendering = schema.Bool(
|
|
187
|
+
title=_(u'Do rendering'),
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
class IContextVariablesRowSchema(Interface):
|
|
192
|
+
"""
|
|
193
|
+
Schema for DataGridField widget's row of field 'context_variables'
|
|
194
|
+
"""
|
|
195
|
+
name = schema.TextLine(
|
|
196
|
+
title=_(u'Variable name'),
|
|
197
|
+
required=True,
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
value = schema.TextLine(
|
|
201
|
+
title=_(u'Value'),
|
|
202
|
+
required=False,
|
|
203
|
+
)
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
class PodFormatsValidator(validator.SimpleFieldValidator):
|
|
207
|
+
""" z3c.form validator class for Pod formats """
|
|
208
|
+
|
|
209
|
+
def validate(self, value, force=False):
|
|
210
|
+
# thanks to widget, we get just-loaded file.filename.
|
|
211
|
+
widgets = self.view.widgets
|
|
212
|
+
current_filename = u""
|
|
213
|
+
for element in widgets.items():
|
|
214
|
+
if element[0] == 'odt_file':
|
|
215
|
+
current_filename = safe_unicode(element[1].filename)
|
|
216
|
+
if current_filename:
|
|
217
|
+
FORMATS_DICT = {'ods': ODS_FORMATS + NEUTRAL_FORMATS,
|
|
218
|
+
'odt': ODT_FORMATS + NEUTRAL_FORMATS}
|
|
219
|
+
extension = current_filename.split('.')[-1]
|
|
220
|
+
if extension not in FORMATS_DICT.keys():
|
|
221
|
+
extension = 'odt'
|
|
222
|
+
authorise_element_list = FORMATS_DICT[extension]
|
|
223
|
+
authorise_extension_list = [elem[0] for elem in authorise_element_list]
|
|
224
|
+
if not value:
|
|
225
|
+
raise Invalid(_(u"No format selected"))
|
|
226
|
+
for element in value:
|
|
227
|
+
if element not in authorise_extension_list:
|
|
228
|
+
elem = self.get_invalid_error(element)
|
|
229
|
+
error_message = _(
|
|
230
|
+
u"element_not_valid",
|
|
231
|
+
default=u"Element ${elem} is not valid for .${extension} template : \"${template}\"",
|
|
232
|
+
mapping={u"elem": elem, u"extension": extension, u"template": current_filename})
|
|
233
|
+
raise Invalid(error_message)
|
|
234
|
+
|
|
235
|
+
def get_invalid_error(self, extension):
|
|
236
|
+
for element in POD_FORMATS:
|
|
237
|
+
if element[0] == extension:
|
|
238
|
+
return element[1]
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
class IRenamePageStylesSchema(model.Schema):
|
|
242
|
+
""" This interface must be removed after migration to 8 is done ! """
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
@provider(IFormFieldProvider)
|
|
246
|
+
class IConfigurablePODTemplate(IPODTemplate):
|
|
247
|
+
"""
|
|
248
|
+
ConfigurablePODTemplate dexterity schema.
|
|
249
|
+
"""
|
|
250
|
+
|
|
251
|
+
form.order_before(is_reusable='enabled')
|
|
252
|
+
form.widget('is_reusable', RadioFieldWidget)
|
|
253
|
+
is_reusable = schema.Bool(
|
|
254
|
+
title=_(u'Reusable'),
|
|
255
|
+
description=_(u'Check if this POD Template can be reused by other POD Template'),
|
|
256
|
+
required=False,
|
|
257
|
+
default=False
|
|
258
|
+
)
|
|
259
|
+
|
|
260
|
+
form.order_before(pod_template_to_use='enabled')
|
|
261
|
+
pod_template_to_use = schema.Choice(
|
|
262
|
+
title=_(u'Select Existing POD Template to reuse'),
|
|
263
|
+
vocabulary='collective.documentgenerator.ExistingPODTemplate',
|
|
264
|
+
required=False,
|
|
265
|
+
default=None
|
|
266
|
+
)
|
|
267
|
+
|
|
268
|
+
form.widget('pod_formats', OrderedSelectFieldWidget, multiple='multiple', size=5)
|
|
269
|
+
pod_formats = schema.List(
|
|
270
|
+
title=_(u'Available formats'),
|
|
271
|
+
description=_(u'Select format in which the template will be generable.'),
|
|
272
|
+
value_type=schema.Choice(source='collective.documentgenerator.Formats'),
|
|
273
|
+
required=True,
|
|
274
|
+
default=['odt', ],
|
|
275
|
+
)
|
|
276
|
+
|
|
277
|
+
csv_field_delimiter = schema.Choice(
|
|
278
|
+
title=_(u'Field Delimiter for CSV format'),
|
|
279
|
+
description=_(u"Select the character to be used to separate fields into CSV files"),
|
|
280
|
+
vocabulary='collective.documentgenerator.CSVFieldDelimiter',
|
|
281
|
+
required=True,
|
|
282
|
+
default=u","
|
|
283
|
+
)
|
|
284
|
+
csv_string_delimiter = schema.Choice(
|
|
285
|
+
title=_(u'String Delimiter for CSV format'),
|
|
286
|
+
description=_(u"Select the character to be used to wrap around string values in CSV files"),
|
|
287
|
+
vocabulary='collective.documentgenerator.CSVStringDelimiter',
|
|
288
|
+
required=True,
|
|
289
|
+
default=u'"'
|
|
290
|
+
)
|
|
291
|
+
|
|
292
|
+
form.widget('pod_portal_types', CheckBoxFieldWidget, multiple='multiple', size=15)
|
|
293
|
+
pod_portal_types = schema.List(
|
|
294
|
+
title=_(u'Allowed portal types'),
|
|
295
|
+
description=_(u'Select for which content types the template will be available.'),
|
|
296
|
+
value_type=schema.Choice(source='collective.documentgenerator.PortalTypes'),
|
|
297
|
+
required=False,
|
|
298
|
+
)
|
|
299
|
+
|
|
300
|
+
form.widget('merge_templates', DataGridFieldFactory)
|
|
301
|
+
merge_templates = schema.List(
|
|
302
|
+
title=_(u'Templates to merge'),
|
|
303
|
+
required=False,
|
|
304
|
+
value_type=DictRow(
|
|
305
|
+
schema=IMergeTemplatesRowSchema,
|
|
306
|
+
required=False
|
|
307
|
+
),
|
|
308
|
+
default=[],
|
|
309
|
+
)
|
|
310
|
+
|
|
311
|
+
form.widget('context_variables', DataGridFieldFactory)
|
|
312
|
+
context_variables = schema.List(
|
|
313
|
+
title=_(u'Context variables.'),
|
|
314
|
+
description=_("These context variables are added to the odt_file context."),
|
|
315
|
+
required=False,
|
|
316
|
+
value_type=DictRow(
|
|
317
|
+
schema=IContextVariablesRowSchema,
|
|
318
|
+
required=False
|
|
319
|
+
),
|
|
320
|
+
)
|
|
321
|
+
|
|
322
|
+
mailing_loop_template = schema.Choice(
|
|
323
|
+
title=_(u'Mailing loop template'),
|
|
324
|
+
description=_(u'Choose the mailing loop template to apply for this template.'),
|
|
325
|
+
vocabulary='collective.documentgenerator.EnabledMailingLoopTemplates',
|
|
326
|
+
required=False,
|
|
327
|
+
)
|
|
328
|
+
|
|
329
|
+
column_modifier = schema.Choice(
|
|
330
|
+
title=_(u'Table column modifier'),
|
|
331
|
+
description=_(COLUMN_MODIFIER_DESCR),
|
|
332
|
+
vocabulary='collective.documentgenerator.PodColumnModifier',
|
|
333
|
+
required=True,
|
|
334
|
+
default=-1
|
|
335
|
+
)
|
|
336
|
+
|
|
337
|
+
@invariant
|
|
338
|
+
def validate_context_variables(data):
|
|
339
|
+
keys = []
|
|
340
|
+
forbidden = ['context', 'view', 'uids', 'brains', 'self']
|
|
341
|
+
to_check = copy.deepcopy(data.context_variables or [])
|
|
342
|
+
to_check.extend(copy.deepcopy(data.merge_templates or []))
|
|
343
|
+
|
|
344
|
+
for line in to_check:
|
|
345
|
+
value = ('name' in line and line['name']) or ('pod_context_name' in line and line['pod_context_name'])
|
|
346
|
+
|
|
347
|
+
if value in forbidden:
|
|
348
|
+
raise Invalid(_("You can't use one of these words: ${list}", mapping={'list': ', '.join(forbidden)}))
|
|
349
|
+
|
|
350
|
+
if value in keys:
|
|
351
|
+
raise Invalid(_("You have twice used the same name '${name}'", mapping={'name': value}))
|
|
352
|
+
else:
|
|
353
|
+
keys.append(value)
|
|
354
|
+
|
|
355
|
+
@invariant
|
|
356
|
+
def validate_pod_file(data):
|
|
357
|
+
if not (data.odt_file or data.pod_template_to_use):
|
|
358
|
+
raise Invalid(_("You must select an odt file or an existing pod template"), schema)
|
|
359
|
+
|
|
360
|
+
@invariant
|
|
361
|
+
def validate_pod_template_to_use(data):
|
|
362
|
+
if data.pod_template_to_use and (data.is_reusable or data.odt_file):
|
|
363
|
+
raise Invalid(_(
|
|
364
|
+
"You can't select a POD Template or set this template reusable "
|
|
365
|
+
"if you have chosen an existing POD Template."),
|
|
366
|
+
schema)
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
# Set conditions for which fields the validator class applies
|
|
370
|
+
validator.WidgetValidatorDiscriminators(PodFormatsValidator, field=IConfigurablePODTemplate['pod_formats'])
|
|
371
|
+
|
|
372
|
+
# Register the validator so it will be looked up by z3c.form machinery
|
|
373
|
+
provideAdapter(PodFormatsValidator)
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
@implementer(IConfigurablePODTemplate)
|
|
377
|
+
class ConfigurablePODTemplate(PODTemplate):
|
|
378
|
+
"""
|
|
379
|
+
ConfigurablePODTemplate dexterity class.
|
|
380
|
+
"""
|
|
381
|
+
|
|
382
|
+
parent_pod_annotation_key = 'linked_child_templates'
|
|
383
|
+
|
|
384
|
+
def get_pod_template_to_use(self):
|
|
385
|
+
"""
|
|
386
|
+
Method used in renderer in order to retrieve the pod_template to be used.
|
|
387
|
+
:return: the used object.
|
|
388
|
+
"""
|
|
389
|
+
if self.pod_template_to_use:
|
|
390
|
+
# make sure we get the POD template holding the odt_file
|
|
391
|
+
# by searching it unrestrictedly
|
|
392
|
+
catalog = api.portal.get_tool('portal_catalog')
|
|
393
|
+
brains = catalog.unrestrictedSearchResults(UID=self.pod_template_to_use)
|
|
394
|
+
if brains:
|
|
395
|
+
return brains[0]._unrestrictedGetObject()
|
|
396
|
+
return None
|
|
397
|
+
|
|
398
|
+
def get_file(self):
|
|
399
|
+
"""
|
|
400
|
+
Method used in renderer in order to retrieve the odt_file to be used.
|
|
401
|
+
:return: an odt_file field.
|
|
402
|
+
"""
|
|
403
|
+
pttu = self.get_pod_template_to_use()
|
|
404
|
+
if pttu:
|
|
405
|
+
return pttu.odt_file
|
|
406
|
+
return self.odt_file
|
|
407
|
+
|
|
408
|
+
def get_filename(self):
|
|
409
|
+
"""Add accessor for file.filename as it is private by default in plone.namedfile. """
|
|
410
|
+
return self.get_file().filename
|
|
411
|
+
|
|
412
|
+
def __setattr__(self, key, value):
|
|
413
|
+
if key == 'pod_template_to_use':
|
|
414
|
+
if hasattr(self, 'pod_template_to_use') and self.pod_template_to_use != value:
|
|
415
|
+
if self.pod_template_to_use:
|
|
416
|
+
self.del_parent_pod_annotation()
|
|
417
|
+
super(ConfigurablePODTemplate, self).__setattr__(key, value)
|
|
418
|
+
self.add_parent_pod_annotation()
|
|
419
|
+
else:
|
|
420
|
+
super(ConfigurablePODTemplate, self).__setattr__(key, value)
|
|
421
|
+
|
|
422
|
+
def has_linked_template(self):
|
|
423
|
+
return self.pod_template_to_use is not None
|
|
424
|
+
|
|
425
|
+
def set_merge_templates(self, pod_template, pod_context_name, do_rendering=True, position=-1):
|
|
426
|
+
old_value = list(self.merge_templates)
|
|
427
|
+
newline = {'template': pod_template.UID(), 'pod_context_name': pod_context_name, 'do_rendering': do_rendering}
|
|
428
|
+
if position >= 0:
|
|
429
|
+
old_value.insert(position, newline)
|
|
430
|
+
else:
|
|
431
|
+
old_value.append(newline)
|
|
432
|
+
self.merge_templates = old_value
|
|
433
|
+
|
|
434
|
+
def get_templates_to_merge(self):
|
|
435
|
+
"""
|
|
436
|
+
Return associated PODTemplates merged into the current PODTemplate
|
|
437
|
+
when it is rendered.
|
|
438
|
+
"""
|
|
439
|
+
catalog = api.portal.get_tool('portal_catalog')
|
|
440
|
+
pod_context = {}
|
|
441
|
+
|
|
442
|
+
if self.merge_templates:
|
|
443
|
+
for line in self.merge_templates:
|
|
444
|
+
pod_template = catalog(UID=line['template'])[0].getObject()
|
|
445
|
+
pod_context[line['pod_context_name'].encode('utf-8')] = (pod_template, line['do_rendering'])
|
|
446
|
+
|
|
447
|
+
return pod_context
|
|
448
|
+
|
|
449
|
+
def get_available_formats(self):
|
|
450
|
+
"""
|
|
451
|
+
Returns formats in which current template may be generated.
|
|
452
|
+
"""
|
|
453
|
+
return self.pod_formats
|
|
454
|
+
|
|
455
|
+
def get_context_variables(self):
|
|
456
|
+
"""
|
|
457
|
+
Returns context_variables as dict
|
|
458
|
+
"""
|
|
459
|
+
ret = {}
|
|
460
|
+
for line in self.context_variables or []:
|
|
461
|
+
# Simple boolean conversion actually implemented
|
|
462
|
+
# May be improved with ZPublisher.Converters, managing boolean, int, date, string, text, ...
|
|
463
|
+
# Those last values in a list box with string as default value
|
|
464
|
+
val = line['value']
|
|
465
|
+
if val == 'True':
|
|
466
|
+
val = True
|
|
467
|
+
elif val == 'False':
|
|
468
|
+
val = False
|
|
469
|
+
ret[line['name']] = val
|
|
470
|
+
return ret
|
|
471
|
+
|
|
472
|
+
def get_column_modifier(self):
|
|
473
|
+
return self.column_modifier
|
|
474
|
+
|
|
475
|
+
def add_parent_pod_annotation(self):
|
|
476
|
+
if self.pod_template_to_use:
|
|
477
|
+
try:
|
|
478
|
+
add_to_annotation(ConfigurablePODTemplate.parent_pod_annotation_key, self.UID(),
|
|
479
|
+
uid=self.pod_template_to_use)
|
|
480
|
+
except TypeError:
|
|
481
|
+
pass
|
|
482
|
+
# object has no UID yet. It will be retried when IObjectCreatedEvent will be triggered
|
|
483
|
+
# for some reasons, isinstance(self, IUUID) always returns False
|
|
484
|
+
|
|
485
|
+
def del_parent_pod_annotation(self):
|
|
486
|
+
if hasattr(self, 'pod_template_to_use') and self.pod_template_to_use:
|
|
487
|
+
del_from_annotation(ConfigurablePODTemplate.parent_pod_annotation_key, self.UID(),
|
|
488
|
+
uid=self.pod_template_to_use)
|
|
489
|
+
|
|
490
|
+
def get_children_pod_template(self):
|
|
491
|
+
"""
|
|
492
|
+
@see plone.api.content.get
|
|
493
|
+
@see imio.helpers.content.get_from_annotation
|
|
494
|
+
@see imio.helpers.content.del_from_annotation
|
|
495
|
+
:return: a list containing the children templates.
|
|
496
|
+
|
|
497
|
+
Handles the case when the uid doesn't match any object by deleting the uid from anotation.
|
|
498
|
+
"""
|
|
499
|
+
res = set()
|
|
500
|
+
to_delete = set()
|
|
501
|
+
annotated = get_from_annotation(ConfigurablePODTemplate.parent_pod_annotation_key, self)
|
|
502
|
+
if annotated:
|
|
503
|
+
for uid in annotated:
|
|
504
|
+
child = api.content.get(UID=uid)
|
|
505
|
+
if child:
|
|
506
|
+
res.add(child)
|
|
507
|
+
else:
|
|
508
|
+
# child doesn't exist anymore. api.content.get returned None
|
|
509
|
+
to_delete.add(uid)
|
|
510
|
+
for uid in to_delete:
|
|
511
|
+
del_from_annotation(ConfigurablePODTemplate.parent_pod_annotation_key, uid, obj=self)
|
|
512
|
+
return res
|
|
513
|
+
|
|
514
|
+
|
|
515
|
+
class ISubTemplate(IPODTemplate):
|
|
516
|
+
"""
|
|
517
|
+
PODTemplate used only a sub template to merge
|
|
518
|
+
"""
|
|
519
|
+
|
|
520
|
+
|
|
521
|
+
@implementer(ISubTemplate)
|
|
522
|
+
class SubTemplate(PODTemplate):
|
|
523
|
+
"""
|
|
524
|
+
PODTemplate used only a sub template to merge
|
|
525
|
+
"""
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
class IMailingLoopTemplate(IPODTemplate):
|
|
529
|
+
"""
|
|
530
|
+
PODTemplate used only to loop for mailing
|
|
531
|
+
"""
|
|
532
|
+
|
|
533
|
+
|
|
534
|
+
@implementer(IMailingLoopTemplate)
|
|
535
|
+
class MailingLoopTemplate(PODTemplate):
|
|
536
|
+
"""
|
|
537
|
+
PODTemplate used only to loop for mailing
|
|
538
|
+
"""
|
|
539
|
+
|
|
540
|
+
|
|
541
|
+
POD_TEMPLATE_TYPES = {
|
|
542
|
+
PODTemplate.__name__: PODTemplate,
|
|
543
|
+
ConfigurablePODTemplate.__name__: ConfigurablePODTemplate,
|
|
544
|
+
SubTemplate.__name__: SubTemplate,
|
|
545
|
+
MailingLoopTemplate.__name__: MailingLoopTemplate,
|
|
546
|
+
StyleTemplate.__name__: StyleTemplate,
|
|
547
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
from collective.documentgenerator import _
|
|
4
|
+
from collective.documentgenerator.utils import compute_md5
|
|
5
|
+
from plone.autoform import directives as form
|
|
6
|
+
from plone.dexterity.content import Item
|
|
7
|
+
from plone.formwidget.namedfile import NamedFileWidget
|
|
8
|
+
from plone.namedfile.field import NamedBlobFile
|
|
9
|
+
from plone.supermodel import model
|
|
10
|
+
from Products.CMFPlone.utils import safe_unicode
|
|
11
|
+
from zope import schema
|
|
12
|
+
from zope.interface import implementer
|
|
13
|
+
|
|
14
|
+
import logging
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
logger = logging.getLogger('collective.documentgenerator: StyleTemplate')
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class IStyleTemplate(model.Schema):
|
|
21
|
+
"""
|
|
22
|
+
StyleTemplate dexterity schema.
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
model.primary('odt_file')
|
|
26
|
+
form.widget('odt_file', NamedFileWidget)
|
|
27
|
+
odt_file = NamedBlobFile(
|
|
28
|
+
title=_(u'ODT File'),
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
form.omitted('initial_md5')
|
|
32
|
+
initial_md5 = schema.TextLine(description=u'Initially loaded file md5. Will be compared with os file md5.')
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@implementer(IStyleTemplate)
|
|
36
|
+
class StyleTemplate(Item):
|
|
37
|
+
"""
|
|
38
|
+
StyleTemplate dexterity class.
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
@property
|
|
42
|
+
def current_md5(self):
|
|
43
|
+
md5 = u''
|
|
44
|
+
if self.odt_file:
|
|
45
|
+
md5 = safe_unicode(compute_md5(self.odt_file.data))
|
|
46
|
+
return md5
|
|
47
|
+
|
|
48
|
+
def has_been_modified(self):
|
|
49
|
+
"""
|
|
50
|
+
Current md5 will be different from initial_md5 if user modification.
|
|
51
|
+
"""
|
|
52
|
+
return self.current_md5 != self.initial_md5
|