Skip to content

Commit

Permalink
WEB-3732 : Add smartweb settings to customize sendinblue subscribing …
Browse files Browse the repository at this point in the history
…button (text and position)
  • Loading branch information
boulch committed Aug 12, 2022
1 parent 5301d16 commit 27f8156
Show file tree
Hide file tree
Showing 11 changed files with 199 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Changelog
1.0.17 (unreleased)
-------------------

- WEB-3732 : Add smartweb settings to customize sendinblue subscribing button (text and position)
[boulch]

- WEB-3730 : By default, Plone open external (Section text / Tiny) links in new tab
[boulch]

Expand Down
30 changes: 30 additions & 0 deletions src/imio/smartweb/core/browser/controlpanel.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
# -*- coding: utf-8 -*-

from collective.z3cform.datagridfield.datagridfield import DataGridFieldFactory
from collective.z3cform.datagridfield.registry import DictRow
from imio.smartweb.locales import SmartwebMessageFactory as _
from plone.app.registry.browser.controlpanel import ControlPanelFormWrapper
from plone.app.registry.browser.controlpanel import RegistryEditForm
from plone.autoform.directives import widget
from plone.z3cform import layout
from zope import schema
from zope.interface import Interface


class ITextRowSchema(Interface):

language = schema.TextLine(
title=_("Language (en, fr,...)"),
description=_("Enter the language code. Ex.: en"),
)

text = schema.TextLine(title=_("Text"), description=_("Your button title"))


class ISmartwebControlPanel(Interface):

url_formdefs_api = schema.TextLine(
Expand Down Expand Up @@ -111,6 +124,23 @@ class ISmartwebControlPanel(Interface):
required=False,
)

sendinblue_button_position = schema.Choice(
title=_("SendInBlue : Define button position"),
default="button_bottom",
source="imio.smartweb.vocabulary.SendInBlueButtonPosition",
)

sendinblue_button_text = schema.List(
title=_("SendInBlue : Define button text"),
description=_("Choose SendInblue submission button text"),
value_type=DictRow(
title="Value",
schema=ITextRowSchema,
),
required=True,
)
widget(sendinblue_button_text=DataGridFieldFactory)


class SmartwebControlPanelForm(RegistryEditForm):
schema = ISmartwebControlPanel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<metal:macro use-macro="context/@@sections_macros/section_title" />

<div tal:define="collapse_klass python: 'collapse' if context.collapsible_section else ''"
tal:attributes="class string:body-section ${collapse_klass};
tal:attributes="class string:body-section ${collapse_klass} ${view/button_position};
id string:body-section-${context/id}">

<p tal:replace="structure context/@@description" />
Expand Down
35 changes: 35 additions & 0 deletions src/imio/smartweb/core/contents/sections/sendinblue/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

from collective.sendinblue.browser.portlet import PortletSubscribeForm
from imio.smartweb.core.contents.sections.views import SectionView
from plone import api
from plone.z3cform.interfaces import IWrappedForm
from zope.component import getMultiAdapter
from zope.interface import alsoProvides


Expand All @@ -20,5 +22,38 @@ def get_subscription_form(self):
form = PortletSubscribeForm(self.context, self.request, data)
alsoProvides(form, IWrappedForm)
form.enable_autofocus = False
button_text = self.button_text
if button_text is not None:
button_text_fr = (
row.get("text")
for row in button_text
if row.get("language") == self.language
)
for text in button_text_fr:
form.buttons._data_values[0].title = text
form.update()
return form

@property
def button_position(self):
return (
api.portal.get_registry_record("smartweb.sendinblue_button_position")
or "button_bottom"
)

@property
def button_text(self):
return (
None
if api.portal.get_registry_record("smartweb.sendinblue_button_text") == []
else api.portal.get_registry_record("smartweb.sendinblue_button_text")
)

@property
def language(self):
context = self.context.aq_inner
portal_state = getMultiAdapter(
(context, self.request), name="plone_portal_state"
)
current_language = portal_state.language()
return current_language
2 changes: 1 addition & 1 deletion src/imio/smartweb/core/profiles/default/metadata.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version='1.0' encoding='UTF-8'?>
<metadata>
<version>1028</version>
<version>1029</version>
<dependencies>
<dependency>profile-plone.app.dexterity:default</dependency>
<dependency>profile-plone.app.imagecropping:default</dependency>
Expand Down
74 changes: 74 additions & 0 deletions src/imio/smartweb/core/tests/test_section_sendinblue.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# -*- coding: utf-8 -*-

from imio.smartweb.core.testing import IMIO_SMARTWEB_CORE_FUNCTIONAL_TESTING
from imio.smartweb.core.testing import ImioSmartwebTestCase
from plone import api
from plone.app.testing import setRoles
from plone.app.testing import TEST_USER_ID
from zope.component import queryMultiAdapter


class TestSectionNews(ImioSmartwebTestCase):

layer = IMIO_SMARTWEB_CORE_FUNCTIONAL_TESTING

def setUp(self):
self.request = self.layer["request"]
self.portal = self.layer["portal"]
setRoles(self.portal, TEST_USER_ID, ["Manager"])
self.portalpage = api.content.create(
container=self.portal,
type="imio.smartweb.PortalPage",
id="Portal page",
)

def test_button_position(self):
section_sendinblue = api.content.create(
container=self.portalpage,
type="imio.smartweb.SectionSendinblue",
title="SendInBlue",
)
section_view = queryMultiAdapter(
(section_sendinblue, self.request), name="view"
)
self.assertEquals("button_bottom", section_view.button_position)

portal_page_view = queryMultiAdapter(
(self.portalpage, self.request), name="full_view"
)
self.assertIn("button_bottom", portal_page_view())

api.portal.set_registry_record(
"smartweb.sendinblue_button_position", "button_right"
)
portal_page_view = queryMultiAdapter(
(self.portalpage, self.request), name="full_view"
)
self.assertIn("button_right", portal_page_view())

def test_button_text(self):
section_sendinblue = api.content.create(
container=self.portalpage,
type="imio.smartweb.SectionSendinblue",
title="SendInBlue",
)
section_view = queryMultiAdapter(
(section_sendinblue, self.request), name="view"
)
self.assertIsNone(section_view.button_text)

portal_page_view = queryMultiAdapter(
(self.portalpage, self.request), name="full_view"
)
self.assertIn('value="Subscribe"', portal_page_view())

texts = [
{"language": "fr", "text": "Je m'inscris!"},
{"language": "en", "text": "Register!"},
]
api.portal.set_registry_record("smartweb.sendinblue_button_text", texts)
portal_page_view = queryMultiAdapter(
(self.portalpage, self.request), name="full_view"
)
self.assertNotIn('value="Subscribe"', portal_page_view())
self.assertIn('value="Register!"', portal_page_view())
3 changes: 3 additions & 0 deletions src/imio/smartweb/core/tests/test_vocabularies.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,6 @@ def test_events_from_entity(self, m):
vocabulary.getTermByToken("1178188bddde4ced95a6cf8bf04c443b").title,
"belleville >> communal >> Bon pied, bon oeil",
)

def test_sendinblue_button_position(self):
self.assertVocabularyLen("imio.smartweb.vocabulary.SendInBlueButtonPosition", 2)
17 changes: 17 additions & 0 deletions src/imio/smartweb/core/upgrades/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@
provides="Products.GenericSetup.interfaces.EXTENSION"
/>

<genericsetup:registerProfile
name="upgrade_1028_to_1029"
title="Upgrade core from 1028 to 1029"
directory="profiles/1028_to_1029"
description="Add some properties/registry keys about SendInblue button"
provides="Products.GenericSetup.interfaces.EXTENSION"
/>

<genericsetup:upgradeStep
title="Configure first official release"
description="Run needed profiles steps and reindex catalog"
Expand Down Expand Up @@ -371,4 +379,13 @@
/>
</genericsetup:upgradeSteps>

<genericsetup:upgradeSteps
source="1028"
destination="1029"
profile="imio.smartweb.core:default">
<genericsetup:upgradeDepends
title="Add some properties/registry keys about SendInblue button"
import_profile="imio.smartweb.core.upgrades:upgrade_1028_to_1029"
/>
</genericsetup:upgradeSteps>
</configure>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0"?>
<registry
xmlns:i18n="http://xml.zope.org/namespaces/i18n"
i18n:domain="imio.smartweb">

<records interface="imio.smartweb.core.browser.controlpanel.ISmartwebControlPanel"
prefix="smartweb">
<value key="sendinblue_button_position">button_bottom</value>
</records>

<records interface="imio.smartweb.core.browser.controlpanel.ISmartwebControlPanel"
prefix="smartweb">
<value key="sendinblue_button_text"></value>
</records>

</registry>
13 changes: 13 additions & 0 deletions src/imio/smartweb/core/vocabularies.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,3 +533,16 @@ def __call__(self, context=None):


GalleryModeVocabulary = GalleryModeVocabularyFactory()


class SendInBlueButtonPosVocabularyFactory:
def __call__(self, context=None):
bootstrap_css = [
("button_bottom", _("Bottom")),
("button_right", _("Right")),
]
terms = [SimpleTerm(value=t[0], token=t[0], title=t[1]) for t in bootstrap_css]
return SimpleVocabulary(terms)


SendInBlueButtonPosVocabulary = SendInBlueButtonPosVocabularyFactory()
6 changes: 6 additions & 0 deletions src/imio/smartweb/core/vocabularies.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,10 @@
provides="zope.schema.interfaces.IVocabularyFactory"
/>

<utility
name="imio.smartweb.vocabulary.SendInBlueButtonPosition"
component=".vocabularies.SendInBlueButtonPosVocabulary"
provides="zope.schema.interfaces.IVocabularyFactory"
/>

</configure>

0 comments on commit 27f8156

Please sign in to comment.