Skip to content

Commit

Permalink
add new field and Rename service endpoint to *@editable-footer-data* …
Browse files Browse the repository at this point in the history
…and changed its data structure
  • Loading branch information
cekk committed Jan 31, 2024
1 parent a13a2b9 commit 5b16204
Show file tree
Hide file tree
Showing 18 changed files with 196 additions and 142 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*.py?
*.swp
# dirs
__pycache__/
bin/
buildout-cache/
develop-eggs/
Expand Down
5 changes: 4 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ Changelog
1.2.2 (unreleased)
------------------

- Nothing changed yet.
- Add footer_top field in settings, to manage a new footer row before columns.
[cekk]
- [BREAKING] Rename service endpoint to *@editable-footer-data* and changed its data structure.
[cekk]


1.2.1 (2024-01-17)
Expand Down
28 changes: 15 additions & 13 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,25 @@ Volto endpoint

Anonymous users can't access registry resources by default with plone.restapi (there is a special permission).

To avoid enabling registry access to everyone, this package exposes a dedicated restapi route with the infos to draw the menu: *@footer-columns*::
To avoid enabling registry access to everyone, this package exposes a dedicated restapi route with the infos to draw the menu: *@editable-footer-data*::

> curl -i http://localhost:8080/Plone/@footer-columns -H 'Accept: application/json'
> curl -i http://localhost:8080/Plone/@editable-footer-data -H 'Accept: application/json'


The response is something similar to this::

[
{
'text': {'data': '<span>foo</span>'},
'title': 'First column'
},
{
'text': {'content-type': 'text/html', 'data': ''},
'title': 'Second column'
}
]
{
"footer_top": {...},
"footer_columns": [
{
'text': {'data': '<span>foo</span>'},
'title': 'First column'
},
{
'text': {'content-type': 'text/html', 'data': ''},
'title': 'Second column'
}
]
}


Control panel
Expand Down
2 changes: 2 additions & 0 deletions src/redturtle/voltoplugin/editablefooter/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

<include package=".browser" />
<include package=".restapi" />
<include package=".upgrades" />


<include file="permissions.zcml" />

Expand Down
9 changes: 9 additions & 0 deletions src/redturtle/voltoplugin/editablefooter/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ class IRedturtleVoltoEditablefooterLayer(IDefaultBrowserLayer):


class IEditableFooterSettings(IControlpanel):
footer_top = SourceText(
title=_("footer_top_label", default="Footer top"),
description=_(
"footer_top_help",
default="Insert some text that will be shown as first element in the footer, before the columns.",
),
required=False,
default="",
)
footer_columns = SourceText(
title=_("footer_columns_label", default="Footer columns"),
description=_(
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2020-10-08 14:24+0000\n"
"POT-Creation-Date: 2024-01-31 11:22+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI +ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand All @@ -18,38 +18,48 @@ msgstr ""
msgid "Editable footer settings"
msgstr "Impostazioni footer"

#: redturtle/voltoplugin/editablefooter/configure.zcml:28
#: redturtle/voltoplugin/editablefooter/configure.zcml:31
msgid "Installs the redturtle.voltoplugin.editablefooter add-on."
msgstr "Installa redturtle.voltoplugin.editablefooter"

#: redturtle/voltoplugin/editablefooter/configure.zcml:37
#: redturtle/voltoplugin/editablefooter/configure.zcml:40
msgid "Uninstalls the redturtle.voltoplugin.editablefooter add-on."
msgstr "Disinstalla redturtle.voltoplugin.editablefooter"

#: redturtle/voltoplugin/editablefooter/configure.zcml:31
msgid "Volto Editable Footer"
msgstr "Volto Editable Footer"

#: redturtle/voltoplugin/editablefooter/configure.zcml:40
msgid "Volto Editable Footer (uninstall)"
msgstr "Volto Editable Footer (uninstall"

#. Default: "Set infos for columns in footer."
#: redturtle/voltoplugin/editablefooter/browser/controlpanel.py:13
#: redturtle/voltoplugin/editablefooter/browser/controlpanel.py:12
msgid "editable_footer_settings_help"
msgstr "Imposta i dati per le colonne del footer."

#. Default: "Editable Footer Settings"
#: redturtle/voltoplugin/editablefooter/browser/controlpanel.py:10
#: redturtle/voltoplugin/editablefooter/browser/controlpanel.py:11
msgid "editable_footer_settings_label"
msgstr "Impostazioni footer"

#. Default: "Set a list of custom columns for the footer. You can have different sets for each portal's languages."
#: redturtle/voltoplugin/editablefooter/interfaces.py:15
#: redturtle/voltoplugin/editablefooter/interfaces.py:24
msgid "footer_columns_help"
msgstr "Configura una serie di colonne per il footer. Puoi creare differenti impostazioni per le varie lingue del sito."

#. Default: "Footer columns"
#: redturtle/voltoplugin/editablefooter/interfaces.py:14
#: redturtle/voltoplugin/editablefooter/interfaces.py:23
msgid "footer_columns_label"
msgstr "Colonne footer"

#: redturtle/voltoplugin/editablefooter/configure.zcml:28
msgid "redturtle.voltoplugin.editablefooter"
msgstr ""
#. Default: "Insert some text that will be shown as first element in the footer, before the columns."
#: redturtle/voltoplugin/editablefooter/interfaces.py:15
msgid "footer_top_help"
msgstr "Inserisci del testo che apparirà come primo elemento nel footer, sopra alle colonne."

#: redturtle/voltoplugin/editablefooter/configure.zcml:37
msgid "redturtle.voltoplugin.editablefooter (uninstall)"
msgstr ""
#. Default: "Footer top"
#: redturtle/voltoplugin/editablefooter/interfaces.py:14
msgid "footer_top_label"
msgstr "Testata del footer"
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# --- PLEASE EDIT THE LINES BELOW CORRECTLY ---
# SOME DESCRIPTIVE TITLE.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#--- PLEASE EDIT THE LINES BELOW CORRECTLY ---
#SOME DESCRIPTIVE TITLE.
#FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2020-10-08 14:24+0000\n"
"POT-Creation-Date: 2024-01-31 11:22+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI +ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand All @@ -21,38 +21,48 @@ msgstr ""
msgid "Editable footer settings"
msgstr ""

#: redturtle/voltoplugin/editablefooter/configure.zcml:28
#: redturtle/voltoplugin/editablefooter/configure.zcml:31
msgid "Installs the redturtle.voltoplugin.editablefooter add-on."
msgstr ""

#: redturtle/voltoplugin/editablefooter/configure.zcml:37
#: redturtle/voltoplugin/editablefooter/configure.zcml:40
msgid "Uninstalls the redturtle.voltoplugin.editablefooter add-on."
msgstr ""

#: redturtle/voltoplugin/editablefooter/configure.zcml:31
msgid "Volto Editable Footer"
msgstr ""

#: redturtle/voltoplugin/editablefooter/configure.zcml:40
msgid "Volto Editable Footer (uninstall)"
msgstr ""

#. Default: "Set infos for columns in footer."
#: redturtle/voltoplugin/editablefooter/browser/controlpanel.py:13
#: redturtle/voltoplugin/editablefooter/browser/controlpanel.py:12
msgid "editable_footer_settings_help"
msgstr ""

#. Default: "Editable Footer Settings"
#: redturtle/voltoplugin/editablefooter/browser/controlpanel.py:10
#: redturtle/voltoplugin/editablefooter/browser/controlpanel.py:11
msgid "editable_footer_settings_label"
msgstr ""

#. Default: "Set a list of custom columns for the footer. You can have different sets for each portal's languages."
#: redturtle/voltoplugin/editablefooter/interfaces.py:15
#: redturtle/voltoplugin/editablefooter/interfaces.py:24
msgid "footer_columns_help"
msgstr ""

#. Default: "Footer columns"
#: redturtle/voltoplugin/editablefooter/interfaces.py:14
#: redturtle/voltoplugin/editablefooter/interfaces.py:23
msgid "footer_columns_label"
msgstr ""

#: redturtle/voltoplugin/editablefooter/configure.zcml:28
msgid "redturtle.voltoplugin.editablefooter"
#. Default: "Insert some text that will be shown as first element in the footer, before the columns."
#: redturtle/voltoplugin/editablefooter/interfaces.py:15
msgid "footer_top_help"
msgstr ""

#: redturtle/voltoplugin/editablefooter/configure.zcml:37
msgid "redturtle.voltoplugin.editablefooter (uninstall)"
#. Default: "Footer top"
#: redturtle/voltoplugin/editablefooter/interfaces.py:14
msgid "footer_top_label"
msgstr ""
4 changes: 2 additions & 2 deletions src/redturtle/voltoplugin/editablefooter/locales/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

domain = "redturtle.voltoplugin.editablefooter"
os.chdir(pkg_resources.resource_filename(domain, ""))
os.chdir("../../../")
os.chdir("../../../../")
target_path = "src/redturtle/voltoplugin/editablefooter/"
locale_path = target_path + "locales/"
i18ndude = "./bin/i18ndude"
Expand All @@ -31,7 +31,7 @@ def locale_folder_setup():
)
subprocess.call(cmd, shell=True)

os.chdir("../../../../")
os.chdir("../../../../../")


def _rebuild():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<version>1000</version>
<version>1001</version>
<dependencies>
<dependency>profile-plone.restapi:default</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
<!-- endpoint to get footer data -->
<plone:service
method="GET"
factory=".get.FooterColumns"
factory=".get.EditableFooterGet"
for="Products.CMFCore.interfaces.ISiteRoot"
permission="zope2.View"
name="@footer-columns"
name="@editable-footer-data"
/>

<cache:ruleset
for=".get.FooterColumns"
for=".get.EditableFooterGet"
ruleset="plone.content.dynamic"
/>
</configure>
14 changes: 10 additions & 4 deletions src/redturtle/voltoplugin/editablefooter/restapi/deserializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,21 @@ def __call__(self):
req = json_body(self.controlpanel.request)
proxy = self.registry.forInterface(self.schema, prefix=self.schema_prefix)
errors = []
data = req.get("footer_columns", {})
if not data:
footer_top = req.get("footer_top", {})
footer_columns = req.get("footer_columns", {})

if not footer_columns:
errors.append({"message": "Missing data", "field": "footer_columns"})
raise BadRequest(errors)
try:
# later we need to do some validations
setattr(proxy, "footer_columns", json.dumps(data))
setattr(proxy, "footer_columns", json.dumps(footer_columns))
except ValueError as e:
errors.append({"message": str(e), "field": "footer_columns", "error": e})

try:
# later we need to do some validations
setattr(proxy, "footer_top", json.dumps(footer_top))
except ValueError as e:
errors.append({"message": str(e), "field": "footer_top", "error": e})
if errors:
raise BadRequest(errors)
22 changes: 13 additions & 9 deletions src/redturtle/voltoplugin/editablefooter/restapi/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,20 @@


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

class EditableFooterGet(Service):
def reply(self):
record = api.portal.get_registry_record(
res = {"footer_top": None, "footer_columns": None}
footer_top = api.portal.get_registry_record(
"footer_top", interface=IEditableFooterSettings, default=""
)
footer_columns = api.portal.get_registry_record(
"footer_columns", interface=IEditableFooterSettings, default=""
)
if not record:
return []
data = json.loads(record)
if footer_top:
res["footer_top"] = json.loads(footer_top)
if not footer_columns:
return res
data = json.loads(footer_columns)
portal_url = self.get_portal_url()
for el in data or []:
if isinstance(el, dict):
Expand All @@ -44,7 +47,8 @@ def reply(self):
item["text"]["data"] = item["text"]["data"].replace(
'href="/', f'href="{portal_url}/'
)
return data
res["footer_columns"] = data
return res

def get_portal_url(self):
portal_url = api.portal.get().absolute_url()
Expand Down
Loading

0 comments on commit 5b16204

Please sign in to comment.