From 08cf8238e1558d92f32ad9b44ba055632058b855 Mon Sep 17 00:00:00 2001 From: Jens Vagelpohl Date: Fri, 17 May 2024 14:38:51 +0200 Subject: [PATCH 1/2] - define custom content type for Page Template (fixes #1212) --- .meta.toml | 1 + CHANGES.rst | 4 ++++ MANIFEST.in | 1 + src/Products/PageTemplates/__init__.py | 9 +++++++++ src/Products/PageTemplates/mime.types | 1 + src/webdav/NullResource.py | 4 +++- 6 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/Products/PageTemplates/mime.types diff --git a/.meta.toml b/.meta.toml index 51f8d75edd..f8e05ee3c3 100644 --- a/.meta.toml +++ b/.meta.toml @@ -104,6 +104,7 @@ additional-rules = [ "recursive-include src *.svg", "recursive-include src *.ttf", "recursive-include src *.txt", + "recursive-include src *.types", "recursive-include src *.webmanifest", "recursive-include src *.woff", "recursive-include src *.woff2", diff --git a/CHANGES.rst b/CHANGES.rst index edac84affb..af4740762a 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -10,6 +10,10 @@ https://github.com/zopefoundation/Zope/blob/4.x/CHANGES.rst 5.9.1 (unreleased) ------------------ +- Define a custom MIME type for Zope Page Templates + instead of relying on platform-dependent MIME type configurations. + (`#1212 `_) + - Clean up and fix installation documentation. - Officially support Python 3.12.1. diff --git a/MANIFEST.in b/MANIFEST.in index 8d9d6e273c..d7c1523a2d 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -43,6 +43,7 @@ recursive-include src *.rst recursive-include src *.svg recursive-include src *.ttf recursive-include src *.txt +recursive-include src *.types recursive-include src *.webmanifest recursive-include src *.woff recursive-include src *.woff2 diff --git a/src/Products/PageTemplates/__init__.py b/src/Products/PageTemplates/__init__.py index 62cac12138..19e91ba625 100644 --- a/src/Products/PageTemplates/__init__.py +++ b/src/Products/PageTemplates/__init__.py @@ -15,6 +15,10 @@ This wrapper allows the Page Template modules to be segregated in a separate package. """ +import os + +from zope.contenttype import add_files + # Placeholder for Zope Product data misc_ = {} @@ -29,3 +33,8 @@ def initialize(context): # Import lazily, and defer initialization to the module from . import ZopePageTemplate ZopePageTemplate.initialize(context) + + # Add the custom MIME type information for Page Templates + # to the Python mimetypes module so they are recognized correctly + here = os.path.dirname(os.path.abspath(__file__)) + add_files([os.path.join(here, 'mime.types')]) diff --git a/src/Products/PageTemplates/mime.types b/src/Products/PageTemplates/mime.types new file mode 100644 index 0000000000..2223b74bd5 --- /dev/null +++ b/src/Products/PageTemplates/mime.types @@ -0,0 +1 @@ +application/vnd.zopefoundation.pagetemplate pt zpt diff --git a/src/webdav/NullResource.py b/src/webdav/NullResource.py index 02deb8ba5f..1cbbbd3568 100644 --- a/src/webdav/NullResource.py +++ b/src/webdav/NullResource.py @@ -114,7 +114,9 @@ def _default_PUT_factory(self, name, typ, body): if ext == '.dtml': ob = DTMLDocument('', __name__=name) - elif typ in ('text/html', 'text/xml'): + elif typ in ('text/html', + 'text/xml', + 'application/vnd.zopefoundation.pagetemplate'): ob = ZopePageTemplate(name, body, content_type=typ) elif typ.startswith('image/'): ob = Image(name, '', body, content_type=typ) From d8aaff79f96f476e04b6a40e3022e5ae4b378f2e Mon Sep 17 00:00:00 2001 From: Jens Vagelpohl Date: Sat, 18 May 2024 07:02:28 +0200 Subject: [PATCH 2/2] - simplifying the solution --- .meta.toml | 1 - CHANGES.rst | 3 +-- MANIFEST.in | 1 - src/Products/PageTemplates/__init__.py | 9 --------- src/Products/PageTemplates/mime.types | 1 - src/webdav/NullResource.py | 4 +--- 6 files changed, 2 insertions(+), 17 deletions(-) delete mode 100644 src/Products/PageTemplates/mime.types diff --git a/.meta.toml b/.meta.toml index f8e05ee3c3..51f8d75edd 100644 --- a/.meta.toml +++ b/.meta.toml @@ -104,7 +104,6 @@ additional-rules = [ "recursive-include src *.svg", "recursive-include src *.ttf", "recursive-include src *.txt", - "recursive-include src *.types", "recursive-include src *.webmanifest", "recursive-include src *.woff", "recursive-include src *.woff2", diff --git a/CHANGES.rst b/CHANGES.rst index af4740762a..690f733840 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -10,8 +10,7 @@ https://github.com/zopefoundation/Zope/blob/4.x/CHANGES.rst 5.9.1 (unreleased) ------------------ -- Define a custom MIME type for Zope Page Templates - instead of relying on platform-dependent MIME type configurations. +- Recognize Page Templates by file extension for WebDAV. (`#1212 `_) - Clean up and fix installation documentation. diff --git a/MANIFEST.in b/MANIFEST.in index d7c1523a2d..8d9d6e273c 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -43,7 +43,6 @@ recursive-include src *.rst recursive-include src *.svg recursive-include src *.ttf recursive-include src *.txt -recursive-include src *.types recursive-include src *.webmanifest recursive-include src *.woff recursive-include src *.woff2 diff --git a/src/Products/PageTemplates/__init__.py b/src/Products/PageTemplates/__init__.py index 19e91ba625..62cac12138 100644 --- a/src/Products/PageTemplates/__init__.py +++ b/src/Products/PageTemplates/__init__.py @@ -15,10 +15,6 @@ This wrapper allows the Page Template modules to be segregated in a separate package. """ -import os - -from zope.contenttype import add_files - # Placeholder for Zope Product data misc_ = {} @@ -33,8 +29,3 @@ def initialize(context): # Import lazily, and defer initialization to the module from . import ZopePageTemplate ZopePageTemplate.initialize(context) - - # Add the custom MIME type information for Page Templates - # to the Python mimetypes module so they are recognized correctly - here = os.path.dirname(os.path.abspath(__file__)) - add_files([os.path.join(here, 'mime.types')]) diff --git a/src/Products/PageTemplates/mime.types b/src/Products/PageTemplates/mime.types deleted file mode 100644 index 2223b74bd5..0000000000 --- a/src/Products/PageTemplates/mime.types +++ /dev/null @@ -1 +0,0 @@ -application/vnd.zopefoundation.pagetemplate pt zpt diff --git a/src/webdav/NullResource.py b/src/webdav/NullResource.py index 1cbbbd3568..687803a3d7 100644 --- a/src/webdav/NullResource.py +++ b/src/webdav/NullResource.py @@ -114,9 +114,7 @@ def _default_PUT_factory(self, name, typ, body): if ext == '.dtml': ob = DTMLDocument('', __name__=name) - elif typ in ('text/html', - 'text/xml', - 'application/vnd.zopefoundation.pagetemplate'): + elif ext in ('.pt', '.zpt') or typ in ('text/html', 'text/xml'): ob = ZopePageTemplate(name, body, content_type=typ) elif typ.startswith('image/'): ob = Image(name, '', body, content_type=typ)