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

Add new field and changed its data structure #6

Merged
merged 4 commits into from
Mar 7, 2024
Merged
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
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
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ Changelog
1.2.2 (unreleased)
------------------

- Nothing changed yet.
- Add footer_top field in settings, to manage a new footer row before columns.
[cekk]


1.2.1 (2024-01-17)
Expand Down
23 changes: 13 additions & 10 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,19 @@ To avoid enabling registry access to everyone, this package exposes a dedicated

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"
/>

<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
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
class EditableFooterControlpanelSerializeToJson(ControlpanelSerializeToJson):
def __call__(self):
json_data = super(EditableFooterControlpanelSerializeToJson, self).__call__()
conf = json_data["data"].get("footer_columns", "")
if conf:
json_data["data"]["footer_columns"] = json.loads(conf)
for field in ["footer_columns", "footer_top"]:
value = json_data["data"].get(field, "")
if value:
json_data["data"][field] = json.loads(value)
return json_data
Loading
Loading