Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
PLONE_VERSION: [ 4.3, 5.1, 5.2 ]
services:
libreoffice:
image: harbor.imio.be/library/libreoffice:25.2
image: harbor.imio.be/library/libreoffice:25.8
ports:
- 2002:2002
volumes:
Expand All @@ -35,6 +35,7 @@ jobs:
sudo apt-get install -qq -y libreoffice libreoffice-script-provider-python libjpeg62 libjpeg62-dev libbz2-dev
mkdir -p buildout-cache/{eggs,downloads}
pip install -r requirements.txt
soffice --version
- name: Set up pyenv and Python
uses: "gabrielfalcao/pyenv-action@v18"
with:
Expand Down Expand Up @@ -71,7 +72,7 @@ jobs:
PLONE_VERSION: [5.2]
services:
libreoffice:
image: harbor.imio.be/library/libreoffice:25.2
image: harbor.imio.be/library/libreoffice:25.8
ports:
- 2002:2002
volumes:
Expand Down
13 changes: 11 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,17 @@ Changelog
3.48 (unreleased)
-----------------

- Nothing changed yet.

- Use `Compromiser` evaluator.
[gbastien]
- Added migration to `16` that will make sure existing POD templates are safe.
[gbastien]
- Added parameter `prepend_pod_title=True` to `DocumentGenerationView._get_filename`
so it is especially possible to not preprend pod template title to generated
file filename.
[gbastien]
- Close tag `<label>` correctly in `children_pod_template.pt` or the full template
is rendered with fields in the `<label>` leading to every values being `bold`.
[gbastien]

3.47 (2026-03-03)
-----------------
Expand Down
7 changes: 7 additions & 0 deletions buildout.d/plone-4.3.x.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@ backports.functools-lru-cache = 1.5
zc.lockfile = 2.0
zope.configuration = 3.8.1
shortuuid = 0.5.0
cryptography = 3.3.2
psutil = 6.1.1
shortuuid = 0.5.0
wcwidth = 0.2.5
PyJWT = 1.7.1
cffi = 1.15.1
pycparser = 2.21
7 changes: 7 additions & 0 deletions buildout.d/plone-5.1.x.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,10 @@ extends =

[versions]
shortuuid = 0.5.0
cryptography = 3.3.2
psutil = 6.1.1
shortuuid = 0.5.0
wcwidth = 0.2.5
PyJWT = 1.7.1
cffi = 1.15.1
pycparser = 2.21
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<tal:defines define="children view/get_children">
<label class="horizontal" i18n:domain="collective.documentgenerator"
i18n:translate="Linked POD Template using this one"/>
<label i18n:domain="collective.documentgenerator"
i18n:translate="Linked POD Template using this one"></label>
<ul tal:condition="children">
<li tal:repeat="child children">
<a href="#"
Expand All @@ -13,4 +13,4 @@

<p class="discreet" tal:condition="not:children" i18n:domain="collective.documentgenerator" i18n:translate="None">None</p>

</tal:defines>
</tal:defines>
18 changes: 14 additions & 4 deletions src/collective/documentgenerator/browser/generation_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from AccessControl import Unauthorized
from appy.pod.renderer import CsvOptions
from appy.pod.renderer import Renderer
from appy.pod.evaluator import Compromiser
from appy.pod.styles_manager import TableProperties
from collective.documentgenerator import config
from collective.documentgenerator import utils
Expand Down Expand Up @@ -127,13 +128,21 @@ def _generate_doc(self, pod_template, output_format, **kwargs):
filename = self._get_filename()
return rendered, filename, gen_context

def _get_filename(self):
""" """
# we limit filename to 120 characters
first_part = u'{0} {1}'.format(self.pod_template.title, safe_unicode(self.context.Title()))
def _get_filename(self, prepend_pod_title=True):
"""
Return generated file filename.

:param prepend_pod_title: will preprend the POD template title before
context title for the generated file filename
title then pod template title
"""
first_part = safe_unicode(self.context.Title())
if prepend_pod_title:
first_part = u'{0} {1}'.format(self.pod_template.title, first_part)
# replace unicode special characters with ascii equivalent value
first_part = unicodedata.normalize('NFKD', first_part).encode('ascii', 'ignore')
util = queryUtility(IFileNameNormalizer)
# we limit filename to 120 characters
# remove '-' from first_part because it is handled by cropName that manages max_length
# and it behaves weirdly if it encounters '-'
# moreover avoid more than one blank space at a time
Expand Down Expand Up @@ -283,6 +292,7 @@ def _render_document(self, pod_template, output_format, sub_documents, raiseOnEr
html=True,
optimalColumnWidths=optimalColumnWidths,
distributeColumns=distributeColumns,
evaluator=Compromiser(),
stylesMapping=stylesMapping,
stream=config.get_use_stream(),
csvOptions=csvOptions,
Expand Down
86 changes: 86 additions & 0 deletions src/collective/documentgenerator/migrations/migrate_to_16.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# -*- coding: utf-8 -*-

from appy.pod.evaluator import Compromiser
from collections import OrderedDict
from collective.documentgenerator.content.pod_template import IPODTemplate
from collective.documentgenerator.search_replace.pod_template import SearchAndReplacePODTemplates
from imio.helpers.content import uuidToObject
from imio.migrator.migrator import Migrator
from imio.pyutils.utils import safe_encode
from plone import api

import logging


logger = logging.getLogger('collective.documentgenerator')


class Migrate_To_16(Migrator):

def __init__(self, context):
Migrator.__init__(self, context)
self.catalog = api.portal.get_tool('portal_catalog')

def _clean_expr(self):
"""Clean expressions of existing POD templates."""
logger.info('Cleaning expressions for existing POD templates...')
results = []
for brain in self.catalog(object_provides=IPODTemplate.__identifier__):
pod_template = brain.getObject()
with SearchAndReplacePODTemplates([pod_template]) as search_replace:
# banned
for banned_expr in Compromiser.banned:
res = search_replace.replace(Compromiser.getBannedRex().pattern, '++REPLACED++', is_regex=True)
if res:
results.append(res)
# underscored
res = search_replace.replace(Compromiser.underscored.pattern, '++REPLACED++', is_regex=True)
if res:
results.append(res)
# format results and dump it in the Zope log
# as clean as possible so it can be used to know what changed
data = {}
for result in results:
pt_uid, infos = result.items()[0]
pt = uuidToObject(pt_uid, unrestricted=True)
pt_path_and_title = "{0} - {1}".format(
'/'.join(pt.getPhysicalPath()), pt.Title())
if pt_path_and_title not in data:
data[pt_path_and_title] = []
self.warnings.append('Replacements were done in POD template at %s'
% pt_path_and_title)
for info in infos:
line = repr(info).replace(' These changes were done:', '>>>'). \
replace('\n\n', '\n').rstrip('\n')
data[pt_path_and_title].append(line)
logger.info("REPLACEMENTS IN POD TEMPLATES")
if not data:
logger.info("=============================")
logger.info("No replacement was done.")
else:
# order data by pt_path
ordered_data = OrderedDict(sorted(data.items()))
output = ["============================="]
for pt_path_and_title, infos in ordered_data.items():
output.append("POD template " + pt_path_and_title)
output.append('-' * len("POD template " + pt_path_and_title))
for info in infos:
output.append(info)
# make sure we do not mix unicode and utf-8
fixed_output = []
for line in output:
line = safe_encode(line)
fixed_output.append(line)
logger.info('\n'.join(fixed_output))
logger.info('Done.')

def run(self):
logger.info('Migrating to collective.documentgenerator 16...')
self._clean_expr()
self.finish()


def migrate(context):
'''
'''
Migrate_To_16(context).run()
11 changes: 11 additions & 0 deletions src/collective/documentgenerator/profiles.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,17 @@
import_steps="plone.app.registry" />
</genericsetup:upgradeSteps>


<genericsetup:upgradeSteps
source="15"
destination="16"
profile="collective.documentgenerator:default">
<genericsetup:upgradeStep
title="collective.documentgenerator: upgrade to 16"
description="Clean expressions (using Comprimser) of every existing POD templates"
handler="collective.documentgenerator.migrations.migrate_to_16.migrate" />
</genericsetup:upgradeSteps>

<utility factory=".setuphandlers.HiddenProfiles" name="collective.documentgenerator" />
<utility factory=".setuphandlers.HiddenProducts" name="collective.documentgenerator" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
<dependencies>
<dependency>profile-collective.documentgenerator:install-base</dependency>
</dependencies>
<version>15</version>
<version>16</version>
</metadata>
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
<dependencies>
<dependency>profile-collective.documentgenerator:install-base</dependency>
</dependencies>
<version>15</version>
<version>16</version>
</metadata>
Loading