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,245 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
from appy.bin.oclean import Cleaner
|
|
3
|
+
from collective.documentgenerator import _
|
|
4
|
+
from imio.helpers.security import fplog
|
|
5
|
+
from plone import api
|
|
6
|
+
from plone.namedfile.file import NamedBlobFile
|
|
7
|
+
from Products.CMFCore.utils import getToolByName
|
|
8
|
+
from Products.CMFPlone.utils import safe_unicode
|
|
9
|
+
from zope import i18n
|
|
10
|
+
from zope.component import getMultiAdapter
|
|
11
|
+
from zope.component.hooks import getSite
|
|
12
|
+
from zope.component.hooks import setSite
|
|
13
|
+
from zope.interface import Interface
|
|
14
|
+
from zope.interface import Invalid
|
|
15
|
+
from zope.lifecycleevent import Attributes
|
|
16
|
+
from zope.lifecycleevent import modified
|
|
17
|
+
|
|
18
|
+
import hashlib
|
|
19
|
+
import logging
|
|
20
|
+
import os
|
|
21
|
+
import re
|
|
22
|
+
import tempfile
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
logger = logging.getLogger("collective.documentgenerator")
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def translate(msgid, domain="collective.documentgenerator"):
|
|
29
|
+
portal = api.portal.get()
|
|
30
|
+
translation = i18n.translate(msgid, domain=domain, context=portal.REQUEST)
|
|
31
|
+
return translation
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def compute_md5(data):
|
|
35
|
+
md5 = hashlib.md5(data).hexdigest()
|
|
36
|
+
return md5
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def update_templates(templates, profile="", force=False):
|
|
40
|
+
"""
|
|
41
|
+
function to manage templates update.
|
|
42
|
+
# see http://trac.imio.be/trac/ticket/9383 for full implementation
|
|
43
|
+
:param list templates: list of tuples containing ('plone-template-path', 'os-template-path')
|
|
44
|
+
:param str profile: profile path stored on template (or various identification)
|
|
45
|
+
:param bool force: force overrides of templates
|
|
46
|
+
"""
|
|
47
|
+
# Don't use profile now !
|
|
48
|
+
portal = api.portal.getSite()
|
|
49
|
+
ret = []
|
|
50
|
+
for (ppath, ospath) in templates:
|
|
51
|
+
ppath = ppath.strip("/ ")
|
|
52
|
+
obj = portal.unrestrictedTraverse(ppath, default=None)
|
|
53
|
+
if not obj:
|
|
54
|
+
logger.warn("The plone template '%s' was not found" % ppath)
|
|
55
|
+
ret.append((ppath, ospath, "plone path error"))
|
|
56
|
+
continue
|
|
57
|
+
if not obj.odt_file:
|
|
58
|
+
logger.warn("The plone template '%s' doesn't have odt file" % ppath)
|
|
59
|
+
ret.append((ppath, ospath, "no odt file"))
|
|
60
|
+
continue
|
|
61
|
+
if not os.path.exists(ospath):
|
|
62
|
+
logger.warn("The template file '%s' doesn't exist" % ospath)
|
|
63
|
+
ret.append((ppath, ospath, "os path error"))
|
|
64
|
+
continue
|
|
65
|
+
with open(ospath, "rb") as f:
|
|
66
|
+
data = f.read()
|
|
67
|
+
new_md5 = compute_md5(data)
|
|
68
|
+
if obj.initial_md5 == new_md5:
|
|
69
|
+
ret.append((ppath, ospath, "unchanged"))
|
|
70
|
+
continue
|
|
71
|
+
elif obj.has_been_modified() and not force:
|
|
72
|
+
ret.append((ppath, ospath, "kept"))
|
|
73
|
+
continue
|
|
74
|
+
obj.initial_md5 = new_md5
|
|
75
|
+
obj.style_modification_md5 = new_md5
|
|
76
|
+
obj.odt_file.data = data
|
|
77
|
+
modified(obj, Attributes(Interface, "odt_file"))
|
|
78
|
+
ret.append((ppath, ospath, "replaced"))
|
|
79
|
+
return ret
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def update_dict_with_validation(
|
|
83
|
+
original_dict, update_dict, error_message=_("Dict update collision on key")
|
|
84
|
+
):
|
|
85
|
+
for key in update_dict:
|
|
86
|
+
if key in original_dict:
|
|
87
|
+
raise Invalid(
|
|
88
|
+
_(
|
|
89
|
+
"${error_message} for key = '${key}'",
|
|
90
|
+
mapping={"error_message": error_message, "key": key},
|
|
91
|
+
)
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
original_dict[key] = update_dict[key]
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def safe_encode(value, encoding="utf-8"):
|
|
98
|
+
"""
|
|
99
|
+
Converts a value to encoding, only when it is not already encoded.
|
|
100
|
+
"""
|
|
101
|
+
if isinstance(value, bytes): # noqa: F821
|
|
102
|
+
return value.encode(encoding)
|
|
103
|
+
return value
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def ulocalized_time(
|
|
107
|
+
date,
|
|
108
|
+
long_format=None,
|
|
109
|
+
time_only=None,
|
|
110
|
+
custom_format=None,
|
|
111
|
+
domain="plonelocales",
|
|
112
|
+
target_language=None,
|
|
113
|
+
context=None,
|
|
114
|
+
request=None,
|
|
115
|
+
month_lc=True,
|
|
116
|
+
day_lc=True,
|
|
117
|
+
):
|
|
118
|
+
"""
|
|
119
|
+
Return for a datetime the string value with week and mont translated.
|
|
120
|
+
Take into account %a, %A, %b, %B
|
|
121
|
+
"""
|
|
122
|
+
if not custom_format:
|
|
123
|
+
# use toLocalizedTime
|
|
124
|
+
plone = getMultiAdapter((context, request), name=u"plone")
|
|
125
|
+
formatted_date = plone.toLocalizedTime(date, long_format, time_only)
|
|
126
|
+
else:
|
|
127
|
+
from Products.CMFPlone.i18nl10n import monthname_msgid
|
|
128
|
+
from Products.CMFPlone.i18nl10n import monthname_msgid_abbr
|
|
129
|
+
from Products.CMFPlone.i18nl10n import weekdayname_msgid
|
|
130
|
+
from Products.CMFPlone.i18nl10n import weekdayname_msgid_abbr
|
|
131
|
+
|
|
132
|
+
if request is None:
|
|
133
|
+
portal = api.portal.get()
|
|
134
|
+
request = portal.REQUEST
|
|
135
|
+
# first replace parts to translate
|
|
136
|
+
custom_format = custom_format.replace("%%", "_p_c_")
|
|
137
|
+
|
|
138
|
+
conf = {
|
|
139
|
+
"a": {"fct": weekdayname_msgid_abbr, "fmt": "%w", "low": day_lc},
|
|
140
|
+
"A": {"fct": weekdayname_msgid, "fmt": "%w", "low": day_lc},
|
|
141
|
+
"b": {"fct": monthname_msgid_abbr, "fmt": "%m", "low": month_lc},
|
|
142
|
+
"B": {"fct": monthname_msgid, "fmt": "%m", "low": month_lc},
|
|
143
|
+
}
|
|
144
|
+
matches = re.findall(r"%([aAbB])", custom_format)
|
|
145
|
+
for match in sorted(set(matches)):
|
|
146
|
+
# function( int(date.strftime(format) )
|
|
147
|
+
msgid = conf[match]["fct"](int(date.strftime(conf[match]["fmt"])))
|
|
148
|
+
repl = i18n.translate(
|
|
149
|
+
msgid, domain, context=request, target_language=target_language
|
|
150
|
+
)
|
|
151
|
+
if conf[match]["low"]:
|
|
152
|
+
repl = repl.lower()
|
|
153
|
+
custom_format = re.sub("%{}".format(match), repl, custom_format)
|
|
154
|
+
|
|
155
|
+
# then format date
|
|
156
|
+
custom_format = custom_format.replace("_p_c_", "%%")
|
|
157
|
+
formatted_date = date.strftime(custom_format)
|
|
158
|
+
return safe_unicode(formatted_date)
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def remove_tmp_file(filename):
|
|
162
|
+
"""Do not break if unable to remove temporary file, but log error if any."""
|
|
163
|
+
try:
|
|
164
|
+
os.remove(filename)
|
|
165
|
+
except OSError:
|
|
166
|
+
logger.warn("Could not remove temporary file at {0}".format(filename))
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def update_oo_config():
|
|
170
|
+
"""Update config following buildout var"""
|
|
171
|
+
key_template = "collective.documentgenerator.browser.controlpanel.IDocumentGeneratorControlPanelSchema.{}"
|
|
172
|
+
var = {
|
|
173
|
+
"oo_server": "OO_SERVER",
|
|
174
|
+
"oo_port_list": "OO_PORT",
|
|
175
|
+
"uno_path": "PYTHON_UNO",
|
|
176
|
+
}
|
|
177
|
+
for key in var.keys():
|
|
178
|
+
full_key = key_template.format(key)
|
|
179
|
+
configured_oo_option = api.portal.get_registry_record(full_key)
|
|
180
|
+
env_value = os.getenv(var.get(key, "NO_ONE"), None)
|
|
181
|
+
if env_value:
|
|
182
|
+
new_oo_option = type(configured_oo_option)(
|
|
183
|
+
os.getenv(var.get(key, "NO_ONE"), "")
|
|
184
|
+
)
|
|
185
|
+
if new_oo_option and new_oo_option != configured_oo_option:
|
|
186
|
+
api.portal.set_registry_record(full_key, new_oo_option)
|
|
187
|
+
logger.info("LibreOffice configuration updated for " + getSite().getId())
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
def update_oo_config_after_bigbang(event):
|
|
191
|
+
setSite(event.object)
|
|
192
|
+
try:
|
|
193
|
+
update_oo_config()
|
|
194
|
+
except Exception:
|
|
195
|
+
logger.error("Update LibreOffice configuration failed", exc_info=1)
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
def get_site_root_relative_path(obj):
|
|
199
|
+
return "/" + "/".join(getToolByName(obj, "portal_url").getRelativeContentPath(obj))
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def temporary_file_name(suffix=""):
|
|
203
|
+
tmp_dir = os.getenv("CUSTOM_TMP", None)
|
|
204
|
+
if tmp_dir and not os.path.exists(tmp_dir):
|
|
205
|
+
os.mkdir(tmp_dir)
|
|
206
|
+
return tempfile.mktemp(suffix=suffix, dir=tmp_dir)
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
def create_temporary_file(initial_file=None, base_name=""):
|
|
210
|
+
tmp_filename = temporary_file_name(suffix=base_name)
|
|
211
|
+
# create the file in any case
|
|
212
|
+
with open(tmp_filename, "wb") as tmp_file:
|
|
213
|
+
if initial_file:
|
|
214
|
+
tmp_file.write(initial_file.data)
|
|
215
|
+
return tmp_file
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
def clean_notes(pod_template):
|
|
219
|
+
"""Use appy.pod Cleaner to clean notes (comments)."""
|
|
220
|
+
cleaned = 0
|
|
221
|
+
odt_file = pod_template.odt_file
|
|
222
|
+
if odt_file:
|
|
223
|
+
# write file to /tmp to be able to use appy.pod Cleaner
|
|
224
|
+
tmp_file = create_temporary_file(odt_file, "-to-clean.odt")
|
|
225
|
+
cleaner = Cleaner(path=tmp_file.name, silent=False)
|
|
226
|
+
cleaned = cleaner.run()
|
|
227
|
+
if cleaned:
|
|
228
|
+
manually_modified = pod_template.has_been_modified()
|
|
229
|
+
with open(tmp_file.name, "rb") as res_file:
|
|
230
|
+
# update template
|
|
231
|
+
result = NamedBlobFile(
|
|
232
|
+
data=res_file.read(),
|
|
233
|
+
contentType=odt_file.contentType,
|
|
234
|
+
filename=pod_template.odt_file.filename,
|
|
235
|
+
)
|
|
236
|
+
pod_template.odt_file = result
|
|
237
|
+
if not manually_modified:
|
|
238
|
+
pod_template.style_modification_md5 = pod_template.current_md5
|
|
239
|
+
extras = "pod_template={0} cleaned_parts={1}".format(
|
|
240
|
+
repr(pod_template), cleaned
|
|
241
|
+
)
|
|
242
|
+
fplog("clean_notes", extras=extras)
|
|
243
|
+
remove_tmp_file(tmp_file.name)
|
|
244
|
+
|
|
245
|
+
return bool(cleaned)
|
|
File without changes
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
try:
|
|
4
|
+
from collective.eeafaceted.batchactions.browser.viewlets import BatchActionsViewlet
|
|
5
|
+
except ImportError:
|
|
6
|
+
from plone.app.layout.viewlets import ViewletBase as BatchActionsViewlet
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class DGBatchActionsViewlet(BatchActionsViewlet):
|
|
10
|
+
""" """
|
|
11
|
+
|
|
12
|
+
def available(self):
|
|
13
|
+
"""Global availability of the viewlet."""
|
|
14
|
+
return self.view.__name__ == "dg-templates-listing"
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<configure
|
|
2
|
+
xmlns="http://namespaces.zope.org/zope"
|
|
3
|
+
xmlns:browser="http://namespaces.zope.org/browser"
|
|
4
|
+
xmlns:plone="http://namespaces.plone.org/plone"
|
|
5
|
+
i18n_domain="collective.documentgenerator"
|
|
6
|
+
>
|
|
7
|
+
|
|
8
|
+
<browser:viewlet
|
|
9
|
+
name="document-generation-link"
|
|
10
|
+
for="*"
|
|
11
|
+
manager="plone.app.layout.viewlets.interfaces.IBelowContentTitle"
|
|
12
|
+
class="collective.documentgenerator.viewlets.generationlinks.DocumentGeneratorLinksViewlet"
|
|
13
|
+
template="generationlinks.pt"
|
|
14
|
+
permission="zope2.View"
|
|
15
|
+
/>
|
|
16
|
+
|
|
17
|
+
</configure>
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
<div id="doc-generation-view"
|
|
2
|
+
tal:condition="view/available"
|
|
3
|
+
i18n:domain="collective.documentgenerator"
|
|
4
|
+
>
|
|
5
|
+
|
|
6
|
+
<ul class="pod-template"
|
|
7
|
+
tal:define="
|
|
8
|
+
infos view/get_links_info;
|
|
9
|
+
titles python:infos.keys();
|
|
10
|
+
"
|
|
11
|
+
>
|
|
12
|
+
<li class="template-link"
|
|
13
|
+
tal:repeat="title titles"
|
|
14
|
+
>
|
|
15
|
+
<span class="template-link-title"
|
|
16
|
+
tal:content="title"
|
|
17
|
+
>Template title</span>
|
|
18
|
+
<span class="template-link-after-title"></span>
|
|
19
|
+
<span class="template-link-before-link"
|
|
20
|
+
tal:repeat="link python: infos[title]"
|
|
21
|
+
>
|
|
22
|
+
<a class="generation-link"
|
|
23
|
+
target="_blank"
|
|
24
|
+
tal:attributes="
|
|
25
|
+
href link/link;
|
|
26
|
+
title string:${link/output_format_title};
|
|
27
|
+
"
|
|
28
|
+
>
|
|
29
|
+
<img class="svg-icon"
|
|
30
|
+
src="#"
|
|
31
|
+
tal:define="
|
|
32
|
+
alt python: '{} {}'.format(link['title'], link['output_format'].upper());
|
|
33
|
+
"
|
|
34
|
+
tal:attributes="
|
|
35
|
+
src string:${view/portal_url}/++resource++collective.documentgenerator/${link/output_format}.svg;
|
|
36
|
+
alt alt;
|
|
37
|
+
title link/output_format_title;
|
|
38
|
+
"
|
|
39
|
+
/>
|
|
40
|
+
</a>
|
|
41
|
+
</span>
|
|
42
|
+
<span class="link-separator"></span>
|
|
43
|
+
</li>
|
|
44
|
+
</ul>
|
|
45
|
+
|
|
46
|
+
</div>
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
from collections import OrderedDict
|
|
4
|
+
from collective.documentgenerator.config import POD_FORMATS
|
|
5
|
+
from collective.documentgenerator.interfaces import IGenerablePODTemplates
|
|
6
|
+
from plone import api
|
|
7
|
+
from plone.app.layout.viewlets import ViewletBase
|
|
8
|
+
from plone.memoize.view import memoize
|
|
9
|
+
from zope.component import getAdapter
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class DocumentGeneratorLinksViewlet(ViewletBase):
|
|
13
|
+
"""This viewlet displays available documents to generate."""
|
|
14
|
+
|
|
15
|
+
@property
|
|
16
|
+
def portal_url(self):
|
|
17
|
+
return api.portal.get_tool("portal_url")
|
|
18
|
+
|
|
19
|
+
def available(self):
|
|
20
|
+
return bool(self.get_generable_templates())
|
|
21
|
+
|
|
22
|
+
@memoize
|
|
23
|
+
def get_generable_templates(self):
|
|
24
|
+
adapter = getAdapter(self.context, IGenerablePODTemplates)
|
|
25
|
+
generable_templates = adapter.get_generable_templates()
|
|
26
|
+
return generable_templates
|
|
27
|
+
|
|
28
|
+
def get_generation_view_name(self, template, output_format):
|
|
29
|
+
return "document-generation"
|
|
30
|
+
|
|
31
|
+
def get_links_info(self):
|
|
32
|
+
base_url = self.context.absolute_url()
|
|
33
|
+
links = OrderedDict()
|
|
34
|
+
pod_formats = {podf[0]: podf[1] for podf in POD_FORMATS}
|
|
35
|
+
for template in self.get_generable_templates():
|
|
36
|
+
for output_format in template.get_available_formats():
|
|
37
|
+
title = template.Title().strip()
|
|
38
|
+
if title not in links:
|
|
39
|
+
links[title] = []
|
|
40
|
+
description = template.Description()
|
|
41
|
+
uid = template.UID()
|
|
42
|
+
link = "{base_url}/{gen_view_name}?template_uid={uid}&output_format={output_format}".format(
|
|
43
|
+
base_url=base_url,
|
|
44
|
+
uid=uid,
|
|
45
|
+
output_format=output_format,
|
|
46
|
+
gen_view_name=self.get_generation_view_name(
|
|
47
|
+
template, output_format
|
|
48
|
+
),
|
|
49
|
+
)
|
|
50
|
+
infos = {
|
|
51
|
+
"link": link,
|
|
52
|
+
"title": title,
|
|
53
|
+
"description": description,
|
|
54
|
+
"output_format": output_format,
|
|
55
|
+
"output_format_title": pod_formats[output_format],
|
|
56
|
+
"template_uid": uid,
|
|
57
|
+
"template": template,
|
|
58
|
+
}
|
|
59
|
+
infos.update(self.add_extra_links_info(template, infos))
|
|
60
|
+
links[title].append(infos)
|
|
61
|
+
return links
|
|
62
|
+
|
|
63
|
+
def add_extra_links_info(self, template, infos):
|
|
64
|
+
"""This method is made to be overrided and ease adding extra infos
|
|
65
|
+
to the list of dicts returned by self.get_links_info.
|
|
66
|
+
It needs to returns a dict that will update data stored in infos."""
|
|
67
|
+
return {}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import sys, types, os;p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('collective',));importlib = __import__('importlib.util');__import__('importlib.machinery');m = sys.modules.setdefault('collective', importlib.util.module_from_spec(importlib.machinery.PathFinder.find_spec('collective', [os.path.dirname(p)])));m = m or sys.modules.setdefault('collective', types.ModuleType('collective'));mp = (m or []) and m.__dict__.setdefault('__path__',[]);(p not in mp) and mp.append(p)
|