collective.documentgenerator 4.0__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/DX_renderer.py +51 -0
- collective/documentgenerator/__init__.py +11 -0
- collective/documentgenerator/adapters.py +30 -0
- collective/documentgenerator/browser/__init__.py +0 -0
- collective/documentgenerator/browser/actionspanel.py +19 -0
- collective/documentgenerator/browser/check_pod_templates.pt +86 -0
- collective/documentgenerator/browser/children_pod_template.pt +27 -0
- collective/documentgenerator/browser/configure.zcml +217 -0
- collective/documentgenerator/browser/controlpanel.py +165 -0
- collective/documentgenerator/browser/generation_view.py +613 -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 +1232 -0
- collective/documentgenerator/browser/static/xls.svg +159 -0
- collective/documentgenerator/browser/static/xlsx.svg +48 -0
- collective/documentgenerator/browser/table.py +326 -0
- collective/documentgenerator/browser/templates_listing.pt +29 -0
- collective/documentgenerator/browser/views.py +366 -0
- collective/documentgenerator/config.py +174 -0
- collective/documentgenerator/configure.zcml +51 -0
- collective/documentgenerator/content/__init__.py +0 -0
- collective/documentgenerator/content/condition.py +66 -0
- collective/documentgenerator/content/conditions.zcml +30 -0
- collective/documentgenerator/content/configure.zcml +18 -0
- collective/documentgenerator/content/document_factory.py +73 -0
- collective/documentgenerator/content/file_representation.py +70 -0
- collective/documentgenerator/content/file_representation.zcml +29 -0
- collective/documentgenerator/content/merge_templates.py +15 -0
- collective/documentgenerator/content/merge_templates.zcml +11 -0
- collective/documentgenerator/content/pod_template.py +601 -0
- collective/documentgenerator/content/style_template.py +54 -0
- collective/documentgenerator/content/vocabulary.py +344 -0
- collective/documentgenerator/content/vocabulary.zcml +105 -0
- collective/documentgenerator/demo/__init__.py +0 -0
- collective/documentgenerator/demo/configure.zcml +18 -0
- collective/documentgenerator/demo/helper.py +170 -0
- collective/documentgenerator/events/__init__.py +0 -0
- collective/documentgenerator/events/configure.zcml +44 -0
- collective/documentgenerator/events/pod_templates_events.py +66 -0
- collective/documentgenerator/events/styles_events.py +151 -0
- collective/documentgenerator/helper/__init__.py +7 -0
- collective/documentgenerator/helper/base.py +334 -0
- collective/documentgenerator/helper/configure.zcml +34 -0
- collective/documentgenerator/helper/dexterity.py +178 -0
- collective/documentgenerator/interfaces.py +166 -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 +52 -0
- collective/documentgenerator/migrations/migrate_to_12.py +32 -0
- collective/documentgenerator/migrations/migrate_to_13.py +35 -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 +34 -0
- collective/documentgenerator/migrations/migrate_to_8.py +36 -0
- collective/documentgenerator/migrations/migrate_to_9.py +50 -0
- collective/documentgenerator/profiles/base/browserlayer.xml +6 -0
- collective/documentgenerator/profiles/base/controlpanel.xml +21 -0
- collective/documentgenerator/profiles/base/metadata.xml +8 -0
- collective/documentgenerator/profiles/base/registry.xml +48 -0
- collective/documentgenerator/profiles/base/types/ConfigurablePODTemplate.xml +69 -0
- collective/documentgenerator/profiles/base/types/MailingLoopTemplate.xml +68 -0
- collective/documentgenerator/profiles/base/types/PODTemplate.xml +68 -0
- collective/documentgenerator/profiles/base/types/StyleTemplate.xml +68 -0
- collective/documentgenerator/profiles/base/types/SubTemplate.xml +68 -0
- collective/documentgenerator/profiles/base/types.xml +22 -0
- collective/documentgenerator/profiles/base/viewlets.xml +10 -0
- collective/documentgenerator/profiles/demo/browserlayer.xml +6 -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 +14 -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/testing/metadata.xml +7 -0
- collective/documentgenerator/profiles/testing/types/member.xml +114 -0
- collective/documentgenerator/profiles/testing/types.xml +9 -0
- collective/documentgenerator/profiles/uninstall/browserlayer.xml +7 -0
- collective/documentgenerator/profiles/uninstall/controlpanel.xml +21 -0
- collective/documentgenerator/profiles/uninstall/metadata.xml +4 -0
- collective/documentgenerator/profiles/uninstall/registry.xml +14 -0
- collective/documentgenerator/profiles/uninstall/types.xml +27 -0
- collective/documentgenerator/profiles/uninstall/viewlets.xml +8 -0
- collective/documentgenerator/profiles.zcml +209 -0
- collective/documentgenerator/renderer.zcml +36 -0
- collective/documentgenerator/search_replace/__init__.py +0 -0
- collective/documentgenerator/search_replace/configure.zcml +21 -0
- collective/documentgenerator/search_replace/pod_template.py +161 -0
- collective/documentgenerator/search_replace/search_result_form.pt +76 -0
- collective/documentgenerator/search_replace/searchreplace_panel.pt +31 -0
- collective/documentgenerator/search_replace/searchreplace_panel.py +274 -0
- collective/documentgenerator/setuphandlers.py +297 -0
- collective/documentgenerator/testing.py +278 -0
- collective/documentgenerator/testing.zcml +17 -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_DX_helper_view.py +398 -0
- collective/documentgenerator/tests/test_base_helper_view.py +216 -0
- collective/documentgenerator/tests/test_check_podtemplates_view.py +138 -0
- collective/documentgenerator/tests/test_config.py +119 -0
- collective/documentgenerator/tests/test_configurable_pod_template.py +467 -0
- collective/documentgenerator/tests/test_demo_profile.py +121 -0
- collective/documentgenerator/tests/test_events.py +187 -0
- collective/documentgenerator/tests/test_generation_view.py +680 -0
- collective/documentgenerator/tests/test_mailing_loop_template.py +48 -0
- collective/documentgenerator/tests/test_pod_template.py +190 -0
- collective/documentgenerator/tests/test_robot.py +26 -0
- collective/documentgenerator/tests/test_search_replace.py +485 -0
- collective/documentgenerator/tests/test_setup.py +77 -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 +120 -0
- collective/documentgenerator/tests/test_utils.py +205 -0
- collective/documentgenerator/tests/test_vocabulary.py +169 -0
- collective/documentgenerator/utils.py +245 -0
- collective/documentgenerator/viewlets/__init__.py +0 -0
- collective/documentgenerator/viewlets/batchactions.py +14 -0
- collective/documentgenerator/viewlets/configure.zcml +17 -0
- collective/documentgenerator/viewlets/generationlinks.pt +46 -0
- collective/documentgenerator/viewlets/generationlinks.py +67 -0
- collective.documentgenerator-4.0-py3.12-nspkg.pth +1 -0
- collective_documentgenerator-4.0.dist-info/METADATA +1136 -0
- collective_documentgenerator-4.0.dist-info/RECORD +167 -0
- collective_documentgenerator-4.0.dist-info/WHEEL +5 -0
- collective_documentgenerator-4.0.dist-info/entry_points.txt +2 -0
- collective_documentgenerator-4.0.dist-info/namespace_packages.txt +1 -0
- collective_documentgenerator-4.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
from collective.documentgenerator import _
|
|
4
|
+
from collective.documentgenerator.config import get_column_modifier
|
|
5
|
+
from collective.documentgenerator.config import get_csv_field_delimiters
|
|
6
|
+
from collective.documentgenerator.config import get_csv_string_delimiters
|
|
7
|
+
from collective.documentgenerator.config import POD_FORMATS
|
|
8
|
+
from collective.documentgenerator.content.pod_template import IConfigurablePODTemplate
|
|
9
|
+
from collective.documentgenerator.content.pod_template import IPODTemplate
|
|
10
|
+
from collective.documentgenerator.utils import get_site_root_relative_path
|
|
11
|
+
from plone import api
|
|
12
|
+
from Products.CMFPlone.utils import safe_unicode
|
|
13
|
+
from z3c.form.i18n import MessageFactory as _z3c_form
|
|
14
|
+
from z3c.form.interfaces import IContextAware
|
|
15
|
+
from z3c.form.interfaces import IDataManager
|
|
16
|
+
from z3c.form.term import MissingChoiceTermsVocabulary
|
|
17
|
+
from z3c.form.term import MissingTermsMixin
|
|
18
|
+
from zope.component import getMultiAdapter
|
|
19
|
+
from zope.component import getUtility
|
|
20
|
+
from zope.component import queryUtility
|
|
21
|
+
from zope.schema.interfaces import IVocabularyFactory
|
|
22
|
+
from zope.schema.vocabulary import SimpleTerm
|
|
23
|
+
from zope.schema.vocabulary import SimpleVocabulary
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class FormatsVocabularyFactory(object):
|
|
27
|
+
"""
|
|
28
|
+
Vocabulary factory for 'pod_formats' field.
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
def __call__(self, context):
|
|
32
|
+
vocabulary = SimpleVocabulary(
|
|
33
|
+
[
|
|
34
|
+
SimpleTerm(pod_format, pod_format, label)
|
|
35
|
+
for pod_format, label in POD_FORMATS
|
|
36
|
+
]
|
|
37
|
+
)
|
|
38
|
+
return vocabulary
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class PortalTypesVocabularyFactory(object):
|
|
42
|
+
"""
|
|
43
|
+
Vocabulary factory for 'pod_portal_types' field.
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
def __call__(self, context):
|
|
47
|
+
control_panel = api.portal.get_tool("portal_types")
|
|
48
|
+
all_portaltypes = control_panel.listContentTypes()
|
|
49
|
+
vocabulary = SimpleVocabulary([SimpleTerm(p, p, p) for p in all_portaltypes])
|
|
50
|
+
return vocabulary
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class StyleTemplatesVocabularyFactory(object):
|
|
54
|
+
"""
|
|
55
|
+
Vocabulary factory for 'style_template' field.
|
|
56
|
+
"""
|
|
57
|
+
|
|
58
|
+
def __call__(self, context):
|
|
59
|
+
catalog = api.portal.get_tool("portal_catalog")
|
|
60
|
+
style_template_brains = catalog(portal_type="StyleTemplate")
|
|
61
|
+
voc_terms = [SimpleTerm("--NOVALUE--", "--NOVALUE--", _z3c_form("No value"))]
|
|
62
|
+
|
|
63
|
+
for brain in style_template_brains:
|
|
64
|
+
voc_terms.append(
|
|
65
|
+
SimpleTerm(brain.UID, brain.UID, self._renderTermTitle(brain))
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
vocabulary = SimpleVocabulary(voc_terms)
|
|
69
|
+
|
|
70
|
+
return vocabulary
|
|
71
|
+
|
|
72
|
+
def _renderTermTitle(self, brain):
|
|
73
|
+
return brain.Title
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class MergeTemplatesVocabularyFactory(object):
|
|
77
|
+
"""
|
|
78
|
+
Vocabulary factory for 'merge_templates' field.
|
|
79
|
+
"""
|
|
80
|
+
|
|
81
|
+
def _portal_types(self):
|
|
82
|
+
return ["PODTemplate", "SubTemplate"]
|
|
83
|
+
|
|
84
|
+
def _render_term_title(self, brain):
|
|
85
|
+
return brain.Title
|
|
86
|
+
|
|
87
|
+
def __call__(self, context):
|
|
88
|
+
catalog = api.portal.get_tool("portal_catalog")
|
|
89
|
+
pod_templates = catalog(
|
|
90
|
+
portal_type=self._portal_types(),
|
|
91
|
+
sort_on="sortable_title",
|
|
92
|
+
sort_order="ascending",
|
|
93
|
+
)
|
|
94
|
+
voc_terms = [SimpleTerm("--NOVALUE--", "--NOVALUE--", _z3c_form("No value"))]
|
|
95
|
+
|
|
96
|
+
for brain in pod_templates:
|
|
97
|
+
voc_terms.append(
|
|
98
|
+
SimpleTerm(brain.UID, brain.UID, self._render_term_title(brain))
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
vocabulary = SimpleVocabulary(voc_terms)
|
|
102
|
+
|
|
103
|
+
return vocabulary
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
class ConfigColumnModifierVocabularyFactory(object):
|
|
107
|
+
"""
|
|
108
|
+
Vocabulary factory for control panel 'column_modifier' field.
|
|
109
|
+
"""
|
|
110
|
+
|
|
111
|
+
def __call__(self, context):
|
|
112
|
+
voc_terms = [
|
|
113
|
+
SimpleTerm("disabled", 0, _("Disabled")),
|
|
114
|
+
SimpleTerm("nothing", 1, _("Nothing")),
|
|
115
|
+
SimpleTerm("optimize", 2, _("Optimize")),
|
|
116
|
+
SimpleTerm("distribute", 3, _("Distribute")),
|
|
117
|
+
]
|
|
118
|
+
|
|
119
|
+
return SimpleVocabulary(voc_terms)
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
class PodColumnModifierVocabularyFactory(object):
|
|
123
|
+
"""
|
|
124
|
+
Vocabulary factory for pod template 'column_modifier' field.
|
|
125
|
+
"""
|
|
126
|
+
|
|
127
|
+
def __call__(self, context):
|
|
128
|
+
# adapt first term value depending on global configuration value
|
|
129
|
+
# get term from global value vocabulary
|
|
130
|
+
vocabulary = queryUtility(
|
|
131
|
+
IVocabularyFactory, "collective.documentgenerator.ConfigColumnModifier"
|
|
132
|
+
)
|
|
133
|
+
voc = vocabulary(context)
|
|
134
|
+
global_value = _(voc.getTerm(get_column_modifier()).title)
|
|
135
|
+
global_value_term = _(
|
|
136
|
+
"Global value (${global_value})", mapping={"global_value": global_value}
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
voc_terms = [
|
|
140
|
+
SimpleTerm(-1, -1, global_value_term),
|
|
141
|
+
SimpleTerm("disabled", 0, _("Force disabled")),
|
|
142
|
+
SimpleTerm("nothing", 1, _("Force nothing")),
|
|
143
|
+
SimpleTerm("optimize", 2, _("Force optimize")),
|
|
144
|
+
SimpleTerm("distribute", 3, _("Force distribute")),
|
|
145
|
+
]
|
|
146
|
+
|
|
147
|
+
return SimpleVocabulary(voc_terms)
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def get_mailing_loop_templates(enabled_only=True):
|
|
151
|
+
brains = []
|
|
152
|
+
catalog = api.portal.get_tool("portal_catalog")
|
|
153
|
+
|
|
154
|
+
for brain in catalog(portal_type="MailingLoopTemplate"):
|
|
155
|
+
if enabled_only and not brain.getObject().enabled:
|
|
156
|
+
continue
|
|
157
|
+
brains.append(brain)
|
|
158
|
+
return brains
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
class MailingLoopTemplatesEnabledVocabularyFactory(object):
|
|
162
|
+
"""
|
|
163
|
+
Vocabulary factory for 'mailing_loop_template' field.
|
|
164
|
+
"""
|
|
165
|
+
|
|
166
|
+
def __call__(self, context):
|
|
167
|
+
voc_terms = []
|
|
168
|
+
|
|
169
|
+
for brain in get_mailing_loop_templates(enabled_only=True):
|
|
170
|
+
voc_terms.append(
|
|
171
|
+
SimpleTerm(brain.UID, brain.UID, self._renderTermTitle(brain))
|
|
172
|
+
)
|
|
173
|
+
return SimpleVocabulary(voc_terms)
|
|
174
|
+
|
|
175
|
+
def _renderTermTitle(self, brain):
|
|
176
|
+
return brain.Title
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
class MailingLoopTemplatesAllVocabularyFactory(object):
|
|
180
|
+
"""
|
|
181
|
+
Vocabulary factory with all mailing_loop_template.
|
|
182
|
+
"""
|
|
183
|
+
|
|
184
|
+
def __call__(self, context):
|
|
185
|
+
voc_terms = []
|
|
186
|
+
|
|
187
|
+
for brain in get_mailing_loop_templates(enabled_only=False):
|
|
188
|
+
voc_terms.append(
|
|
189
|
+
SimpleTerm(brain.UID, brain.UID, self._renderTermTitle(brain))
|
|
190
|
+
)
|
|
191
|
+
|
|
192
|
+
return SimpleVocabulary(voc_terms)
|
|
193
|
+
|
|
194
|
+
def _renderTermTitle(self, brain):
|
|
195
|
+
return brain.Title
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
class ExistingPODTemplateFactory(object):
|
|
199
|
+
"""
|
|
200
|
+
Vocabulary factory with all existing_pod_templates.
|
|
201
|
+
"""
|
|
202
|
+
|
|
203
|
+
def __call__(self, context):
|
|
204
|
+
voc_terms = []
|
|
205
|
+
|
|
206
|
+
for brain in self._get_existing_pod_templates(context, enabled_only=False):
|
|
207
|
+
voc_terms.append(
|
|
208
|
+
SimpleTerm(brain.UID, brain.UID, self._renderTermTitle(brain))
|
|
209
|
+
)
|
|
210
|
+
|
|
211
|
+
return SimpleVocabulary(voc_terms)
|
|
212
|
+
|
|
213
|
+
def _get_existing_pod_templates(self, context, enabled_only=False):
|
|
214
|
+
brains = []
|
|
215
|
+
catalog = api.portal.get_tool("portal_catalog")
|
|
216
|
+
for brain in catalog(object_provides=IConfigurablePODTemplate.__identifier__):
|
|
217
|
+
template = brain.getObject()
|
|
218
|
+
if enabled_only and not template.enabled:
|
|
219
|
+
continue
|
|
220
|
+
if template.is_reusable and template != context:
|
|
221
|
+
brains.append(brain)
|
|
222
|
+
return brains
|
|
223
|
+
|
|
224
|
+
def _renderTermTitle(self, brain):
|
|
225
|
+
return u"{} -> {}".format(
|
|
226
|
+
safe_unicode(brain.Title), safe_unicode(brain.getObject().odt_file.filename)
|
|
227
|
+
)
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
class AllPODTemplateWithFileVocabularyFactory(object):
|
|
231
|
+
"""
|
|
232
|
+
Vocabulary factory with all existing pod_templates.
|
|
233
|
+
"""
|
|
234
|
+
|
|
235
|
+
def __call__(self, context):
|
|
236
|
+
voc_terms = [SimpleTerm("all", "all", _("All POD templates"))]
|
|
237
|
+
|
|
238
|
+
for brain in self._get_all_pod_templates_with_file():
|
|
239
|
+
voc_terms.append(
|
|
240
|
+
SimpleTerm(brain.UID, brain.UID, self._renderTermTitle(brain))
|
|
241
|
+
)
|
|
242
|
+
|
|
243
|
+
return SimpleVocabulary(voc_terms)
|
|
244
|
+
|
|
245
|
+
def _get_all_pod_templates_with_file(self):
|
|
246
|
+
brains = []
|
|
247
|
+
catalog = api.portal.get_tool("portal_catalog")
|
|
248
|
+
for brain in catalog(object_provides=IPODTemplate.__identifier__):
|
|
249
|
+
template = brain.getObject()
|
|
250
|
+
if hasattr(template, "odt_file") and template.odt_file:
|
|
251
|
+
brains.append(brain)
|
|
252
|
+
return brains
|
|
253
|
+
|
|
254
|
+
def _renderTermTitle(self, brain):
|
|
255
|
+
return u"{} ({})".format(
|
|
256
|
+
safe_unicode(get_site_root_relative_path(brain.getObject())),
|
|
257
|
+
safe_unicode(brain.Title),
|
|
258
|
+
)
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
class CSVFieldDelimiterFactory(object):
|
|
262
|
+
def __call__(self, context):
|
|
263
|
+
voc_terms = []
|
|
264
|
+
for title, delimiter in get_csv_field_delimiters().items():
|
|
265
|
+
voc_terms.append(SimpleTerm(delimiter, title, _(title)))
|
|
266
|
+
|
|
267
|
+
return SimpleVocabulary(voc_terms)
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
class CSVStringDelimiterFactory(object):
|
|
271
|
+
def __call__(self, context):
|
|
272
|
+
voc_terms = []
|
|
273
|
+
for title, delimiter in get_csv_string_delimiters().items():
|
|
274
|
+
voc_terms.append(SimpleTerm(delimiter, title, _(title)))
|
|
275
|
+
|
|
276
|
+
return SimpleVocabulary(voc_terms)
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
#########################
|
|
280
|
+
# vocabularies adapters #
|
|
281
|
+
#########################
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
class MissingTerms(MissingTermsMixin):
|
|
285
|
+
def getTerm(self, value):
|
|
286
|
+
try:
|
|
287
|
+
return super(MissingTermsMixin, self).getTerm(value)
|
|
288
|
+
except LookupError:
|
|
289
|
+
try:
|
|
290
|
+
return self.complete_voc().getTerm(value)
|
|
291
|
+
except LookupError:
|
|
292
|
+
pass
|
|
293
|
+
if IContextAware.providedBy(self.widget) and not self.widget.ignoreContext:
|
|
294
|
+
curValue = getMultiAdapter(
|
|
295
|
+
(self.widget.context, self.field), IDataManager
|
|
296
|
+
).query()
|
|
297
|
+
if curValue == value:
|
|
298
|
+
return self._makeMissingTerm(value)
|
|
299
|
+
raise
|
|
300
|
+
|
|
301
|
+
def getTermByToken(self, token):
|
|
302
|
+
try:
|
|
303
|
+
return super(MissingTermsMixin, self).getTermByToken(token)
|
|
304
|
+
except LookupError:
|
|
305
|
+
try:
|
|
306
|
+
return self.complete_voc().getTermByToken(token)
|
|
307
|
+
except LookupError:
|
|
308
|
+
pass
|
|
309
|
+
if IContextAware.providedBy(self.widget) and not self.widget.ignoreContext:
|
|
310
|
+
value = getMultiAdapter(
|
|
311
|
+
(self.widget.context, self.field), IDataManager
|
|
312
|
+
).query()
|
|
313
|
+
term = self._makeMissingTerm(value)
|
|
314
|
+
if term.token == token:
|
|
315
|
+
return term
|
|
316
|
+
raise LookupError(token)
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
class PTMCTV(MissingChoiceTermsVocabulary, MissingTerms):
|
|
320
|
+
"""Managing missing terms for IImioDmsIncomingMail."""
|
|
321
|
+
|
|
322
|
+
def complete_voc(self):
|
|
323
|
+
if self.field.getName() == "mailing_loop_template":
|
|
324
|
+
return getUtility(
|
|
325
|
+
IVocabularyFactory,
|
|
326
|
+
"collective.documentgenerator.AllMailingLoopTemplates",
|
|
327
|
+
)(self.context)
|
|
328
|
+
else:
|
|
329
|
+
return SimpleVocabulary([])
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
class ConfigStreamVocabularyFactory(object):
|
|
333
|
+
"""
|
|
334
|
+
Vocabulary factory for control panel 'use_stream' field.
|
|
335
|
+
"""
|
|
336
|
+
|
|
337
|
+
def __call__(self, context):
|
|
338
|
+
voc_terms = [
|
|
339
|
+
SimpleTerm(u"auto", u"auto", _("Auto")),
|
|
340
|
+
SimpleTerm(True, True, _("Yes")),
|
|
341
|
+
SimpleTerm(False, False, _("No")),
|
|
342
|
+
]
|
|
343
|
+
|
|
344
|
+
return SimpleVocabulary(voc_terms)
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
<configure
|
|
2
|
+
xmlns="http://namespaces.zope.org/zope"
|
|
3
|
+
i18n_domain="collective.documentgenerator"
|
|
4
|
+
>
|
|
5
|
+
|
|
6
|
+
<!-- Formats Vocabulary -->
|
|
7
|
+
<utility
|
|
8
|
+
factory=".vocabulary.FormatsVocabularyFactory"
|
|
9
|
+
provides="zope.schema.interfaces.IVocabularyFactory"
|
|
10
|
+
name="collective.documentgenerator.Formats"
|
|
11
|
+
/>
|
|
12
|
+
|
|
13
|
+
<!-- Portal Types Vocabulary -->
|
|
14
|
+
<utility
|
|
15
|
+
factory=".vocabulary.PortalTypesVocabularyFactory"
|
|
16
|
+
provides="zope.schema.interfaces.IVocabularyFactory"
|
|
17
|
+
name="collective.documentgenerator.PortalTypes"
|
|
18
|
+
/>
|
|
19
|
+
|
|
20
|
+
<!-- Styles Vocabulary -->
|
|
21
|
+
<utility
|
|
22
|
+
factory=".vocabulary.StyleTemplatesVocabularyFactory"
|
|
23
|
+
provides="zope.schema.interfaces.IVocabularyFactory"
|
|
24
|
+
name="collective.documentgenerator.StyleTemplates"
|
|
25
|
+
/>
|
|
26
|
+
|
|
27
|
+
<!-- Merge templates Vocabulary -->
|
|
28
|
+
<utility
|
|
29
|
+
factory=".vocabulary.MergeTemplatesVocabularyFactory"
|
|
30
|
+
provides="zope.schema.interfaces.IVocabularyFactory"
|
|
31
|
+
name="collective.documentgenerator.MergeTemplates"
|
|
32
|
+
/>
|
|
33
|
+
|
|
34
|
+
<!-- MailingLoop Vocabulary -->
|
|
35
|
+
<utility
|
|
36
|
+
factory=".vocabulary.MailingLoopTemplatesEnabledVocabularyFactory"
|
|
37
|
+
provides="zope.schema.interfaces.IVocabularyFactory"
|
|
38
|
+
name="collective.documentgenerator.EnabledMailingLoopTemplates"
|
|
39
|
+
/>
|
|
40
|
+
|
|
41
|
+
<!-- Existing POD Template Vocabulary -->
|
|
42
|
+
<utility
|
|
43
|
+
factory=".vocabulary.ExistingPODTemplateFactory"
|
|
44
|
+
provides="zope.schema.interfaces.IVocabularyFactory"
|
|
45
|
+
name="collective.documentgenerator.ExistingPODTemplate"
|
|
46
|
+
/>
|
|
47
|
+
|
|
48
|
+
<!-- All POD Template Vocabulary -->
|
|
49
|
+
<utility
|
|
50
|
+
factory=".vocabulary.AllPODTemplateWithFileVocabularyFactory"
|
|
51
|
+
provides="zope.schema.interfaces.IVocabularyFactory"
|
|
52
|
+
name="collective.documentgenerator.AllPODTemplateWithFile"
|
|
53
|
+
/>
|
|
54
|
+
|
|
55
|
+
<!-- columnModifier Vocabulary -->
|
|
56
|
+
<utility
|
|
57
|
+
factory=".vocabulary.PodColumnModifierVocabularyFactory"
|
|
58
|
+
provides="zope.schema.interfaces.IVocabularyFactory"
|
|
59
|
+
name="collective.documentgenerator.PodColumnModifier"
|
|
60
|
+
/>
|
|
61
|
+
<utility
|
|
62
|
+
factory=".vocabulary.ConfigColumnModifierVocabularyFactory"
|
|
63
|
+
provides="zope.schema.interfaces.IVocabularyFactory"
|
|
64
|
+
name="collective.documentgenerator.ConfigColumnModifier"
|
|
65
|
+
/>
|
|
66
|
+
|
|
67
|
+
<utility
|
|
68
|
+
factory=".vocabulary.MailingLoopTemplatesAllVocabularyFactory"
|
|
69
|
+
provides="zope.schema.interfaces.IVocabularyFactory"
|
|
70
|
+
name="collective.documentgenerator.AllMailingLoopTemplates"
|
|
71
|
+
/>
|
|
72
|
+
|
|
73
|
+
<utility
|
|
74
|
+
factory=".vocabulary.ConfigStreamVocabularyFactory"
|
|
75
|
+
provides="zope.schema.interfaces.IVocabularyFactory"
|
|
76
|
+
name="collective.documentgenerator.ConfigStream"
|
|
77
|
+
/>
|
|
78
|
+
|
|
79
|
+
<!-- MISSING VOCABULARIES -->
|
|
80
|
+
<!-- type, layer, view, field, vocabulary, widget -->
|
|
81
|
+
<adapter
|
|
82
|
+
factory=".vocabulary.PTMCTV"
|
|
83
|
+
for="collective.documentgenerator.content.pod_template.IConfigurablePODTemplate
|
|
84
|
+
z3c.form.interfaces.IFormLayer
|
|
85
|
+
zope.interface.Interface
|
|
86
|
+
zope.schema.interfaces.IChoice
|
|
87
|
+
zope.schema.interfaces.IBaseVocabulary
|
|
88
|
+
z3c.form.interfaces.ISelectWidget"
|
|
89
|
+
/>
|
|
90
|
+
|
|
91
|
+
<!-- CSV field delimiter Vocabulary -->
|
|
92
|
+
<utility
|
|
93
|
+
factory=".vocabulary.CSVFieldDelimiterFactory"
|
|
94
|
+
provides="zope.schema.interfaces.IVocabularyFactory"
|
|
95
|
+
name="collective.documentgenerator.CSVFieldDelimiter"
|
|
96
|
+
/>
|
|
97
|
+
|
|
98
|
+
<!-- CSV string delimiter Vocabulary -->
|
|
99
|
+
<utility
|
|
100
|
+
factory=".vocabulary.CSVStringDelimiterFactory"
|
|
101
|
+
provides="zope.schema.interfaces.IVocabularyFactory"
|
|
102
|
+
name="collective.documentgenerator.CSVStringDelimiter"
|
|
103
|
+
/>
|
|
104
|
+
|
|
105
|
+
</configure>
|
|
File without changes
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<configure
|
|
2
|
+
xmlns="http://namespaces.zope.org/zope"
|
|
3
|
+
xmlns:browser="http://namespaces.zope.org/browser"
|
|
4
|
+
xmlns:i18n="http://namespaces.zope.org/i18n"
|
|
5
|
+
xmlns:zcml="http://namespaces.zope.org/zcml"
|
|
6
|
+
i18n_domain="collective.documentgenerator"
|
|
7
|
+
>
|
|
8
|
+
|
|
9
|
+
<!-- helper view for demo profile -->
|
|
10
|
+
<browser:page
|
|
11
|
+
name="document_generation_helper_view"
|
|
12
|
+
for="plone.dexterity.interfaces.IDexterityContent"
|
|
13
|
+
class="collective.documentgenerator.demo.helper.DXDemoHelperView"
|
|
14
|
+
permission="zope2.View"
|
|
15
|
+
layer="collective.documentgenerator.interfaces.IDemoLayer"
|
|
16
|
+
/>
|
|
17
|
+
|
|
18
|
+
</configure>
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
from collective.documentgenerator.helper import DocumentGenerationHelperView
|
|
4
|
+
from collective.documentgenerator.helper import DXDocumentGenerationHelperView
|
|
5
|
+
from collective.documentgenerator.utils import translate as _
|
|
6
|
+
from DateTime import DateTime
|
|
7
|
+
from imio.pyutils.utils import safe_encode
|
|
8
|
+
from plone import api
|
|
9
|
+
from plone.app.textfield import RichText
|
|
10
|
+
from plone.dexterity.events import EditCancelledEvent
|
|
11
|
+
from plone.dexterity.interfaces import IDexterityContainer
|
|
12
|
+
from zope.component import getUtility
|
|
13
|
+
from zope.event import notify
|
|
14
|
+
from zope.i18n.interfaces import ITranslationDomain
|
|
15
|
+
from zope.schema import List
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class BaseDemoHelperView(DocumentGenerationHelperView):
|
|
19
|
+
""" """
|
|
20
|
+
|
|
21
|
+
def get_default_CT_fields(self):
|
|
22
|
+
raise NotImplementedError
|
|
23
|
+
|
|
24
|
+
def _get_default_CT_fields_filtered_fields(self):
|
|
25
|
+
""" """
|
|
26
|
+
return ["id", "title"]
|
|
27
|
+
|
|
28
|
+
def is_default_field(self, field_name):
|
|
29
|
+
if not self.is_rich_text_field(field_name) and not self.is_line_field(
|
|
30
|
+
field_name
|
|
31
|
+
):
|
|
32
|
+
return True
|
|
33
|
+
return False
|
|
34
|
+
|
|
35
|
+
def is_rich_text_field(self, field_name):
|
|
36
|
+
raise NotImplementedError
|
|
37
|
+
|
|
38
|
+
def is_line_field(self, field_name):
|
|
39
|
+
raise NotImplementedError
|
|
40
|
+
|
|
41
|
+
def get_localized_field_name(self, field_name):
|
|
42
|
+
translation_domain = getUtility(ITranslationDomain, "plone")
|
|
43
|
+
target_language = api.portal.get_registry_record("plone.default_language")
|
|
44
|
+
|
|
45
|
+
unlocalized_field_label = self._get_unlocalized_field_label(field_name)
|
|
46
|
+
|
|
47
|
+
translation = translation_domain.translate(
|
|
48
|
+
unlocalized_field_label, target_language=target_language, default=field_name
|
|
49
|
+
)
|
|
50
|
+
return translation
|
|
51
|
+
|
|
52
|
+
def _get_unlocalized_field_label(self, field_name):
|
|
53
|
+
raise NotImplementedError
|
|
54
|
+
|
|
55
|
+
def get_slash_separated_date(self, date):
|
|
56
|
+
date = DateTime(date)
|
|
57
|
+
formatted_date = date.strftime("%d/%m/%Y %H:%M")
|
|
58
|
+
return formatted_date
|
|
59
|
+
|
|
60
|
+
def display_code(self, field_name):
|
|
61
|
+
code = []
|
|
62
|
+
if self.is_default_field(field_name):
|
|
63
|
+
code.append("%s : context.%s" % (_(u"input_field"), field_name))
|
|
64
|
+
elif self.is_rich_text_field(field_name):
|
|
65
|
+
code.append(
|
|
66
|
+
"%s : do text from view.render_xhtml('%s')"
|
|
67
|
+
% (_(u"comment"), field_name)
|
|
68
|
+
)
|
|
69
|
+
elif self.is_line_field(field_name):
|
|
70
|
+
code.append("%s : line" % _(u"input_field"))
|
|
71
|
+
code.append(
|
|
72
|
+
"%s : do text for line in view.list('%s')" % (_(u"comment"), field_name)
|
|
73
|
+
)
|
|
74
|
+
return code
|
|
75
|
+
|
|
76
|
+
def summary(self, obj):
|
|
77
|
+
summary = "%s - %s - %s %s" % (
|
|
78
|
+
obj.Title(),
|
|
79
|
+
obj.creators[0],
|
|
80
|
+
_(u"last_change"),
|
|
81
|
+
obj.modification_date.strftime("%d/%m/%Y %H:%M"),
|
|
82
|
+
)
|
|
83
|
+
return summary
|
|
84
|
+
|
|
85
|
+
def get_collection_CT_fields(self):
|
|
86
|
+
raise NotImplementedError
|
|
87
|
+
|
|
88
|
+
def _get_collection_CT_fields_filtered_fields(self):
|
|
89
|
+
""" """
|
|
90
|
+
return [
|
|
91
|
+
"id",
|
|
92
|
+
"title",
|
|
93
|
+
"text",
|
|
94
|
+
"sort_on",
|
|
95
|
+
"sort_reversed",
|
|
96
|
+
"b_size",
|
|
97
|
+
"limit",
|
|
98
|
+
"customViewFields",
|
|
99
|
+
]
|
|
100
|
+
|
|
101
|
+
def is_folderish(self):
|
|
102
|
+
raise NotImplementedError
|
|
103
|
+
|
|
104
|
+
def mailing_list(self, gen_context=None):
|
|
105
|
+
paths = api.portal.get_registry_record(
|
|
106
|
+
"collective.documentgenerator.mailing_list"
|
|
107
|
+
)
|
|
108
|
+
ret = []
|
|
109
|
+
for path in paths:
|
|
110
|
+
obj = self.portal.unrestrictedTraverse(safe_encode(path))
|
|
111
|
+
ret.append(obj)
|
|
112
|
+
return ret
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
class DXDemoHelperView(DXDocumentGenerationHelperView, BaseDemoHelperView):
|
|
116
|
+
"""
|
|
117
|
+
Dexterity implementation of demo document generation helper methods.
|
|
118
|
+
"""
|
|
119
|
+
|
|
120
|
+
def get_default_CT_fields(self):
|
|
121
|
+
field_list = []
|
|
122
|
+
filtered_fields = self._get_default_CT_fields_filtered_fields()
|
|
123
|
+
default_field_list = self._get_fields()
|
|
124
|
+
for field in default_field_list:
|
|
125
|
+
if field.__name__ not in filtered_fields:
|
|
126
|
+
field_list.append(field.__name__)
|
|
127
|
+
return field_list
|
|
128
|
+
|
|
129
|
+
def _get_fields(self, fieldsets=["default"]):
|
|
130
|
+
with api.env.adopt_roles(["Manager"]):
|
|
131
|
+
edit_form = self.real_context.unrestrictedTraverse("@@edit").form_instance
|
|
132
|
+
edit_form.update()
|
|
133
|
+
notify(EditCancelledEvent(self.real_context))
|
|
134
|
+
|
|
135
|
+
fields = edit_form.fields.values()
|
|
136
|
+
return [f.field for f in fields]
|
|
137
|
+
|
|
138
|
+
def _get_field(self, field_name):
|
|
139
|
+
fields = self._get_fields()
|
|
140
|
+
for field in fields:
|
|
141
|
+
if field.__name__ == field_name:
|
|
142
|
+
return field
|
|
143
|
+
|
|
144
|
+
def is_rich_text_field(self, field_name):
|
|
145
|
+
field = self._get_field(field_name)
|
|
146
|
+
if field and isinstance(field, RichText):
|
|
147
|
+
return True
|
|
148
|
+
return False
|
|
149
|
+
|
|
150
|
+
def is_line_field(self, field_name):
|
|
151
|
+
field = self._get_field(field_name)
|
|
152
|
+
if field and isinstance(field, List):
|
|
153
|
+
return True
|
|
154
|
+
return False
|
|
155
|
+
|
|
156
|
+
def _get_unlocalized_field_label(self, field_name):
|
|
157
|
+
field = self._get_field(field_name)
|
|
158
|
+
return field.title
|
|
159
|
+
|
|
160
|
+
def get_collection_CT_fields(self):
|
|
161
|
+
field_list = []
|
|
162
|
+
filtered_fields = self._get_collection_CT_fields_filtered_fields()
|
|
163
|
+
default_field_list = self._get_fields()
|
|
164
|
+
for field_name, field in default_field_list:
|
|
165
|
+
if field_name not in filtered_fields:
|
|
166
|
+
field_list.append(field_name)
|
|
167
|
+
return field_list
|
|
168
|
+
|
|
169
|
+
def is_folderish(self):
|
|
170
|
+
return IDexterityContainer.providedBy(self.real_context)
|
|
File without changes
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
<configure
|
|
2
|
+
xmlns="http://namespaces.zope.org/zope"
|
|
3
|
+
xmlns:five="http://namespaces.zope.org/five"
|
|
4
|
+
xmlns:i18n="http://namespaces.zope.org/i18n"
|
|
5
|
+
i18n_domain="collective.documentgenerator"
|
|
6
|
+
>
|
|
7
|
+
|
|
8
|
+
<subscriber
|
|
9
|
+
for="..content.pod_template.IPODTemplate
|
|
10
|
+
zope.lifecycleevent.interfaces.IObjectCreatedEvent"
|
|
11
|
+
handler=".pod_templates_events.podtemplate_created"
|
|
12
|
+
/>
|
|
13
|
+
|
|
14
|
+
<subscriber
|
|
15
|
+
for="..content.pod_template.IPODTemplate
|
|
16
|
+
OFS.interfaces.IObjectWillBeRemovedEvent"
|
|
17
|
+
handler=".pod_templates_events.podtemplate_will_be_removed"
|
|
18
|
+
/>
|
|
19
|
+
|
|
20
|
+
<subscriber
|
|
21
|
+
for="..content.style_template.IStyleTemplate
|
|
22
|
+
zope.lifecycleevent.interfaces.IObjectCreatedEvent"
|
|
23
|
+
handler=".styles_events.styletemplate_created"
|
|
24
|
+
/>
|
|
25
|
+
|
|
26
|
+
<subscriber
|
|
27
|
+
for="..content.style_template.IStyleTemplate
|
|
28
|
+
zope.lifecycleevent.interfaces.IObjectModifiedEvent"
|
|
29
|
+
handler=".styles_events.update_styles_of_all_PODtemplate"
|
|
30
|
+
/>
|
|
31
|
+
|
|
32
|
+
<subscriber
|
|
33
|
+
for="..content.pod_template.IPODTemplate
|
|
34
|
+
zope.lifecycleevent.interfaces.IObjectModifiedEvent"
|
|
35
|
+
handler=".pod_templates_events.podtemplate_modified"
|
|
36
|
+
/>
|
|
37
|
+
|
|
38
|
+
<subscriber
|
|
39
|
+
for="..content.pod_template.IPODTemplate
|
|
40
|
+
zope.lifecycleevent.interfaces.IObjectModifiedEvent"
|
|
41
|
+
handler=".pod_templates_events.apply_default_page_style_for_mailing"
|
|
42
|
+
/>
|
|
43
|
+
|
|
44
|
+
</configure>
|