Skip to content

Commit

Permalink
Use plone.distribution and add voltodemo with testdata (#35)
Browse files Browse the repository at this point in the history
* Use plone.distribution and add voltodemo with testdata

* use distribution when creating the site

* update checkouts

* Fix create_site

* Fix system block style

* Some more demo content

* fix create_site (again)

* add copy of footer to customize

* remove company branding

* Update setup for python 3.12

* Add classicdemo distribution

* Add content to distribution

* remove old import-data

* make format

* remove obsolete checkouts and fix isort

* Add changenote

* update demo content

* remove checkouts after release

* add more example content, partly from the old vlt demo page

* content cleanup

* hide home tab and fix zpretty

* update create-site script

* Fix making forms translatable

* fix python-version check

* shamelessly steal better create-site script from plone.edu

* fix all references to images

* flake8

* store form data (to be able to test form block)
  • Loading branch information
pbauer authored Mar 12, 2024
1 parent 43725d5 commit 5f1eb20
Show file tree
Hide file tree
Showing 190 changed files with 26,571 additions and 756 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# 2024-03-08

- Switch to plone.distribution. [pbauer]

- Add distribution voltodemo, use volto-light-theme and add some demo content. [pbauer]

- Add distribution classicdemo and add easyform. [pbauer]

# 2024-02-23

- Run a single workflow for build and deploy, twice a day. [fredvd]
Expand Down
12 changes: 8 additions & 4 deletions backend/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ GREEN=`tput setaf 2`
RESET=`tput sgr0`
YELLOW=`tput setaf 3`

# Set distributions still in development
DISTRIBUTIONS="voltodemo"
ALLOWED_DISTRIBUTIONS="voltodemo"

PLONE_VERSION=6.0.10.1

BACKEND_FOLDER=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
Expand Down Expand Up @@ -42,7 +46,7 @@ endif
# version ok?
PYTHON_VERSION_MIN=3.8
PYTHON_VERSION_OK=$(shell $(PYTHON) -c "import sys; print((int(sys.version_info[0]), int(sys.version_info[1])) >= tuple(map(int, '$(PYTHON_VERSION_MIN)'.split('.'))))")
ifeq ($(PYTHON_VERSION_OK),0)
ifeq ($(PYTHON_VERSION_OK),False)
$(error "Need python $(PYTHON_VERSION) >= $(PYTHON_VERSION_MIN)")
endif

Expand Down Expand Up @@ -87,7 +91,7 @@ clean-test: ## remove test and coverage artifacts
bin/pip:
@echo "$(GREEN)==> Setup Virtual Env$(RESET)"
$(PYTHON) -m venv .
bin/pip install -U "pip" "wheel" "cookiecutter" "mxdev"
bin/pip install -U "setuptools" "pip" "wheel" "cookiecutter" "mxdev"

.PHONY: config
config: bin/pip ## Create instance configuration
Expand Down Expand Up @@ -150,8 +154,8 @@ test_quiet: ## run tests removing deprecation warnings
PYTHONWARNINGS=ignore ./bin/zope-testrunner --auto-color --auto-progress --test-path src/plone6demo/src/

.PHONY: create-site
create-site: instance/etc/zope.ini ## Create a new site from scratch
PYTHONWARNINGS=ignore ./bin/zconsole run instance/etc/zope.conf ./scripts/create_site.py
create-site: ## Create a new site using default distribution and default answers
DEVELOP_DISTRIBUTIONS=$(DISTRIBUTIONS) ALLOWED_DISTRIBUTIONS=$(DISTRIBUTIONS) PYTHONWARNINGS=ignore ./bin/zconsole run instance/etc/zope.conf scripts/create-site.py

.PHONY: start
start: ## Start a Plone instance on localhost:8080
Expand Down
3 changes: 1 addition & 2 deletions backend/instance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ default_context:
initial_user_name: 'admin'
initial_user_password: 'admin'

load_zcml:
package_includes: ['plone6demo']
zcml_package_includes: 'plone6demo'

db_storage: direct
98 changes: 98 additions & 0 deletions backend/scripts/create-site.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
from AccessControl.SecurityManagement import newSecurityManager
from pathlib import Path
from plone.distribution.api import site as site_api
from Testing.makerequest import makerequest

import json
import logging
import os
import transaction


logging.basicConfig(format="%(message)s")

# Silence some loggers
for logger_name in [
"GenericSetup.componentregistry",
"Products.MimetypesRegistry.MimeTypesRegistry",
]:
logging.getLogger(logger_name).setLevel(logging.ERROR)

logger = logging.getLogger("Plone Site Creation")
logger.setLevel(logging.DEBUG)

SCRIPT_DIR = Path().cwd() / "scripts"

truthy = frozenset(("t", "true", "y", "yes", "on", "1"))


def asbool(s):
"""Return the boolean value ``True`` if the case-lowered value of string
input ``s`` is a :term:`truthy string`. If ``s`` is already one of the
boolean values ``True`` or ``False``, return it."""
if s is None:
return False
if isinstance(s, bool):
return s
s = str(s).strip()
return s.lower() in truthy


app = makerequest(globals()["app"])

request = app.REQUEST

admin = app.acl_users.getUserById("admin")
admin = admin.__of__(app.acl_users)
newSecurityManager(None, admin)


def get_answers_file() -> Path:
filename = f"{ANSWERS}.json"
return SCRIPT_DIR / filename


def parse_answers(answers_file: Path, site_id: str = "") -> dict:
answers = json.loads(answers_file.read_text())
if "distribution" not in answers:
# This is a bug in plone.distribution and should be fixed there
answers["distribution"] = DISTRIBUTION
if site_id:
answers["site_id"] = site_id
return answers


# VARS
DISTRIBUTION = os.getenv("DISTRIBUTION", "voltodemo")
SITE_ID = os.getenv("SITE_ID") # if set, this overrides the value in ANSWERS
ANSWERS = os.getenv("ANSWERS", "default")
DELETE_EXISTING = asbool(os.getenv("DELETE_EXISTING"))

# Load site creation parameters
answers_file = get_answers_file()
answers = parse_answers(answers_file, SITE_ID)
site_id = answers["site_id"]


logger.info(f"Creating a new Plone site @ {site_id}")
logger.info(f" - Using the {DISTRIBUTION} distribution and answers from {answers_file}")


if site_id in app.objectIds() and DELETE_EXISTING:
app.manage_delObjects([site_id])
transaction.commit()
app._p_jar.sync()
logger.info(f" - Deleted existing site with id {site_id}")
else:
logger.info(
f" - Stopping site creation, as there is already a site with id {site_id}. "
"Set DELETE_EXISTING=1 to delete the existing site before creating a new one."
)

if site_id not in app.objectIds():
site = site_api._create_site(
context=app, distribution_name=DISTRIBUTION, answers=answers
)
transaction.commit()
app._p_jar.sync()
logger.info(" - Site created!")
62 changes: 0 additions & 62 deletions backend/scripts/create_site.py

This file was deleted.

8 changes: 8 additions & 0 deletions backend/scripts/default.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"site_id": "Plone",
"title": "Welcome to Plone 6",
"description": "Site created with a new Plone Distribution",
"default_language": "en",
"portal_timezone": "Europe/Berlin",
"setup_content": true
}
8 changes: 7 additions & 1 deletion backend/src/plone6demo/setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Installer for the plone6demo package."""

from setuptools import find_packages
from setuptools import setup

Expand All @@ -22,9 +23,13 @@
"Framework :: Plone",
"Framework :: Plone :: Addon",
"Framework :: Plone :: 6.0",
"Framework :: Plone :: Distribution",
"Programming Language :: Python",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Operating System :: OS Independent",
"License :: OSI Approved :: GNU General Public License v2 (GPLv2)",
],
Expand All @@ -46,8 +51,9 @@
install_requires=[
"setuptools",
"Plone",
"prettyconf",
"plone.api",
"plone.distribution",
"collective.volto.formsupport",
],
extras_require={
"test": [
Expand Down
12 changes: 12 additions & 0 deletions backend/src/plone6demo/src/plone6demo/configure.zcml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:i18n="http://namespaces.zope.org/i18n"
xmlns:plone="http://namespaces.plone.org/plone"
i18n_domain="plone6demo"
>

Expand All @@ -14,6 +15,10 @@
package="plone.behavior"
file="meta.zcml"
/>
<include
package="plone.distribution"
file="meta.zcml"
/>

<include file="dependencies.zcml" />

Expand All @@ -28,4 +33,11 @@
<include package=".services" />
<include package=".subscribers" />

<plone:distribution
name="voltodemo"
title="Volto Demo Site"
description="A Plone 6 Site with demo content"
directory="distributions/voltodemo"
/>

</configure>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 5f1eb20

Please sign in to comment.