Skip to content

Commit

Permalink
Merge pull request #3981 from plone/distributions
Browse files Browse the repository at this point in the history
Refactor site creation
  • Loading branch information
mauritsvanrees authored Oct 8, 2024
2 parents 840f075 + f62110e commit 0e91d5a
Show file tree
Hide file tree
Showing 17 changed files with 230 additions and 282 deletions.
88 changes: 17 additions & 71 deletions Products/CMFPlone/browser/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from importlib.metadata import distribution
from importlib.metadata import PackageNotFoundError
from OFS.interfaces import IApplication
from plone.base.interfaces import INonInstallable
from plone.base.interfaces import IPloneSiteRoot
from plone.base.utils import get_installer
from plone.i18n.locales.interfaces import IContentLanguageAvailability
Expand All @@ -15,16 +14,13 @@
from plone.protect.interfaces import IDisableCSRFProtection
from Products.CMFCore.permissions import ManagePortal
from Products.CMFPlone.factory import _DEFAULT_PROFILE
from Products.CMFPlone.factory import _TYPES_PROFILE
from Products.CMFPlone.factory import addPloneSite
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from Products.GenericSetup import BASE
from Products.GenericSetup import EXTENSION
from Products.GenericSetup import profile_registry
from Products.GenericSetup.upgrade import normalize_version
from urllib import parse
from ZODB.broken import Broken
from zope.component import adapter
from zope.component import getAllUtilitiesRegisteredFor
from zope.component import getUtility
from zope.component import queryMultiAdapter
from zope.component import queryUtility
Expand All @@ -46,6 +42,11 @@
HAS_VOLTO = True
except PackageNotFoundError:
HAS_VOLTO = False
try:
distribution("plone.app.caching")
HAS_CACHING = True
except PackageNotFoundError:
HAS_CACHING = False
try:
distribution("plone.app.upgrade")
HAS_UPGRADE = True
Expand All @@ -67,8 +68,6 @@ def publishTraverse(self, request, name):


class Overview(BrowserView):
has_volto = HAS_VOLTO

def sites(self, root=None):
if root is None:
root = self.context
Expand Down Expand Up @@ -155,67 +154,15 @@ class FrontPage(BrowserView):


class AddPloneSite(BrowserView):
# Profiles that are installed by default,
# but can be removed later.
default_extension_profiles = (
"plone.app.caching:default",
"plonetheme.barceloneta:default",
)
# Let's have a separate list for Volto.
volto_default_extension_profiles = (
"plone.app.caching:default",
"plonetheme.barceloneta:default",
"plone.volto:default",
)

def profiles(self):
base_profiles = []
extension_profiles = []
if HAS_VOLTO and not self.request.get("classic"):
selected_extension_profiles = self.volto_default_extension_profiles
else:
selected_extension_profiles = self.default_extension_profiles

# profiles available for install/uninstall, but hidden at the time
# the Plone site is created
not_installable = [
"Products.CMFPlacefulWorkflow:CMFPlacefulWorkflow",
]
utils = getAllUtilitiesRegisteredFor(INonInstallable)
for util in utils:
not_installable.extend(
util.getNonInstallableProfiles()
if hasattr(util, "getNonInstallableProfiles")
else []
)

for info in profile_registry.listProfileInfo():
if info.get("type") == EXTENSION and info.get("for") in (
IPloneSiteRoot,
None,
):
profile_id = info.get("id")
if profile_id not in not_installable:
if profile_id in selected_extension_profiles:
info["selected"] = "selected"
extension_profiles.append(info)

def _key(v):
# Make sure implicitly selected items come first
selected = v.get("selected") and "automatic" or "manual"
return "{}-{}".format(selected, v.get("title", ""))

extension_profiles.sort(key=_key)

for info in profile_registry.listProfileInfo():
if info.get("type") == BASE and info.get("for") in (IPloneSiteRoot, None):
base_profiles.append(info)

return dict(
base=tuple(base_profiles),
default=_DEFAULT_PROFILE,
extensions=tuple(extension_profiles),
)
@property
def default_extension_profiles(self):
# Profiles that are installed by default,
# but can be removed later.
profiles = [_TYPES_PROFILE]
if HAS_CACHING:
profiles.append("plone.app.caching:default")
profiles.append("plonetheme.barceloneta:default")
return profiles

def browser_language(self):
language = "en"
Expand Down Expand Up @@ -308,9 +255,8 @@ def __call__(self):
context,
site_id,
title=form.get("title", ""),
profile_id=form.get("profile_id", _DEFAULT_PROFILE),
extension_ids=form.get("extension_ids", ()),
setup_content=form.get("setup_content", False),
profile_id=_DEFAULT_PROFILE,
extension_ids=self.default_extension_profiles,
default_language=form.get("default_language", "en"),
portal_timezone=form.get("portal_timezone", "UTC"),
)
Expand Down
52 changes: 28 additions & 24 deletions Products/CMFPlone/browser/admin.zcml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser"
xmlns:zcml="http://namespaces.zope.org/zcml"
>

<browser:view
Expand All @@ -10,21 +11,34 @@
permission="zope.Public"
/>

<browser:page
name="plone-addsite"
for="OFS.interfaces.IApplication"
class=".admin.AddPloneSite"
template="templates/plone-addsite.pt"
permission="zope2.ViewManagementScreens"
/>
<configure zcml:condition="not-installed plone.distribution">
<adapter factory=".admin.AppTraverser" />

<browser:page
name="plone-addsite"
for="OFS.Folder.Folder"
class=".admin.AddPloneSite"
template="templates/plone-addsite.pt"
permission="zope2.ViewManagementScreens"
/>
<browser:page
name="plone-overview"
for="OFS.interfaces.IApplication"
class=".admin.Overview"
template="templates/plone-overview.pt"
permission="zope.Public"
/>

<browser:page
name="plone-addsite"
for="OFS.interfaces.IApplication"
class=".admin.AddPloneSite"
template="templates/plone-addsite.pt"
permission="zope2.ViewManagementScreens"
/>

<browser:page
name="plone-addsite"
for="OFS.Folder.Folder"
class=".admin.AddPloneSite"
template="templates/plone-addsite.pt"
permission="zope2.ViewManagementScreens"
/>

</configure>

<browser:page
name="plone-upgrade"
Expand All @@ -34,14 +48,6 @@
permission="cmf.ManagePortal"
/>

<browser:page
name="plone-overview"
for="OFS.interfaces.IApplication"
class=".admin.Overview"
template="templates/plone-overview.pt"
permission="zope.Public"
/>

<browser:page
name="plone-root-login"
for="OFS.interfaces.IApplication"
Expand All @@ -56,8 +62,6 @@
permission="zope.Public"
/>

<adapter factory=".admin.AppTraverser" />

<browser:resource
name="plone-admin-ui.css"
file="static/plone-admin-ui.css"
Expand Down
93 changes: 1 addition & 92 deletions Products/CMFPlone/browser/templates/plone-addsite.pt
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,7 @@
</header>
<form action="#"
method="post"
tal:attributes="action string:${context/absolute_url}/@@plone-addsite"
tal:define="profiles view/profiles;
base_profiles profiles/base;
default_profile profiles/default;
extension_profiles profiles/extensions;
advanced request/advanced|nothing;">
tal:attributes="action string:${context/absolute_url}/@@plone-addsite">
<article class="row">
<div class="col-md-12">
<h1><span i18n:translate="">Create a Plone site</span></h1>
Expand Down Expand Up @@ -120,92 +115,6 @@
</div>
</div>

<div class="col-md-12 mb-3"
tal:condition="advanced">
<div class="form-check">
<input class="form-check-input"
id="example-content"
type="checkbox"
name="setup_content:boolean"
checked="checked" />
<label class="form-check-label"
for="example-content"
i18n:translate="">Example content</label>
<div class="form-text" i18n:translate="">
Should the default example content be added to the site?
</div>
</div>
</div>

<input tal:condition="not:advanced"
type="hidden" name="setup_content:boolean" value="true" />

<div class="col-md-12"
tal:condition="python: len(base_profiles) > 1">
<div class="mb-3">
<p class="lead" i18n:translate="">Base configuration</p>

<div tal:repeat="info base_profiles"
class="form-check mb-3">
<input type="radio"
name="profile_id:string"
value="profile"
class="form-check-input"
tal:attributes="id info/id;
value info/id;
checked python: default_profile==info['id'] and 'checked' or nothing" />
<label class="form-check-label" tal:attributes="for info/id">${info/title}</label>
<div class="form-text" tal:content="info/description">${info/description}</div>
</div>

<div class="form-text" i18n:translate="">
You normally don't need to change anything here unless you have specific reasons and know what you are doing.
</div>

</div>
</div>


<div class="col-md-12 mt-3"
tal:define="has_selected python:[p for p in extension_profiles if p.get('selected', None)]"
tal:condition="python: extension_profiles or advanced"
tal:omit-tag="python: has_selected and not advanced">
<tal:block condition="python: advanced">
<h2 i18n:translate="">Add-ons</h2>

<div class="lead"
i18n:translate="" >
Select any add-ons you want to activate immediately.
You can also activate add-ons after the site has been created using the Add-ons control panel.
</div>
</tal:block>

<tal:loop tal:repeat="info extension_profiles">
<tal:set tal:define="selected info/selected|nothing">
<tal:normal tal:condition="python: not selected or advanced">
<div class="form-check mb-3"
tal:condition="python: advanced">
<input type="checkbox"
name="extension_ids:list"
value="${info/id}"
id="${info/id}"
class="form-check-input"
tal:attributes="checked info/selected|nothing;" />
<label class="form-check-label" for="${info/id}" >${info/title}</label>
<div class="form-text"
tal:condition="python: advanced and info['description']">
${info/description}
</div>
</div>
</tal:normal>
<tal:hidden tal:condition="python: selected and not advanced">
<input type="hidden"
name="extension_ids:list"
value="${info/id}" />
</tal:hidden>
</tal:set>
</tal:loop>
</div>
<div class="col-md-12 mt-3">
<input type="hidden" name="form.submitted:boolean" value="True" />
<button class="btn btn-success mt-3" type="submit" name="submit" i18n:translate="">Create Plone Site</button>
Expand Down
22 changes: 6 additions & 16 deletions Products/CMFPlone/browser/templates/plone-overview.pt
Original file line number Diff line number Diff line change
Expand Up @@ -87,24 +87,9 @@
<input type="hidden" name="site_id" value="Plone${site_number}" />
<button type="submit"
class="btn btn-${python:'success' if sites else 'primary'}"
i18n:translate="">Create a new Plone site</button>
<a class="btn btn-info"
i18n:translate=""
tal:condition="view/has_volto"
href="${action}?site_id=Plone${site_number}&amp;classic=1"
>Create Classic UI Plone site</a>
<a class="btn btn-secondary"
i18n:translate=""
href="${action}?site_id=Plone${site_number}&amp;advanced=1"
>Advanced</a>
i18n:translate="">Create Classic UI Plone site</button>
</form>
<br/>
<p i18n:translate="help_create_plone_site_buttons_1">
Starting with Plone 6, 'Create a new Plone site' applies a
profile and creates default content for the new React based
default frontend Volto. You are however required to set up and run
an additional frontend service to use this setup.
</p>
<p i18n:translate="help_create_plone_site_buttons_2">
The 'Create Classic UI Plone site' button creates a Plone site configured
for HTML based output, as was already supported by previous Plone versions.
Expand All @@ -117,6 +102,11 @@
these frontends and possible upgrade paths from older Plone versions
to Plone 6.
</p>
<p i18n:translate="help_create_plone_site_buttons_3">
Starting with Plone 6.1, default content is not loaded into the site.
If you want to load the default content, you should install the <code>plone.classicui</code> package.
If you see this text, that means you have not installed that package yet.
</p>
</div>
</article>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ def setUp(self):

def test_search_control_panel_link(self):
self.browser.open("%s/@@overview-controlpanel" % self.portal_url)
self.browser.getLink("Search").click()
# The first "Search" link actually points to "Advanced Search"...
# self.browser.getLink("Search").click()
self.browser.getLink(url=f"{self.portal_url}/@@search-controlpanel").click()

def test_search_control_panel_backlink(self):
self.browser.open("%s/@@search-controlpanel" % self.portal_url)
Expand Down
Loading

0 comments on commit 0e91d5a

Please sign in to comment.