imio.prettylink 1.24__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,11 @@
1
+ # -*- coding: utf-8 -*-
2
+ """Init and utils."""
3
+
4
+ from zope.i18nmessageid import MessageFactory
5
+
6
+
7
+ _ = MessageFactory("imio.prettylink")
8
+
9
+
10
+ def initialize(context):
11
+ """Initializer called when used as a Zope 2 product."""
@@ -0,0 +1,248 @@
1
+ # -*- coding: utf-8 -*-
2
+ from imio.helpers.cache import obj_modified
3
+ from plone import api
4
+ from plone.memoize import ram
5
+ from plone.rfc822.interfaces import IPrimaryFieldInfo
6
+ from Products.CMFCore.permissions import View
7
+ from Products.CMFCore.utils import _checkPermission
8
+ from Products.CMFCore.WorkflowCore import WorkflowException
9
+ from zope.i18n import translate
10
+ from zope.i18nmessageid import Message
11
+
12
+ import html
13
+
14
+
15
+ try:
16
+ from plone.base.utils import base_hasattr
17
+ from plone.base.utils import safe_text
18
+ except ImportError:
19
+ from Products.CMFPlone.utils import base_hasattr
20
+ from Products.CMFPlone.utils import safe_unicode as safe_text
21
+
22
+
23
+ class PrettyLinkAdapter(object):
24
+ """Adapter that manage rendering the pretty link."""
25
+
26
+ def __init__(
27
+ self,
28
+ context,
29
+ showColors=True,
30
+ showIcons=True,
31
+ showContentIcon=False,
32
+ showLockedIcon=True,
33
+ contentValue="",
34
+ display_tag_title=True,
35
+ tag_title="",
36
+ maxLength=0,
37
+ target="_self",
38
+ appendToUrl="",
39
+ additionalCSSClasses=[],
40
+ isViewable=True,
41
+ link_pattern=u"<div class='pretty_link'{0}>{1}<span class='pretty_link_content{2}'>{3}</span></div>",
42
+ **kwargs
43
+ ):
44
+ self.context = context
45
+ self.request = self.context.REQUEST
46
+ self.portal_url = api.portal.get().absolute_url()
47
+ # we set parameters in the init so it it reusable across every methods
48
+ self.showColors = showColors
49
+ self.showIcons = showIcons
50
+ self.showContentIcon = showContentIcon
51
+ self.showLockedIcon = showLockedIcon
52
+ # value to use for the link, if not given, object's title will be used
53
+ self.contentValue = contentValue
54
+ # arbitrary tag_title
55
+ self.tag_title = tag_title
56
+ self.display_tag_title = display_tag_title
57
+ # truncate link content to given maxLength if any
58
+ self.maxLength = maxLength
59
+ # target of the link : _blank, _self, ...
60
+ self.target = target
61
+ # append arbitrary to the rendered URL
62
+ self.appendToUrl = appendToUrl
63
+ # arbitrary css classes
64
+ self.additionalCSSClasses = additionalCSSClasses
65
+ self.kwargs = kwargs
66
+ # we also manage the fact that we want to display an element that is
67
+ # actually not reachable by current user... In this case, we display
68
+ # a <div> to the element with a help message...
69
+ self.isViewable = isViewable
70
+ # we may force isViewable to False even if user has the 'View' permission
71
+ # on it, but if isViewable is True, we check if target is really viewable
72
+ if isViewable:
73
+ if not _checkPermission(View, self.context):
74
+ self.isViewable = False
75
+ self.notViewableHelpMessage = translate(
76
+ "can_not_access_this_element",
77
+ domain="imio.prettylink",
78
+ context=self.request,
79
+ default=u"<span class='discreet no_access'>(You can not access this element)</span>",
80
+ )
81
+ self.link_pattern = link_pattern
82
+
83
+ def getLink_cachekey(method, self):
84
+ """cachekey method for self.getLink."""
85
+ is_locked = self._show_lock_icon()
86
+ review_state = api.content.get_state(self.context, None)
87
+ server_url = self.request.get("SERVER_URL", None)
88
+ # cache by context, until modified, is_locked, state changed or server_url is different
89
+ # + every parameters passed in __init__
90
+ return (
91
+ self.context.UID(),
92
+ obj_modified(self.context, asdatetime=False),
93
+ is_locked,
94
+ review_state,
95
+ server_url,
96
+ self.showColors,
97
+ self.showIcons,
98
+ self.showContentIcon,
99
+ self.showLockedIcon,
100
+ self.contentValue,
101
+ self.tag_title,
102
+ self.display_tag_title,
103
+ self.maxLength,
104
+ self.target,
105
+ self.appendToUrl,
106
+ self.additionalCSSClasses,
107
+ self.isViewable,
108
+ self.kwargs,
109
+ )
110
+
111
+ @ram.cache(getLink_cachekey)
112
+ def getLink(self):
113
+ """See docstring in interfaces.py."""
114
+ return self._getLink()
115
+
116
+ def _getLink(self):
117
+ """Private method that does the link computation without the cachekey,
118
+ this is done so it is possible to override the cachekey."""
119
+ completeContent = safe_text(self.contentValue or self.context.Title())
120
+ content = completeContent
121
+ if self.maxLength:
122
+ plone_view = self.context.restrictedTraverse("@@plone")
123
+ ellipsis = self.kwargs.get("ellipsis", "...")
124
+ content = plone_view.cropText(completeContent, self.maxLength, ellipsis)
125
+ icons = self.showIcons and self._icons() or ""
126
+ title = safe_text(self.tag_title or completeContent)
127
+ icons_tag = icons and u"<span class='pretty_link_icons'>{0}</span>".format(icons) or ""
128
+ # as link is rendered using "structure", escape various texts
129
+ content = html.escape(content)
130
+ title = html.escape(title).replace("'", "&apos;")
131
+ self.target = html.escape(self.target)
132
+ if self.isViewable:
133
+ url = self._get_url()
134
+ css_classes = self.CSSClasses()
135
+ return (
136
+ u"<a class='pretty_link{0}'{1} href='{2}' target='{3}'>{4}"
137
+ u"<span class='pretty_link_content{5}'>{6}</span></a>".format(
138
+ css_classes.get("a"),
139
+ self.display_tag_title and u" title='{0}'".format(title) or "",
140
+ url,
141
+ self.target,
142
+ icons_tag,
143
+ css_classes.get("span"),
144
+ safe_text(content),
145
+ )
146
+ )
147
+ else:
148
+ # append the notViewableHelpMessage
149
+ content = u"{0} {1}".format(content, self.notViewableHelpMessage)
150
+ return self.link_pattern.format(
151
+ self.display_tag_title and u" title='{0}'".format(title) or "",
152
+ icons_tag,
153
+ self.CSSClasses()["span"],
154
+ safe_text(content),
155
+ )
156
+
157
+ def _get_url(self):
158
+ """Compute the url to the content."""
159
+ url = self.context.absolute_url()
160
+ # add @@download to url if necessary, it is the case for dexterity files
161
+ try:
162
+ primary_field_info = IPrimaryFieldInfo(self.context)
163
+ primary_field = getattr(self.context, primary_field_info.fieldname)
164
+ if base_hasattr(primary_field, "filename"):
165
+ url = u"{0}/@@download".format(url)
166
+ except TypeError:
167
+ pass
168
+ return url + self.appendToUrl
169
+
170
+ def CSSClasses(self):
171
+ """See docstring in interfaces.py."""
172
+ css_classes = {"a": [], "span": []}
173
+ css_classes["a"] += list(self.additionalCSSClasses)
174
+ if self.showColors:
175
+ wft = api.portal.get_tool("portal_workflow")
176
+ try:
177
+ css_classes["span"].append("state-{0}".format(wft.getInfoFor(self.context, "review_state")))
178
+ except WorkflowException:
179
+ # if self.context does not have a workflow, just pass
180
+ pass
181
+ # in case the contentIcon must be shown and it the icon
182
+ # is shown by the generated contentttype-xxx class
183
+ if self.showContentIcon:
184
+ type_info = api.portal.get_tool("portal_types")[self.context.portal_type]
185
+ if not type_info.icon_expr:
186
+ css_classes["span"].append("contenttype-{0}".format(type_info.getId()))
187
+ if css_classes["a"]:
188
+ css_classes["a"].insert(0, "")
189
+ css_classes["a"] = " ".join(css_classes["a"])
190
+ if css_classes["span"]:
191
+ css_classes["span"].insert(0, "")
192
+ css_classes["span"] = " ".join(css_classes["span"])
193
+ return css_classes
194
+
195
+ def _icons(self, **kwargs):
196
+ """See docstring in interfaces.py."""
197
+ icons = []
198
+
199
+ # manage icons we want to be displayed before managed icons
200
+ icons = icons + self._leadingIcons()
201
+
202
+ # display the icon that shows that an element is currently locked by another user
203
+ if self._show_lock_icon():
204
+ icons.append(
205
+ (
206
+ "lock_icon.png",
207
+ translate("Locked", domain="plone", context=self.request),
208
+ )
209
+ )
210
+
211
+ # in case the contentIcon must be shown, the icon url is defined on the type_info
212
+ if self.showContentIcon:
213
+ type_info = api.portal.get_tool("portal_types")[self.context.portal_type]
214
+ if type_info.icon_expr:
215
+ # we assume that stored icon_expr is like string:${portal_url}/myContentIcon.png
216
+ # or like string:${portal_url}/++resource++package/myContentIcon.png
217
+ # we skip first part
218
+ contentIcon = "/".join(type_info.icon_expr.split("/")[1:])
219
+ # title will return an i18n msgid or a string if portal_type
220
+ # does not have a i18n_domain
221
+ type_info_title = type_info.Title()
222
+ if isinstance(type_info_title, Message):
223
+ type_info_title = translate(type_info_title, context=self.request)
224
+ icons.append((contentIcon, type_info_title))
225
+
226
+ # manage icons we want to be displayed after managed icons
227
+ icons = icons + self._trailingIcons()
228
+ return " ".join(
229
+ [
230
+ u"<img title='{0}' src='{1}' style=\"width: 16px; height: 16px;\" />".format(
231
+ safe_text(icon[1]).replace("'", "&apos;"),
232
+ u"{0}/{1}".format(self.portal_url, icon[0]),
233
+ )
234
+ for icon in icons
235
+ ]
236
+ )
237
+
238
+ def _show_lock_icon(self):
239
+ """ """
240
+ return self.showLockedIcon and self.context.wl_isLocked()
241
+
242
+ def _leadingIcons(self):
243
+ """See docstring in interfaces.py."""
244
+ return []
245
+
246
+ def _trailingIcons(self):
247
+ """See docstring in interfaces.py."""
248
+ return []
@@ -0,0 +1,22 @@
1
+ <configure
2
+ xmlns="http://namespaces.zope.org/zope"
3
+ xmlns:five="http://namespaces.zope.org/five"
4
+ xmlns:genericsetup="http://namespaces.zope.org/genericsetup"
5
+ xmlns:i18n="http://namespaces.zope.org/i18n"
6
+ i18n_domain="imio.prettylink"
7
+ >
8
+
9
+ <five:registerPackage
10
+ package="."
11
+ initialize=".initialize"
12
+ />
13
+
14
+ <i18n:registerTranslations directory="locales" />
15
+
16
+ <adapter
17
+ factory=".adapters.PrettyLinkAdapter"
18
+ provides=".interfaces.IPrettyLink"
19
+ for="OFS.interfaces.IItem"
20
+ />
21
+
22
+ </configure>
@@ -0,0 +1,26 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from zope.interface import Interface
4
+
5
+
6
+ class IPrettyLink(Interface):
7
+ """ """
8
+
9
+ def getLink(self):
10
+ """Returns complete link to the element."""
11
+
12
+ def CSSClasses(self):
13
+ """Manage CSS classes to apply to the link.
14
+ It depends on :
15
+ - additionalCSSClasses : some arbitrary classes you can define;
16
+ - showColors : will display a colored link depending on workflow state;
17
+ - showContentIcon : will apply the class that displays the content icon."""
18
+
19
+ def _icons(self):
20
+ """Returns icons to prepend to the link."""
21
+
22
+ def _leadingIcons(self):
23
+ """Returns icons to prepend to icons returned by _icons."""
24
+
25
+ def _trailingIcons(self):
26
+ """Returns icons to append to icons returned by _icons."""
@@ -0,0 +1,20 @@
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: PACKAGE VERSION\n"
4
+ "POT-Creation-Date: 2015-06-22 13:30-100\n"
5
+ "PO-Revision-Date: YEAR-MO-DA HO:MI +ZONE\n"
6
+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
7
+ "Language-Team: LANGUAGE <LL@li.org>\n"
8
+ "MIME-Version: 1.0\n"
9
+ "Content-Type: text/plain; charset=utf-8\n"
10
+ "Content-Transfer-Encoding: 8bit\n"
11
+ "Plural-Forms: nplurals=1; plural=0\n"
12
+ "Language-Code: en\n"
13
+ "Language-Name: English\n"
14
+ "Preferred-Encodings: utf-8 latin1\n"
15
+ "Domain: DOMAIN\n"
16
+
17
+ #. Default: "<span class='discreet no_access'>(You can not access this element)</span>"
18
+ msgid "can_not_access_this_element"
19
+ msgstr "<span class='discreet no_access'>(You can not access this element)</span>"
20
+
@@ -0,0 +1,20 @@
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: PACKAGE VERSION\n"
4
+ "POT-Creation-Date: 2015-06-22 13:30-100\n"
5
+ "PO-Revision-Date: YEAR-MO-DA HO:MI +ZONE\n"
6
+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
7
+ "Language-Team: LANGUAGE <LL@li.org>\n"
8
+ "MIME-Version: 1.0\n"
9
+ "Content-Type: text/plain; charset=utf-8\n"
10
+ "Content-Transfer-Encoding: 8bit\n"
11
+ "Plural-Forms: nplurals=1; plural=0\n"
12
+ "Language-Code: en\n"
13
+ "Language-Name: English\n"
14
+ "Preferred-Encodings: utf-8 latin1\n"
15
+ "Domain: DOMAIN\n"
16
+
17
+ #. Default: "<span class='discreet no_access'>(You can not access this element)</span>"
18
+ msgid "can_not_access_this_element"
19
+ msgstr "<span class='discreet no_access'>(Vous n'avez pas accès à cet élément)</span>"
20
+
@@ -0,0 +1,16 @@
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: imio.prettylink 1.0\n"
4
+ "POT-Creation-Date: 2015-06-22 13:30-100\n"
5
+ "MIME-Version: 1.0\n"
6
+ "Content-Type: text/plain; charset=utf-8\n"
7
+ "Content-Transfer-Encoding: 8bit\n"
8
+ "Plural-Forms: nplurals=1; plural=0\n"
9
+ "Language-Code: en\n"
10
+ "Language-Name: English\n"
11
+ "Preferred-Encodings: utf-8 latin1\n"
12
+ "Domain: imio.prettylink\n"
13
+
14
+ #. Default: "<span class='discreet no_access'>(You can not access this element)</span>"
15
+ msgid "can_not_access_this_element"
16
+ msgstr ""
@@ -0,0 +1,9 @@
1
+ files="imio.prettylink"
2
+ languages="en fr"
3
+
4
+ for file in $files; do
5
+ for language in $languages; do
6
+ i18ndude sync --pot $file.pot $language/LC_MESSAGES/$file.po
7
+ msgfmt -o $language/LC_MESSAGES/$file.mo $language/LC_MESSAGES/$file.po
8
+ done
9
+ done
@@ -0,0 +1,86 @@
1
+ # -*- coding: utf-8 -*-
2
+ """Base module for unittesting."""
3
+
4
+ from imio.helpers import HAS_PLONE_6_AND_MORE
5
+ from plone.app.robotframework.testing import AUTOLOGIN_LIBRARY_FIXTURE
6
+ from plone.app.testing import FunctionalTesting
7
+ from plone.app.testing import IntegrationTesting
8
+ from plone.app.testing import login
9
+ from plone.app.testing import PLONE_FIXTURE
10
+ from plone.app.testing import PloneSandboxLayer
11
+ from plone.app.testing import setRoles
12
+ from plone.app.testing import TEST_USER_ID
13
+ from plone.app.testing import TEST_USER_NAME
14
+ from plone.dexterity.interfaces import IDexterityFTI
15
+ from plone.testing import z2
16
+ from zope.component import getUtility
17
+
18
+ import imio.prettylink
19
+ import unittest
20
+
21
+
22
+ class PloneWithPrettyLinkLayer(PloneSandboxLayer):
23
+
24
+ defaultBases = (PLONE_FIXTURE,)
25
+
26
+ def setUpZope(self, app, configurationContext):
27
+ """Set up Zope."""
28
+ # Load ZCML
29
+ self.loadZCML(package=imio.prettylink, name="testing.zcml")
30
+ z2.installProduct(app, "imio.prettylink")
31
+
32
+ def setUpPloneSite(self, portal):
33
+ """Set up Plone."""
34
+
35
+ if HAS_PLONE_6_AND_MORE:
36
+ fti = getUtility(IDexterityFTI, name="Folder")
37
+ behaviors = list(fti.behaviors)
38
+ locking_behavior = "plone.app.lockingbehavior.behaviors.ILocking"
39
+ if locking_behavior not in behaviors:
40
+ behaviors.append(locking_behavior)
41
+ fti.behaviors = tuple(behaviors)
42
+
43
+ # Login and create some test content
44
+ setRoles(portal, TEST_USER_ID, ["Manager"])
45
+ login(portal, TEST_USER_NAME)
46
+ # make sure we have a default workflow
47
+ portal.portal_workflow.setDefaultChain("simple_publication_workflow")
48
+ folder_id = portal.invokeFactory("Folder", "folder", title="Folder")
49
+ folder_id2 = portal.invokeFactory("Folder", "folder2", title="Folder2")
50
+ portal[folder_id].reindexObject()
51
+ portal[folder_id2].reindexObject()
52
+
53
+ # Commit so that the test browser sees these objects
54
+ import transaction
55
+
56
+ transaction.commit()
57
+
58
+ def tearDownZope(self, app):
59
+ """Tear down Zope."""
60
+ z2.uninstallProduct(app, "imio.prettylink")
61
+
62
+
63
+ FIXTURE = PloneWithPrettyLinkLayer(name="FIXTURE")
64
+
65
+
66
+ INTEGRATION = IntegrationTesting(bases=(FIXTURE,), name="INTEGRATION")
67
+
68
+
69
+ FUNCTIONAL = FunctionalTesting(bases=(FIXTURE,), name="FUNCTIONAL")
70
+
71
+
72
+ ACCEPTANCE = FunctionalTesting(bases=(FIXTURE, AUTOLOGIN_LIBRARY_FIXTURE, z2.ZSERVER_FIXTURE), name="ACCEPTANCE")
73
+
74
+
75
+ class IntegrationTestCase(unittest.TestCase):
76
+ """Base class for integration tests."""
77
+
78
+ layer = INTEGRATION
79
+
80
+ def setUp(self):
81
+ super(IntegrationTestCase, self).setUp()
82
+ self.portal = self.layer["portal"]
83
+ self.folder = self.portal.folder
84
+ self.folder2 = self.portal.folder2
85
+ self.catalog = self.portal.portal_catalog
86
+ self.maxDiff = None
@@ -0,0 +1,9 @@
1
+ <configure
2
+ xmlns="http://namespaces.zope.org/zope"
3
+ xmlns:genericsetup="http://namespaces.zope.org/genericsetup"
4
+ i18n_domain="imio.prettylink"
5
+ >
6
+
7
+ <include file="configure.zcml" />
8
+
9
+ </configure>
File without changes
@@ -0,0 +1,250 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from imio.helpers import HAS_PLONE_6_AND_MORE
4
+ from imio.prettylink.interfaces import IPrettyLink
5
+ from imio.prettylink.testing import IntegrationTestCase
6
+ from plone import api
7
+ from plone.locking.interfaces import ILockable
8
+ from plone.memoize.interfaces import ICacheChooser
9
+ from zope.component import getUtility
10
+
11
+
12
+ class TestPrettyLinkAdapter(IntegrationTestCase):
13
+ def invalidate_cache(self):
14
+ cache = getUtility(ICacheChooser)("imio.prettylink.adapters.getLink")
15
+ cache.ramcache.invalidate("imio.prettylink.adapters.getLink")
16
+
17
+ def test_getLink_caching_modified(self):
18
+ """Cache is invalidated when modified."""
19
+ self.assertEqual(
20
+ IPrettyLink(self.folder).getLink(),
21
+ u"<a class='pretty_link' title='Folder' href='http://nohost/plone/folder' "
22
+ u"target='_self'><span class='pretty_link_content state-private'>Folder</span></a>",
23
+ )
24
+ # change Title and do not notify modified
25
+ self.folder.setTitle("Folder other title")
26
+ self.assertTrue(" title='Folder' " in IPrettyLink(self.folder).getLink())
27
+ # notify modified so cache is invalidated
28
+ self.folder.notifyModified()
29
+ self.assertTrue(" title='Folder other title' " in IPrettyLink(self.folder).getLink())
30
+
31
+ def test_getLink_caching_context(self):
32
+ """Cached by context so getLink on self.folder2 is correct."""
33
+ self.assertEqual(
34
+ IPrettyLink(self.folder).getLink(),
35
+ u"<a class='pretty_link' title='Folder' href='http://nohost/plone/folder' "
36
+ u"target='_self'><span class='pretty_link_content state-private'>Folder</span></a>",
37
+ )
38
+ self.assertEqual(
39
+ IPrettyLink(self.folder2).getLink(),
40
+ u"<a class='pretty_link' title='Folder2' href='http://nohost/plone/folder2' "
41
+ u"target='_self'><span class='pretty_link_content state-private'>Folder2</span></a>",
42
+ )
43
+
44
+ def test_getLink_caching_locking(self):
45
+ """Cache takes locking into account."""
46
+ ILockable(self.folder).lock()
47
+ self.assertTrue(u"lock_icon.png" in IPrettyLink(self.folder).getLink())
48
+ ILockable(self.folder).unlock()
49
+ self.assertFalse(u"lock_icon.png" in IPrettyLink(self.folder).getLink())
50
+
51
+ def test_getLink_caching_review_state(self):
52
+ """Cache takes 'review_state' into account."""
53
+ self.assertTrue(u"<span class='pretty_link_content state-private'>" in IPrettyLink(self.folder).getLink())
54
+ api.content.transition(self.folder, "publish")
55
+ self.assertTrue(u"<span class='pretty_link_content state-published'>" in IPrettyLink(self.folder).getLink())
56
+
57
+ def test_getLink_server_url(self):
58
+ """Cache takes portal url (SERVER_URL) into account,
59
+ this could change when accessing the portal thru different domains or so."""
60
+ portal = api.portal.get()
61
+ portal_url = portal.absolute_url()
62
+ ANOTHER_HOST = "http://another_host"
63
+ self.assertTrue(portal_url in IPrettyLink(self.folder).getLink())
64
+ self.assertFalse(ANOTHER_HOST in IPrettyLink(self.folder).getLink())
65
+ self.portal.REQUEST["SERVER_URL"] = ANOTHER_HOST
66
+ self.assertTrue(ANOTHER_HOST in IPrettyLink(self.folder).getLink())
67
+
68
+ def test_getLink_caching_showColors(self):
69
+ """Cache takes the 'showColors' parameter into account."""
70
+ adapted = IPrettyLink(self.folder)
71
+ self.assertTrue(adapted.showColors)
72
+ self.assertTrue(u"<span class='pretty_link_content state-private'" in adapted.getLink())
73
+ adapted.showColors = False
74
+ self.assertFalse(u"<span class='pretty_link_content state-private'" in adapted.getLink())
75
+
76
+ def test_getLink_caching_showIcons(self):
77
+ """Cache takes the 'showIcons' parameter into account."""
78
+ adapted = IPrettyLink(self.folder)
79
+ self.assertTrue(adapted.showIcons)
80
+ ILockable(self.folder).lock()
81
+ self.assertTrue(u"lock_icon.png" in adapted.getLink())
82
+ adapted.showIcons = False
83
+ self.assertFalse(u"lock_icon.png" in adapted.getLink())
84
+
85
+ def test_getLink_caching_showContentIcon(self):
86
+ """Cache takes the 'showContentIcon' parameter into account."""
87
+ if HAS_PLONE_6_AND_MORE:
88
+ pretty_link_marker = "<img title='Folder' src='http://nohost/plone/folder' style=\"width: 16px; height: 16px;\" /></span><span class='pretty_link_content state-private'>Folder</span>"
89
+ else:
90
+ pretty_link_marker = u"contenttype-Folder"
91
+ adapted = IPrettyLink(self.folder)
92
+ self.assertTrue(adapted.showIcons)
93
+ self.assertFalse(adapted.showContentIcon)
94
+ self.assertFalse(pretty_link_marker in adapted.getLink())
95
+ adapted.showContentIcon = True
96
+ self.assertTrue(pretty_link_marker in adapted.getLink())
97
+ typeInfo = api.portal.get_tool("portal_types")["Folder"]
98
+ # setting an icon
99
+ self.invalidate_cache()
100
+ typeInfo.icon_expr = "string:${portal_url}/myContentIcon.png"
101
+ self.assertFalse(pretty_link_marker in adapted.getLink())
102
+ self.assertTrue(u"plone/myContentIcon.png" in adapted.getLink())
103
+ self.invalidate_cache()
104
+ typeInfo.icon_expr = "string:${portal_url}/++resource++package/myContentIcon.png"
105
+ self.assertFalse(pretty_link_marker in adapted.getLink())
106
+ self.assertTrue(u"plone/++resource++package/myContentIcon.png" in adapted.getLink())
107
+ self.invalidate_cache()
108
+ # when typeInfo's title contains special characters
109
+ # this does not work with AT without a monkey patch
110
+ if HAS_PLONE_6_AND_MORE:
111
+ typeInfo.title = 'h\xc3\xa9h\xc3\xa9'
112
+ self.assertTrue(typeInfo.title in adapted.getLink())
113
+
114
+ def test_getLink_caching_showLockedIcon(self):
115
+ """Cache takes the 'showLockedIcon' parameter into account."""
116
+ adapted = IPrettyLink(self.folder)
117
+ self.assertTrue(adapted.showLockedIcon)
118
+ ILockable(self.folder).lock()
119
+ self.assertTrue(u"lock_icon.png" in adapted.getLink())
120
+ adapted.showLockedIcon = False
121
+ self.assertFalse(u"lock_icon.png" in adapted.getLink())
122
+
123
+ def test_getLink_caching_contentValue(self):
124
+ """Cache takes the 'contentValue' parameter into account."""
125
+ adapted = IPrettyLink(self.folder)
126
+ self.assertFalse(adapted.contentValue)
127
+ self.assertTrue(u"<span class='pretty_link_content state-private'>Folder</span>" in adapted.getLink())
128
+ adapted.contentValue = "Content value"
129
+ self.assertFalse(u"<span class='pretty_link_content state-private'>Folder</span>" in adapted.getLink())
130
+ self.assertTrue(u"<span class='pretty_link_content state-private'>Content value</span>" in adapted.getLink())
131
+
132
+ def test_getLink_caching_tag_title(self):
133
+ """Cache takes the 'tag_title' parameter into account."""
134
+ adapted = IPrettyLink(self.folder)
135
+ self.assertFalse(adapted.tag_title)
136
+ self.assertTrue(u" title='Folder' " in adapted.getLink())
137
+ adapted.tag_title = "Tag title"
138
+ self.assertFalse(u" title='Folder' " in adapted.getLink())
139
+ self.assertTrue(u" title='Tag title' " in adapted.getLink())
140
+
141
+ def test_getLink_caching_maxLength(self):
142
+ """Cache takes the 'maxLength' parameter into account."""
143
+ adapted = IPrettyLink(self.folder)
144
+ self.assertFalse(adapted.maxLength)
145
+ self.assertTrue(u"<span class='pretty_link_content state-private'>Folder</span>" in adapted.getLink())
146
+ adapted.maxLength = 2
147
+ self.assertFalse(u"<span class='pretty_link_content state-private'>Folder</span>" in adapted.getLink())
148
+ self.assertTrue(u"<span class='pretty_link_content state-private'>Fo...</span>" in adapted.getLink())
149
+
150
+ def test_getLink_caching_target(self):
151
+ """Cache takes the 'target' parameter into account."""
152
+ adapted = IPrettyLink(self.folder)
153
+ self.assertEqual(adapted.target, "_self")
154
+ self.assertTrue(u" target='_self'>" in adapted.getLink())
155
+ adapted.target = "_blank"
156
+ self.assertFalse(u" target='_self'>" in adapted.getLink())
157
+ self.assertTrue(u" target='_blank'>" in adapted.getLink())
158
+
159
+ def test_getLink_caching_appendToUrl(self):
160
+ """Cache takes the 'appendToUrl' parameter into account."""
161
+ adapted = IPrettyLink(self.folder)
162
+ self.assertFalse(adapted.appendToUrl)
163
+ self.assertTrue(u" href='http://nohost/plone/folder' " in adapted.getLink())
164
+ adapted.appendToUrl = "/@@append_to_url"
165
+ self.assertTrue(u" href='http://nohost/plone/folder/@@append_to_url' " in adapted.getLink())
166
+
167
+ def test_getLink_caching_additionalCSSClasses(self):
168
+ """Cache takes the 'additionalCSSClasses' parameter into account."""
169
+ adapted = IPrettyLink(self.folder)
170
+ self.assertFalse(adapted.additionalCSSClasses)
171
+ self.assertTrue(u"<span class='pretty_link_content state-private'>" in adapted.getLink())
172
+ adapted.additionalCSSClasses = ["custom_css_class"]
173
+ # additionalCSSClasses are set on the <a> tag
174
+ # state related CSS class is set on the <span> tag
175
+ self.assertEqual(
176
+ adapted.getLink(),
177
+ u"<a class='pretty_link custom_css_class' title='Folder' "
178
+ u"href='http://nohost/plone/folder' target='_self'>"
179
+ u"<span class='pretty_link_content state-private'>Folder</span></a>",
180
+ )
181
+
182
+ def test_getLink_caching_isViewable(self):
183
+ """Cache takes the 'isViewable' parameter into account."""
184
+ adapted = IPrettyLink(self.folder)
185
+ self.assertTrue(adapted.isViewable)
186
+ self.assertFalse(adapted.notViewableHelpMessage in adapted.getLink())
187
+ adapted.isViewable = False
188
+ self.assertTrue(adapted.notViewableHelpMessage in adapted.getLink())
189
+
190
+ def test_getLink_caching_kwargs(self):
191
+ """Cache takes the 'kwargs' parameter into account.
192
+ By default it is used together with maxLength to define the ellipsis type."""
193
+ adapted = IPrettyLink(self.folder)
194
+ adapted.maxLength = 2
195
+ self.assertFalse(adapted.kwargs)
196
+ self.assertTrue(u"<span class='pretty_link_content state-private'>Fo...</span>" in adapted.getLink())
197
+ adapted.kwargs["ellipsis"] = " [truncated]"
198
+ self.assertFalse(u"<span class='pretty_link_content state-private'>Fo...</span>" in adapted.getLink())
199
+ self.assertTrue(u"<span class='pretty_link_content state-private'>Fo [truncated]</span>" in adapted.getLink())
200
+
201
+ def test_getLink_caching_not_breaking_when_no_workflow(self):
202
+ """Caching also work when element has no workflow."""
203
+ self.portal.portal_workflow.setDefaultChain("")
204
+ no_wf_folder = api.content.create(
205
+ container=self.portal,
206
+ type="Folder",
207
+ id="no_wf_folder",
208
+ title="No WF folder",
209
+ )
210
+ self.assertTrue(IPrettyLink(no_wf_folder).getLink())
211
+ # and caching work, change folder title, link is still the same
212
+ # until notifyModified
213
+ no_wf_folder.setTitle("New title")
214
+ self.assertFalse(no_wf_folder.Title() in IPrettyLink(no_wf_folder).getLink())
215
+ no_wf_folder.notifyModified()
216
+ self.assertTrue(no_wf_folder.Title() in IPrettyLink(no_wf_folder).getLink())
217
+
218
+ def test_getLink_link_tooltip(self):
219
+ """title attr is absent if display_tag_title is False."""
220
+ pl = IPrettyLink(self.folder)
221
+ self.assertEqual(
222
+ pl.getLink(),
223
+ u"<a class='pretty_link' title='Folder' href='http://nohost/plone/folder' "
224
+ u"target='_self'><span class='pretty_link_content state-private'>Folder</span></a>",
225
+ )
226
+ pl.display_tag_title = False
227
+ self.assertEqual(
228
+ pl.getLink(),
229
+ u"<a class='pretty_link' href='http://nohost/plone/folder' "
230
+ u"target='_self'><span class='pretty_link_content state-private'>Folder</span></a>",
231
+ )
232
+
233
+ def test_getLink_escape_dangerous_characters(self):
234
+ """As link is rendered, make sure we can not embed dangerous things."""
235
+ self.folder.setTitle('Folder"><script>alert(document.domain)</script>')
236
+ pl = IPrettyLink(self.folder)
237
+ self.assertEqual(
238
+ pl.getLink(),
239
+ u"<a class='pretty_link' title='Folder&quot;&gt;&lt;script&gt;alert(document.domain)"
240
+ u"&lt;/script&gt;' href='http://nohost/plone/folder' target='_self'><span "
241
+ u"class='pretty_link_content state-private'>Folder&quot;&gt;&lt;script&gt;alert"
242
+ u"(document.domain)&lt;/script&gt;</span></a>",
243
+ )
244
+ pl.tag_title = "tag_title<>"
245
+ pl.contentValue = "contentValue<>"
246
+ self.assertEqual(
247
+ pl.getLink(),
248
+ u"<a class='pretty_link' title='tag_title&lt;&gt;' href='http://nohost/plone/folder' "
249
+ u"target='_self'><span class='pretty_link_content state-private'>contentValue&lt;&gt;</span></a>",
250
+ )
@@ -0,0 +1 @@
1
+ import sys, types, os;p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('imio',));importlib = __import__('importlib.util');__import__('importlib.machinery');m = sys.modules.setdefault('imio', importlib.util.module_from_spec(importlib.machinery.PathFinder.find_spec('imio', [os.path.dirname(p)])));m = m or sys.modules.setdefault('imio', types.ModuleType('imio'));mp = (m or []) and m.__dict__.setdefault('__path__',[]);(p not in mp) and mp.append(p)
@@ -0,0 +1,260 @@
1
+ Metadata-Version: 2.4
2
+ Name: imio.prettylink
3
+ Version: 1.24
4
+ Summary: Manage generation of a pretty link to an element including coloration, leading icons, ...
5
+ Home-page: http://pypi.python.org/pypi/imio.prettylink
6
+ Author: Gauthier Bastien
7
+ Author-email: gauthier.bastien@imio.be
8
+ License: GPL
9
+ Keywords: plone pretty link utils dev imio
10
+ Classifier: Environment :: Web Environment
11
+ Classifier: Framework :: Plone
12
+ Classifier: Framework :: Plone :: 4.3
13
+ Classifier: Framework :: Plone :: 5.2
14
+ Classifier: Framework :: Plone :: 6.0
15
+ Classifier: Framework :: Plone :: 6.1
16
+ Classifier: Programming Language :: Python
17
+ Classifier: Programming Language :: Python :: 2.7
18
+ Classifier: Programming Language :: Python :: 3.8
19
+ Classifier: Programming Language :: Python :: 3.9
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Programming Language :: Python :: 3.13
24
+ Requires-Dist: plone.api
25
+ Requires-Dist: imio.helpers>=0.52
26
+ Requires-Dist: setuptools
27
+ Provides-Extra: test
28
+ Requires-Dist: plone.app.testing; extra == "test"
29
+ Requires-Dist: plone.app.robotframework; extra == "test"
30
+ Dynamic: author
31
+ Dynamic: author-email
32
+ Dynamic: classifier
33
+ Dynamic: description
34
+ Dynamic: home-page
35
+ Dynamic: keywords
36
+ Dynamic: license
37
+ Dynamic: provides-extra
38
+ Dynamic: requires-dist
39
+ Dynamic: summary
40
+
41
+ .. image:: https://github.com/IMIO/imio.prettylink/actions/workflows/main.yml/badge.svg
42
+ :target: https://github.com/IMIO/imio.prettylink/actions/workflows/main.yml
43
+
44
+ .. image:: https://coveralls.io/repos/IMIO/imio.prettylink/badge.png?branch=master
45
+ :target: https://coveralls.io/r/IMIO/imio.prettylink?branch=master
46
+
47
+
48
+ ====================
49
+ imio.prettylink
50
+ ====================
51
+
52
+ Manage generation of a pretty link to an element including coloration, leading icons, ...
53
+
54
+ Changelog
55
+ =========
56
+
57
+ 1.24 (2026-01-05)
58
+ -----------------
59
+
60
+ - Addd Plone 6.1 compatibility.
61
+ [chris-adam]
62
+ - Make sure `contentIcon` title HTML attribute contains translated version
63
+ of portal_type's title.
64
+ [gbastien]
65
+
66
+ 1.23 (2025-06-06)
67
+ -----------------
68
+
69
+ - Fixed tag title displaying `&apos;` because `html.escape` was done after
70
+ replacing `'` by `&apos;`, now quote management is done after `html.escape`.
71
+ [gbastien]
72
+
73
+ 1.22 (2024-02-08)
74
+ -----------------
75
+
76
+ - When displaying `contentIcon`, use `typeInfo.Title` method instead translating
77
+ the `typeInfo.title` as `typeInfo.Title` manages various case where title is
78
+ `unicode`, `string` or else.
79
+ [gbastien]
80
+
81
+ 1.21 (2023-08-24)
82
+ -----------------
83
+
84
+ - Adapted call to `imio.helpers.cache.obj_modified` as parameter `asstring=False`
85
+ was removed, we just use the default result type that is `float`.
86
+ [gbastien]
87
+
88
+ 1.20 (2022-06-14)
89
+ -----------------
90
+
91
+ - Escape link content to avoid malicious behaviour.
92
+ [gbastien]
93
+
94
+ 1.19 (2022-01-12)
95
+ -----------------
96
+
97
+ - Used now `imio.helpers.cache.obj_modified` in `getLink_cachekey` to include
98
+ annotation change in modification date.
99
+ [sgeulette]
100
+ - Updated git fetch url
101
+ [sgeulette]
102
+
103
+ 1.18 (2021-03-08)
104
+ -----------------
105
+
106
+ - Improve check for file when adding `@@download` in url.
107
+ [laz, boulch]
108
+
109
+ 1.17 (2020-10-06)
110
+ -----------------
111
+
112
+ - Set icons `<img>` tag `width=16px` and `height=16px` to make `tooltipster`
113
+ happy (computed area to display depends on displayed content).
114
+ [gbaastien]
115
+
116
+ 1.16 (2020-01-10)
117
+ -----------------
118
+
119
+ - While generating not viewable URL, avoid double blank before tag title.
120
+ [gbastien]
121
+ - Adapted `PrettyLinkAdapter.CSSClasses` to manage `<a>` tag CSS classes and
122
+ `<span>` tag CSS classes. `additionalCSSClasses` are set on the `<a>` tag.
123
+ [gbastien]
124
+
125
+ 1.15 (2019-11-26)
126
+ -----------------
127
+
128
+ - Removed `unittest2`.
129
+ [gbastien]
130
+ - Moved the state related CSS class from the `<a>/<div>` tag to the `<span>`
131
+ inner tag, this way it is easier to define CSS compatible for
132
+ `imio.prettylink` and `imio.history`.
133
+ [gbastien]
134
+
135
+ 1.14 (2019-05-16)
136
+ -----------------
137
+
138
+ - Use context.UID instead context in ram.cache cachekey.
139
+ [gbastien]
140
+ - Moved rendering link HTML pattern to the link_pattern so it can be changed.
141
+ [gbastien]
142
+
143
+ 1.13 (2019-01-31)
144
+ -----------------
145
+
146
+ - Fixed `getLink` cachekey to use `SERVER_URL` instead `ACTUAL_URL` or value is
147
+ computed depending on current URL and it leads to be computed on several
148
+ places (dashboard, view, ...). What we need is just to compute if application
149
+ is accessed thru different portal URL.
150
+ [gbastien]
151
+
152
+ 1.12 (2018-08-22)
153
+ -----------------
154
+
155
+ - Small fixes, `isort`, do not compute `icons_tag` at 2 places and
156
+ `self.notViewableHelpMessage` is always defined.
157
+ [gbastien]
158
+
159
+ 1.11 (2018-07-24)
160
+ -----------------
161
+
162
+ - Use `self.context.wl_isLocked()` to show locking icon so it does not break
163
+ on non lockable objects.
164
+ [gbastien]
165
+ - Added boolean `display_tag_title` parameter.
166
+ [sgeulette]
167
+
168
+ 1.10 (2018-01-06)
169
+ -----------------
170
+
171
+ - Handle icon path correctly.
172
+ [sgeulette]
173
+
174
+ 1.9 (2017-02-17)
175
+ ----------------
176
+
177
+ - Do simplify link to file the download by just appending the @@download to
178
+ the URL, this is enough if current context has a primary field.
179
+ [gbastien]
180
+
181
+ 1.8 (2017-02-13)
182
+ ----------------
183
+
184
+ - Take `ACTUAL_URL` stored in the REQUEST into account in the `getLink` caching
185
+ cachekey to manage the fact that the URL to the element changed. This can
186
+ be the case when accessing element thru different domains or if a parent
187
+ of the element was renamed.
188
+ [gbastien]
189
+
190
+ 1.7 (2017-02-02)
191
+ ----------------
192
+
193
+ - Do not break in `PrettyLinkAdapter.getLink_cachekey` if context does not have
194
+ a workflow.
195
+ [gbastien]
196
+
197
+ 1.6 (2017-02-01)
198
+ ----------------
199
+
200
+ - Added caching for `PrettyLinkAdapter.getLink`, the cachekey returns context,
201
+ modified, is_locked, review_state and every parameters defined in
202
+ `PrettyLinkAdapter.__init__`.
203
+ [gbastien]
204
+ - Moved link computation from `PrettyLinkAdapter.getLink` that is now a cached
205
+ method to `PrettyLinkAdapter._getLink` so it is possible to call it directly
206
+ without caching or to override it.
207
+ [gbastien]
208
+ - Finalized testing configuration to be able to test the getLink caching.
209
+ [gbastien]
210
+
211
+ 1.5 (2017-01-25)
212
+ ----------------
213
+
214
+ - Added submethod _get_url that does the url computation.
215
+ Additionally it manages the fact that context is a Dexterity file and
216
+ append relevant part to the url (/@@download/...).
217
+ [gbastien]
218
+ - Do not break if icon name contains special characters.
219
+ [gbastien]
220
+
221
+ 1.4 (2016-08-17)
222
+ ----------------
223
+
224
+ - Added CSS class 'no_access' to <span> "can_not_access_this_element"
225
+ in addition to class 'discreet' so it may be customized if necessary.
226
+ [gbastien]
227
+ - Initialize the 'title' attribute with contentValue, this way if a
228
+ content is cropped to be displayed (maxLength=...), the complete content
229
+ is displayed on hover.
230
+ [gbastien]
231
+
232
+ 1.3 (2016-04-20)
233
+ ----------------
234
+
235
+ - Make sure quotes used in title are not breaking formatted strings,
236
+ we escape it by replacing quotes by it's HTML entity &#39;
237
+ [gbastien]
238
+
239
+ 1.2 (2016-02-16)
240
+ ----------------
241
+
242
+ - If 'isViewable' is True (default), check that current user have
243
+ 'View' on the linked element, if it is forced to False, leave it False.
244
+ This way, 'View' check to linked element is managed by imio.prettylink.
245
+ [gbastien]
246
+
247
+ 1.1 (2015-11-13)
248
+ ----------------
249
+
250
+ - When using 'showColors', do not fail if element has no workflow.
251
+ [gbastien]
252
+ - Makes 'showContentIcon' work, fixed several bugs.
253
+ [gbastien]
254
+
255
+ 1.0 (2015-07-14)
256
+ ----------------
257
+
258
+ - Initial release.
259
+ [gbastien]
260
+
@@ -0,0 +1,19 @@
1
+ imio.prettylink-1.24-py3.12-nspkg.pth,sha256=XTPlQ7ZZOJ9eevOTxBxBdF9Aj2jiqvd7Y7Vv5Sy8VA4,457
2
+ imio/prettylink/__init__.py,sha256=BUfSEC3WBFQvoAPVvEvGwR6lvH7Q2js9EzRr7PStcs0,220
3
+ imio/prettylink/adapters.py,sha256=6lYZUrCCKGeAyEBxqZkwbAY5Kfvt8ZnkDRi2vTvA6vI,10064
4
+ imio/prettylink/configure.zcml,sha256=JdWyszyqk3uzart8L9Z8K6rTLpbCBPjo8nrSlujbsdw,547
5
+ imio/prettylink/interfaces.py,sha256=AwL6BU-9DgzvTO7rjN5GCARgNvL9-TpbqltJdXDgDGI,792
6
+ imio/prettylink/testing.py,sha256=vedfNL8lS-aKI2okhFtdI4PGclFUaL2jA77Zk3uIHdU,2872
7
+ imio/prettylink/testing.zcml,sha256=KNF3JV-Jtu2ZA4GnpLHSfpyDDFbh4g04DSgj8wQHWdE,211
8
+ imio/prettylink/locales/imio.prettylink.pot,sha256=_qNCyBwCRK1JgQtwI70qFxpm4rgt5RDOPIqUkXOitE8,498
9
+ imio/prettylink/locales/sync_pos.sh,sha256=1HXPxYnrPSj6RxGdFHMJRhP9871x0ojARK-tGy_yk80,264
10
+ imio/prettylink/locales/en/LC_MESSAGES/imio.prettylink.po,sha256=Pn_phezixo74R-2sMrqQjQHx6hBmLPy-cuFoPsHr1Po,691
11
+ imio/prettylink/locales/fr/LC_MESSAGES/imio.prettylink.po,sha256=6D9QuHblk5wrRgk5MevoqHPONZNm1RwyiqELYU6uCGo,699
12
+ imio/prettylink/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
+ imio/prettylink/tests/test_adapter.py,sha256=0Wf5h8izXUROR2EwBqfqGHD5tkmCw4_zoHJ7bhgD1iY,12966
14
+ imio_prettylink-1.24.dist-info/METADATA,sha256=-txYr11wCgHnLivIT74TRNgf_8BPtYMwZo9ycSR-Zgs,7413
15
+ imio_prettylink-1.24.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
16
+ imio_prettylink-1.24.dist-info/entry_points.txt,sha256=b5cHz9FINNyhunUZ6BJOQMhgeAi2x9UcnAkA9l8KEC4,40
17
+ imio_prettylink-1.24.dist-info/namespace_packages.txt,sha256=ZktC0EGzThvMTAin9_q_41rzvvfMT2FYbP8pbhSLMSA,5
18
+ imio_prettylink-1.24.dist-info/top_level.txt,sha256=ZktC0EGzThvMTAin9_q_41rzvvfMT2FYbP8pbhSLMSA,5
19
+ imio_prettylink-1.24.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [z3c.autoinclude.plugin]
2
+ target = plone
@@ -0,0 +1 @@
1
+ imio