From 347f55002c5e4d8cb9f6224c50211aef67de0972 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Duch=C3=AAne?= Date: Tue, 15 Oct 2024 13:49:12 +0200 Subject: [PATCH] Fixed an issue in search and replace (#62) --- CHANGES.rst | 4 ++-- .../documentgenerator/search_replace/pod_template.py | 2 +- .../documentgenerator/tests/test_search_replace.py | 8 ++++++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 7f8d62d0..d45b29b6 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,8 +4,8 @@ Changelog 3.44 (unreleased) ----------------- -- Nothing changed yet. - +- Fixed an issue when odt_file.filename could be None when searching and replacing - backport from 4.x. + [aduchene] 3.43 (2024-04-10) ----------------- diff --git a/src/collective/documentgenerator/search_replace/pod_template.py b/src/collective/documentgenerator/search_replace/pod_template.py index 01138dd9..daf41fcc 100644 --- a/src/collective/documentgenerator/search_replace/pod_template.py +++ b/src/collective/documentgenerator/search_replace/pod_template.py @@ -35,7 +35,7 @@ def __init__(self, podtemplates): # compute the (future) file system path of the plone pod templates for podtemplate in podtemplates: - if not podtemplate.odt_file: + if not podtemplate.odt_file or not podtemplate.odt_file.filename: continue # ignore templates referring another pod template. file_extension = podtemplate.odt_file.filename.split(".")[-1].lower() template_path = get_site_root_relative_path(podtemplate) diff --git a/src/collective/documentgenerator/tests/test_search_replace.py b/src/collective/documentgenerator/tests/test_search_replace.py index 2a748b2b..8c880453 100644 --- a/src/collective/documentgenerator/tests/test_search_replace.py +++ b/src/collective/documentgenerator/tests/test_search_replace.py @@ -409,3 +409,11 @@ def test_search_replace_control_panel_regex_validator(self): data = {"replacements": replacements} errors = form.widgets.validate(data) self.assertFalse(errors) + + def test_no_odt_file_or_no_filename(self): + self.template1.odt_file = None + self.template2.odt_file.filename = None + with SearchAndReplacePODTemplates((self.template1, self.template2)) as search_replace: + results = search_replace.search("view") + + self.assertEqual(len(results.keys()), 0)