diff --git a/src/redturtle/volto/browser/configure.zcml b/src/redturtle/volto/browser/configure.zcml
index 5d5d0c6..147c44c 100644
--- a/src/redturtle/volto/browser/configure.zcml
+++ b/src/redturtle/volto/browser/configure.zcml
@@ -33,15 +33,15 @@
-
diff --git a/src/redturtle/volto/browser/site_helpers_views.py b/src/redturtle/volto/browser/site_helpers_views.py
index 3a0f727..84b5d6e 100644
--- a/src/redturtle/volto/browser/site_helpers_views.py
+++ b/src/redturtle/volto/browser/site_helpers_views.py
@@ -3,6 +3,12 @@
from plone.namedfile.file import NamedImage
from plone.registry.interfaces import IRegistry
from zope.component import getUtility
+from redturtle.volto.interfaces import IRegistryImagesView
+from zope.interface import implementer
+from Products.Five import BrowserView
+from zope.publisher.interfaces import IPublishTraverse
+from zope.publisher.interfaces import NotFound
+from redturtle.volto.restapi.services.utils import FIELD_MAPPING
try:
@@ -11,29 +17,38 @@
from Products.CMFPlone.interfaces.controlpanel import ISiteSchema
-class BaseView(Download):
- def __init__(self, context, request):
- super().__init__(context, request)
- self.filename = None
- self.data = None
+@implementer(IRegistryImagesView)
+class RegistryImagesView(BrowserView):
+ """"""
- registry = getUtility(IRegistry)
- settings = registry.forInterface(ISiteSchema, prefix="plone")
- value = getattr(settings, self.field_name, False)
- if value:
- filename, data = b64decode_file(value)
- data = NamedImage(data=data, filename=filename)
- self.data = data
- self.filename = filename
- # self.width, self.height = self.data.getImageSize()
+ def __call__(self):
+ return
- def _getFile(self):
- return self.data
+@implementer(IPublishTraverse)
+class ImagesView(Download):
-class Favicon(BaseView):
- field_name = "site_favicon"
+ def __init__(self, context, request):
+ super().__init__(context=context, request=request)
+ self.data = None
+ def publishTraverse(self, request, name):
+ super().publishTraverse(request=request, name=name)
+
+ if self.fieldname:
+ registry = getUtility(IRegistry)
+ registry_interface = FIELD_MAPPING.get(self.fieldname, None)
+ if not registry_interface:
+ raise NotFound(self, "a", self.request)
+ settings = registry.forInterface(registry_interface, prefix="plone")
+ value = getattr(settings, self.fieldname, None)
+ if value:
+ filename, data = b64decode_file(value)
+ data = NamedImage(data=data, filename=filename)
+ self.data = data
+ return self
-class LogoFooter(BaseView):
- field_name = "site_logo_footer"
+ def _getFile(self):
+ if not self.data:
+ raise NotFound(self, "b", self.request)
+ return self.data
diff --git a/src/redturtle/volto/interfaces.py b/src/redturtle/volto/interfaces.py
index ae90079..9f0ff19 100644
--- a/src/redturtle/volto/interfaces.py
+++ b/src/redturtle/volto/interfaces.py
@@ -111,3 +111,9 @@ class IRedTurtleVoltoSiteSchema(ISiteSchema, IRedTurtleVoltoAdditionalSiteSchema
class IRedTurtleVoltoSiteControlpanel(IControlpanel):
""" """
+
+
+class IRegistryImagesView(Interface):
+ """
+ Marker interface for view
+ """
diff --git a/src/redturtle/volto/restapi/services/site/get.py b/src/redturtle/volto/restapi/services/site/get.py
index 0247706..6b2abad 100644
--- a/src/redturtle/volto/restapi/services/site/get.py
+++ b/src/redturtle/volto/restapi/services/site/get.py
@@ -7,6 +7,7 @@
from plone.restapi.services.site.get import Site as BaseSite
from plone.restapi.services.site.get import SiteGet as BaseSiteGet
from redturtle.volto.interfaces import IRedTurtleVoltoAdditionalSiteSchema
+from redturtle.volto.restapi.services.utils import FIELD_MAPPING
from zope.component import adapter
from zope.component import getUtility
from zope.interface import implementer
@@ -34,7 +35,6 @@ def __call__(self, expand=False):
result = super().__call__(expand=expand)
registry = getUtility(IRegistry)
- site_settings = registry.forInterface(ISiteSchema, prefix="plone", check=False)
additional_settings = registry.forInterface(
IRedTurtleVoltoAdditionalSiteSchema, prefix="plone", check=False
)
@@ -53,29 +53,23 @@ def __call__(self, expand=False):
result["site"]["plone.site_subtitle"] = self.get_translated_value(site_subtitle)
# images
- field_mapping = {
- "logo": site_settings,
- "logo_footer": additional_settings,
- "favicon": site_settings,
- }
site_url = api.portal.get().absolute_url()
- for field, settings_name in field_mapping.items():
- value = self.get_value_from_registry(settings_name, f"site_{field}")
- result["site"][f"plone.site_{field}"] = {}
+ for field, interface_name in FIELD_MAPPING.items():
+ settings = registry.forInterface(
+ interface_name, prefix="plone", check=False
+ )
+ value = self.get_value_from_registry(settings, field)
+ result["site"][f"plone.{field}"] = {}
if value:
filename, data = b64decode_file(value)
- result["site"][f"plone.site_{field}"][
+ result["site"][f"plone.{field}"][
"url"
- ] = f"{site_url}/@@site-{field}/{filename}"
- result["site"][f"plone.site_{field}"]["width"] = (
- self.get_value_from_registry(
- additional_settings, f"site_{field}_width"
- )
+ ] = f"{site_url}/registry-images/@@images/{field}/{filename}"
+ result["site"][f"plone.{field}"]["width"] = (
+ self.get_value_from_registry(additional_settings, f"{field}_width")
)
- result["site"][f"plone.site_{field}"]["height"] = (
- self.get_value_from_registry(
- additional_settings, f"site_{field}_height"
- )
+ result["site"][f"plone.{field}"]["height"] = (
+ self.get_value_from_registry(additional_settings, f"{field}_height")
)
return result
diff --git a/src/redturtle/volto/restapi/services/utils.py b/src/redturtle/volto/restapi/services/utils.py
new file mode 100644
index 0000000..680d40a
--- /dev/null
+++ b/src/redturtle/volto/restapi/services/utils.py
@@ -0,0 +1,12 @@
+from redturtle.volto.interfaces import IRedTurtleVoltoAdditionalSiteSchema
+
+try:
+ from plone.base.interfaces.controlpanel import ISiteSchema
+except ImportError:
+ from Products.CMFPlone.interfaces.controlpanel import ISiteSchema
+
+FIELD_MAPPING = {
+ "site_logo": ISiteSchema,
+ "site_logo_footer": IRedTurtleVoltoAdditionalSiteSchema,
+ "site_favicon": ISiteSchema,
+}