From dce1fc02d5455975468dcc676260b8319995e0e0 Mon Sep 17 00:00:00 2001 From: David Glick Date: Thu, 7 Nov 2024 14:06:20 -0800 Subject: [PATCH] Fix site creation script for Plone 6.1 --- backend_addon/cookiecutter.json | 11 +++++++---- .../constraints.txt | 2 +- .../scripts/create_site.py | 15 +++++++++++---- .../{{ cookiecutter.__folder_name }}/setup.py | 6 +++++- .../backend/scripts/create_site.py | 14 +++++++++----- 5 files changed, 33 insertions(+), 15 deletions(-) diff --git a/backend_addon/cookiecutter.json b/backend_addon/cookiecutter.json index be7b4b6..88fa36f 100644 --- a/backend_addon/cookiecutter.json +++ b/backend_addon/cookiecutter.json @@ -4,11 +4,10 @@ "author": "Plone Community", "email": "collective@plone.org", "github_organization": "collective", + "use_prerelease_versions": "{{ 'No' | use_prerelease_versions }}", + "plone_version": "{{ cookiecutter.use_prerelease_versions | latest_plone }}", "python_package_name": "{{ cookiecutter.github_organization|lower }}.{{ cookiecutter.title|replace(' ', '')|replace('-', '_')|replace('.', '')|lower }}", - "feature_headless": [ - "1", - "0" - ], + "feature_headless": ["1", "0"], "__feature_headless": "{{ cookiecutter.feature_headless }}", "__feature_distribution": "0", "__package_name": "{{ cookiecutter.python_package_name | package_name }}", @@ -26,6 +25,8 @@ "title": "Addon Title", "description": "A short description of your addon", "github_organization": "GitHub Username or Organization", + "use_prerelease_versions": "Should we use prerelease versions?", + "plone_version": "Plone Version", "python_package_name": "Python package name", "author": "Author", "email": "Author E-mail", @@ -37,6 +38,8 @@ }, "_copy_without_render": [], "_extensions": [ + "cookieplone.filters.latest_plone", + "cookieplone.filters.use_prerelease_versions", "cookieplone.filters.pascal_case", "cookieplone.filters.package_name", "cookieplone.filters.package_namespace" diff --git a/backend_addon/{{ cookiecutter.__folder_name }}/constraints.txt b/backend_addon/{{ cookiecutter.__folder_name }}/constraints.txt index 228b6cc..908d9db 100644 --- a/backend_addon/{{ cookiecutter.__folder_name }}/constraints.txt +++ b/backend_addon/{{ cookiecutter.__folder_name }}/constraints.txt @@ -1 +1 @@ --c https://dist.plone.org/release/6.0-latest/constraints.txt +-c https://dist.plone.org/release/{{ cookiecutter.plone_version }}/constraints.txt diff --git a/backend_addon/{{ cookiecutter.__folder_name }}/scripts/create_site.py b/backend_addon/{{ cookiecutter.__folder_name }}/scripts/create_site.py index e4e19f0..a1c2e42 100644 --- a/backend_addon/{{ cookiecutter.__folder_name }}/scripts/create_site.py +++ b/backend_addon/{{ cookiecutter.__folder_name }}/scripts/create_site.py @@ -2,6 +2,7 @@ from {{ cookiecutter.python_package_name }}.interfaces import IBrowserLayer from Products.CMFPlone.factory import _DEFAULT_PROFILE from Products.CMFPlone.factory import addPloneSite +from Products.GenericSetup.tool import SetupTool from Testing.makerequest import makerequest from zope.interface import directlyProvidedBy from zope.interface import directlyProvides @@ -43,9 +44,12 @@ def asbool(s): payload = { "title": "{{ cookiecutter.title }}", "profile_id": _DEFAULT_PROFILE, - "extension_ids": [ - "{{ cookiecutter.python_package_name }}:default", - ], +{% if cookiecutter.plone_version >= "6.1" and cookiecutter.__feature_headless == "0" -%} + "distribution_name": "classic", +{%- endif %} +{% if cookiecutter.plone_version >= "6.1" and cookiecutter.__feature_headless == "1" -%} + "distribution_name": "default", +{%- endif %} "setup_content": False, "default_language": "{{ cookiecutter.__profile_language }}", "portal_timezone": "UTC", @@ -59,4 +63,7 @@ def asbool(s): if site_id not in app.objectIds(): site = addPloneSite(app, site_id, **payload) transaction.commit() - app._p_jar.sync() + + portal_setup: SetupTool = site.portal_setup + portal_setup.runAllImportStepsFromProfile("profile-{{ cookiecutter.python_package_name }}:default") + transaction.commit() diff --git a/backend_addon/{{ cookiecutter.__folder_name }}/setup.py b/backend_addon/{{ cookiecutter.__folder_name }}/setup.py index 3677995..2c8828f 100644 --- a/backend_addon/{{ cookiecutter.__folder_name }}/setup.py +++ b/backend_addon/{{ cookiecutter.__folder_name }}/setup.py @@ -1,4 +1,5 @@ """Installer for the {{ cookiecutter.python_package_name }} package.""" + from pathlib import Path from setuptools import find_packages from setuptools import setup @@ -55,7 +56,7 @@ "setuptools", "Products.CMFPlone", "plone.api", - {%- if cookiecutter.__feature_headless == '1' %} + {% if cookiecutter.__feature_headless == '1' -%} "plone.restapi", "plone.volto", {%- endif %} @@ -65,6 +66,9 @@ "zest.releaser[recommended]", "zestreleaser.towncrier", "plone.app.testing", + {% if cookiecutter.__feature_headless == "0" and cookiecutter.plone_version >= "6.1" -%} + "plone.classicui", + {%- endif -%} "plone.restapi[test]", "pytest", "pytest-cov", diff --git a/sub/project_settings/{{ cookiecutter.__folder_name }}/backend/scripts/create_site.py b/sub/project_settings/{{ cookiecutter.__folder_name }}/backend/scripts/create_site.py index e61602c..a8c0cf6 100644 --- a/sub/project_settings/{{ cookiecutter.__folder_name }}/backend/scripts/create_site.py +++ b/sub/project_settings/{{ cookiecutter.__folder_name }}/backend/scripts/create_site.py @@ -45,9 +45,9 @@ def asbool(s): payload = { "title": "{{ cookiecutter.title }}", "profile_id": _DEFAULT_PROFILE, - "extension_ids": [ - "{{ cookiecutter.python_package_name }}:default", - ], +{% if cookiecutter.plone_version >= "6.1" %} + "distribution_name": "default", +{% endif %} "setup_content": False, "default_language": "{{ cookiecutter.__profile_language }}", "portal_timezone": "UTC", @@ -61,8 +61,12 @@ def asbool(s): if site_id not in app.objectIds(): site = addPloneSite(app, site_id, **payload) transaction.commit() + + portal_setup: SetupTool = site.portal_setup + portal_setup.runAllImportStepsFromProfile("profile-{{ cookiecutter.python_package_name }}:default") + transaction.commit() + if EXAMPLE_CONTENT: - portal_setup: SetupTool = site.portal_setup - portal_setup.runAllImportStepsFromProfile("{{ cookiecutter.python_package_name }}:initial") + portal_setup.runAllImportStepsFromProfile("profile-{{ cookiecutter.python_package_name }}:initial") transaction.commit() app._p_jar.sync()