Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added settings controlpanel with custom css field #68

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions backend/src/ploneorg/src/ploneorg/browser/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@
type="plone"
/>

<!-- Ploneorg settings controlpanel -->
<browser:page
name="ploneorg-settings"
for="Products.CMFPlone.interfaces.IPloneSiteRoot"
class="..controlpanel.PloneorgSettings"
permission="cmf.ManagePortal"
layer="ploneorg.interfaces.IPLONEORGLayer"
/>


<!-- Import stuff (for migration only) -->
<browser:page
name="import_content"
Expand Down
16 changes: 16 additions & 0 deletions backend/src/ploneorg/src/ploneorg/controlpanel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from plone.app.registry.browser.controlpanel import (
ControlPanelFormWrapper,
RegistryEditForm,
)
from ploneorg import _
from ploneorg.interfaces import IPLONEORGSettings


class PloneorgSettingsForm(RegistryEditForm):
schema = IPLONEORGSettings
label = _("ploneorg_settings_label", default="Plone.org Settings")
description = ""


class PloneorgSettings(ControlPanelFormWrapper):
form = PloneorgSettingsForm
16 changes: 16 additions & 0 deletions backend/src/ploneorg/src/ploneorg/interfaces.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
"""Module where all interfaces, events and exceptions live."""

from plone.restapi.controlpanels.interfaces import IControlpanel
from ploneorg import _
from zope.publisher.interfaces.browser import IDefaultBrowserLayer
from zope.schema import SourceText


class IPLONEORGLayer(IDefaultBrowserLayer):
"""Marker interface that defines a browser layer."""


class IPLONEORGSettings(IControlpanel):
custom_css = SourceText(
title=_("custom_css_label", default="Custom CSS"),
description=_(
"custom_css_help",
default="Add custom CSS in your site. \n"
"Warning: use this at your own risk!",
),
required=False,
default="",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0"?>
<object
name="portal_controlpanel"
xmlns:i18n="http://xml.zope.org/namespaces/i18n"
i18n:domain="ploneorg"
purge="False">

<configlet
title="Plone.org Settings"
action_id="ploneorg-settings"
appId="ploneorg"
category="Products"
condition_expr=""
url_expr="string:${portal_url}/@@ploneorg-settings"
icon_expr=""
visible="True"
i18n:attributes="title">
<permission>Manage portal</permission>
</configlet>

</object>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<registry>
<records interface="ploneorg.interfaces.IPLONEORGSettings" />
</registry>
3 changes: 3 additions & 0 deletions backend/src/ploneorg/src/ploneorg/services/configure.zcml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<configure xmlns="http://namespaces.zope.org/zope">

<include package=".controlpanel" />
<include package=".custom_css" />

</configure>
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<configure xmlns="http://namespaces.zope.org/zope">

<!-- controlpanel service -->
<adapter
factory=".controlpanel.PloneorgSettingsControlpanel"
provides="ploneorg.interfaces.IPLONEORGSettings"
name="ploneorg-settings"
/>

</configure>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from plone.restapi.controlpanels import RegistryConfigletPanel
from ploneorg.interfaces import IPLONEORGLayer, IPLONEORGSettings
from zope.component import adapter
from zope.interface import Interface, implementer


@adapter(Interface, IPLONEORGLayer)
@implementer(IPLONEORGSettings)
class PloneorgSettingsControlpanel(RegistryConfigletPanel):
schema = IPLONEORGSettings
configlet_id = "ploneorg-settings"
configlet_category_id = "Products"
schema_prefix = None
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:plone="http://namespaces.plone.org/plone"
xmlns:zcml="http://namespaces.zope.org/zcml"
>


<!-- endpoint to get custom css -->
<plone:service
method="GET"
factory=".get.CustomCSS"
for="Products.CMFCore.interfaces.ISiteRoot"
permission="zope2.View"
name="@custom-css"
/>


</configure>
18 changes: 18 additions & 0 deletions backend/src/ploneorg/src/ploneorg/services/custom_css/get.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
from plone import api
from plone.restapi.services import Service
from ploneorg.interfaces import IPLONEORGSettings
from zope.interface import implementer
from zope.publisher.interfaces import IPublishTraverse


@implementer(IPublishTraverse)
class CustomCSS(Service):
def __init__(self, context, request):
super(CustomCSS, self).__init__(context, request)

def reply(self):
record = api.portal.get_registry_record(
"custom_css", interface=IPLONEORGSettings, default=""
)
return {"data": record}