-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
151 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<configure | ||
xmlns="http://namespaces.zope.org/zope" | ||
xmlns:i18n="http://namespaces.zope.org/i18n" | ||
i18n_domain="plone"> | ||
|
||
|
||
<adapter | ||
for="*" | ||
provides="plone.stringinterp.interfaces.IStringSubstitution" | ||
factory=".volto_url_substitution.VoltoURLSubstitution" | ||
name="volto_absolute_url" | ||
/> | ||
|
||
<adapter | ||
for="*" | ||
provides="plone.stringinterp.interfaces.IStringSubstitution" | ||
factory=".volto_portal_url.VoltoPortalURLSubstitution" | ||
name="volto_portal_url" | ||
/> | ||
|
||
|
||
|
||
</configure> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
""" | ||
Content rule string interpolator to return volto url of a given content item | ||
""" | ||
|
||
from plone import api | ||
from plone.stringinterp.adapters import BaseSubstitution | ||
from plone.volto import _ | ||
from Products.CMFCore.interfaces import IContentish | ||
from zope.component import adapter | ||
|
||
|
||
@adapter(IContentish) | ||
class VoltoAbsoluteURLSubstitution(BaseSubstitution): | ||
""" URL Substitution adapter """ | ||
|
||
category = _(u"All Content") | ||
description = _(u"Volto URL") | ||
|
||
def safe_call(self): | ||
""" get the url """ | ||
context_url = self.context.absolute_url() | ||
plone_domain = api.portal.get().absolute_url() | ||
frontend_domain = api.portal.get_registry_record("volto.frontend_domain") | ||
if frontend_domain.endswith("/"): | ||
frontend_domain = frontend_domain[:-1] | ||
|
||
return context_url.replace(plone_domain, frontend_domain) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
""" | ||
Content rule string interpolator to return volto url of a given content item | ||
""" | ||
|
||
from plone import api | ||
from plone.stringinterp.adapters import BaseSubstitution | ||
from plone.volto import _ | ||
from Products.CMFCore.interfaces import IContentish | ||
from zope.component import adapter | ||
|
||
|
||
@adapter(IContentish) | ||
class VoltoPortalURLSubstitution(BaseSubstitution): | ||
""" URL Substitution adapter """ | ||
|
||
category = _(u"All Content") | ||
description = _(u"Volto Portal URL") | ||
|
||
def safe_call(self): | ||
""" get the url """ | ||
frontend_domain = api.portal.get_registry_record("volto.frontend_domain") | ||
return frontend_domain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
""" test string interpolation substitutions for content rules """ | ||
# -*- coding: utf-8 -*- | ||
import unittest | ||
|
||
from plone import api | ||
from plone.app.testing import TEST_USER_ID, setRoles | ||
from plone.stringinterp.interfaces import IStringInterpolator | ||
|
||
from plone.volto.interpolators.volto_portal_url import ( | ||
VoltoPortalURLSubstitution, | ||
) | ||
from plone.volto.interpolators.volto_absolute_url import ( | ||
VoltoAbsoluteURLSubstitution, | ||
) | ||
from plone.volto.testing import ( | ||
PLONE_VOLTO_CORE_INTEGRATION_TESTING, | ||
PLONE_VOLTO_CORE_FUNCTIONAL_TESTING, | ||
) | ||
|
||
|
||
class TestSubstitutions(unittest.TestCase): | ||
""" Test case for substitutions""" | ||
|
||
layer = PLONE_VOLTO_CORE_INTEGRATION_TESTING | ||
|
||
def setUp(self): | ||
self.portal = self.layer["portal"] | ||
self.request = self.layer["request"] | ||
|
||
def test_volto_portal_url(self): | ||
""" test for volto_portal_url""" | ||
volto_url = api.portal.get_registry_record("volto.frontend_domain") | ||
substitution = VoltoPortalURLSubstitution(self.portal)() | ||
self.assertEqual(substitution, volto_url) | ||
|
||
def test_string_interpolation_volto_portal_url(self): | ||
""" test interpolating as string """ | ||
volto_url = api.portal.get_registry_record("volto.frontend_domain") | ||
string = "${volto_portal_url}" | ||
value = IStringInterpolator(self.portal)(string) | ||
self.assertEqual(value, volto_url) | ||
|
||
|
||
class TestSubstitutionsFunctional(unittest.TestCase): | ||
""" Test case for substitutions""" | ||
|
||
layer = PLONE_VOLTO_CORE_FUNCTIONAL_TESTING | ||
|
||
def setUp(self): | ||
""" test setup """ | ||
self.portal = self.layer["portal"] | ||
self.request = self.layer["request"] | ||
setRoles(self.portal, TEST_USER_ID, ["Manager"]) | ||
|
||
self.portal.invokeFactory("Document", id="doc", title="My Document") | ||
self.document = self.portal.get("doc") | ||
|
||
def test_volto_absolute_url(self): | ||
""" test for volto_absolute_url""" | ||
|
||
volto_url = api.portal.get_registry_record("volto.frontend_domain") | ||
portal_url = self.portal.absolute_url() | ||
context_url = self.document.absolute_url() | ||
substitution = VoltoAbsoluteURLSubstitution(self.document)() | ||
self.assertEqual(substitution, context_url.replace(portal_url, volto_url)) | ||
|
||
def test_string_interpolation_volto_absolute_url(self): | ||
""" test as string interpolator""" | ||
|
||
volto_url = api.portal.get_registry_record("volto.frontend_domain") | ||
portal_url = self.portal.absolute_url() | ||
context_url = self.document.absolute_url() | ||
|
||
string = "${volto_absolute_url}" | ||
value = IStringInterpolator(self.document)(string) | ||
self.assertEqual(value, context_url.replace(portal_url, volto_url)) |