def test_getLink_caching_isViewable(self): """Cache takes the 'isViewable' parameter into account.""" adapted = IPrettyLink(self.folder) self.assertTrue(adapted.isViewable) self.assertFalse(adapted.notViewableHelpMessage in adapted.getLink()) adapted.isViewable = False self.assertTrue(adapted.notViewableHelpMessage in adapted.getLink())
def test_getLink_caching_showIcons(self): """Cache takes the 'showIcons' parameter into account.""" adapted = IPrettyLink(self.folder) self.assertTrue(adapted.showIcons) ILockable(self.folder).lock() self.assertTrue(u"lock_icon.png" in adapted.getLink()) adapted.showIcons = False self.assertFalse(u"lock_icon.png" in adapted.getLink())
def test_getLink_caching_target(self): """Cache takes the 'target' parameter into account.""" adapted = IPrettyLink(self.folder) self.assertEqual(adapted.target, '_self') self.assertTrue(u" target='_self'>" in adapted.getLink()) adapted.target = '_blank' self.assertFalse(u" target='_self'>" in adapted.getLink()) self.assertTrue(u" target='_blank'>" in adapted.getLink())
def test_getLink_caching_tag_title(self): """Cache takes the 'tag_title' parameter into account.""" adapted = IPrettyLink(self.folder) self.assertFalse(adapted.tag_title) self.assertTrue(u" title='Folder' " in adapted.getLink()) adapted.tag_title = 'Tag title' self.assertFalse(u" title='Folder' " in adapted.getLink()) self.assertTrue(u" title='Tag title' " in adapted.getLink())
def test_getLink_caching_showColors(self): """Cache takes the 'showColors' parameter into account.""" adapted = IPrettyLink(self.folder) self.assertTrue(adapted.showColors) self.assertTrue(u"<span class='pretty_link_content state-private'" in adapted.getLink()) adapted.showColors = False self.assertFalse(u"<span class='pretty_link_content state-private'" in adapted.getLink())
def test_getLink_caching_appendToUrl(self): """Cache takes the 'appendToUrl' parameter into account.""" adapted = IPrettyLink(self.folder) self.assertFalse(adapted.appendToUrl) self.assertTrue( u" href='http://nohost/plone/folder' " in adapted.getLink()) adapted.appendToUrl = '/@@append_to_url' self.assertTrue(u" href='http://nohost/plone/folder/@@append_to_url' " in adapted.getLink())
def test_getLink_link_tooltip(self): """title attr is absent if display_tag_title is False.""" pl = IPrettyLink(self.folder) self.assertEqual( pl.getLink(), u"<a class='pretty_link' title='Folder' href='http://nohost/plone/folder' " u"target='_self'><span class='pretty_link_content state-private'>Folder</span></a>" ) pl.display_tag_title = False self.assertEqual( pl.getLink(), u"<a class='pretty_link' href='http://nohost/plone/folder' " u"target='_self'><span class='pretty_link_content state-private'>Folder</span></a>" )
def test_getLink_caching_maxLength(self): """Cache takes the 'maxLength' parameter into account.""" adapted = IPrettyLink(self.folder) self.assertFalse(adapted.maxLength) self.assertTrue( u"<span class='pretty_link_content state-private'>Folder</span>" in adapted.getLink()) adapted.maxLength = 2 self.assertFalse( u"<span class='pretty_link_content state-private'>Folder</span>" in adapted.getLink()) self.assertTrue( u"<span class='pretty_link_content state-private'>Fo...</span>" in adapted.getLink())
def test_getLink_caching_contentValue(self): """Cache takes the 'contentValue' parameter into account.""" adapted = IPrettyLink(self.folder) self.assertFalse(adapted.contentValue) self.assertTrue( u"<span class='pretty_link_content state-private'>Folder</span>" in adapted.getLink()) adapted.contentValue = 'Content value' self.assertFalse( u"<span class='pretty_link_content state-private'>Folder</span>" in adapted.getLink()) self.assertTrue( u"<span class='pretty_link_content state-private'>Content value</span>" in adapted.getLink())
def test_getLink_caching_additionalCSSClasses(self): """Cache takes the 'additionalCSSClasses' parameter into account.""" adapted = IPrettyLink(self.folder) self.assertFalse(adapted.additionalCSSClasses) self.assertTrue(u"<span class='pretty_link_content state-private'>" in adapted.getLink()) adapted.additionalCSSClasses = ['custom_css_class'] # additionalCSSClasses are set on the <a> tag # state related CSS class is set on the <span> tag self.assertEqual( adapted.getLink(), u"<a class='pretty_link custom_css_class' title='Folder' " u"href='http://nohost/plone/folder' target='_self'>" u"<span class='pretty_link_content state-private'>Folder</span></a>" )
def getPrettyLink(self, **kwargs): """Return the IPrettyLink version of the title.""" adapted = IPrettyLink(self) adapted.showContentIcon = True for k, v in kwargs.items(): setattr(adapted, k, v) return adapted.getLink()
def test_getLink_caching_kwargs(self): """Cache takes the 'kwargs' parameter into account. By default it is used together with maxLength to define the ellipsis type.""" adapted = IPrettyLink(self.folder) adapted.maxLength = 2 self.assertFalse(adapted.kwargs) self.assertTrue( u"<span class='pretty_link_content state-private'>Fo...</span>" in adapted.getLink()) adapted.kwargs['ellipsis'] = ' [truncated]' self.assertFalse( u"<span class='pretty_link_content state-private'>Fo...</span>" in adapted.getLink()) self.assertTrue( u"<span class='pretty_link_content state-private'>Fo [truncated]</span>" in adapted.getLink())
def getPrettyLink(self, item): pl = IPrettyLink(item) pl.display_tag_title = False if base_hasattr(pl.context, '_link_portal_type'): pl.additionalCSSClasses = ['contenttype-{}'.format(pl.context._link_portal_type)] else: pl.additionalCSSClasses = ['contenttype-{}'.format(pl.context.portal_type)] pl.contentValue = self.contentValue(item) return pl.getLink()
def renderCell(self, item): """ """ obj = self._getObject(item) prettyLinker = IPrettyLink(obj) prettyLinker.target = '_parent' prettyLinker.showContentIcon = True annexes = staticInfos = moreInfos = '' tool = api.portal.get_tool('portal_plonemeeting') cfg = tool.getMeetingConfig(self.context) if obj.meta_type == 'MeetingItem': isPrivacyViewable = obj.adapted().isPrivacyViewable() prettyLinker.isViewable = isPrivacyViewable # display annexes and infos if item and item isPrivacyViewable if isPrivacyViewable: # display moreInfos about item # visible columns are one define for items listings or when the meeting is displayed # so check where we are if IMeeting.providedBy(self.context): # on the meeting if displaying_available_items(self.context): visibleColumns = cfg.getAvailableItemsListVisibleColumns( ) else: visibleColumns = cfg.getItemsListVisibleColumns() else: visibleColumns = cfg.getItemColumns() staticInfos = obj.restrictedTraverse('@@static-infos')( visibleColumns=visibleColumns) if self.showMoreInfos: moreInfos = obj.restrictedTraverse('@@item-more-infos')( visibleColumns=visibleColumns) # display annexes annexes = render_item_annexes(obj, tool) elif obj.getTagName() == 'Meeting': visibleColumns = cfg.getMeetingColumns() staticInfos = obj.restrictedTraverse('@@static-infos')( visibleColumns=visibleColumns) # check_can_view=True because permission check is not enough annexes += obj.restrictedTraverse('@@categorized-childs')( portal_type='annex', check_can_view=True) # display number of items in meeting title contentValue = "{0} [{1}]".format(obj.Title(), obj.number_of_items()) prettyLinker.contentValue = contentValue if annexes: annexes = u"<div class='dashboard_annexes'>{0}</div>".format( annexes) pretty_link = prettyLinker.getLink() return pretty_link + staticInfos + moreInfos + annexes
def test_getLink_caching_showContentIcon(self): """Cache takes the 'showContentIcon' parameter into account.""" adapted = IPrettyLink(self.folder) self.assertTrue(adapted.showIcons) self.assertFalse(adapted.showContentIcon) self.assertFalse(u"contenttype-Folder" in adapted.getLink()) adapted.showContentIcon = True self.assertTrue(u"contenttype-Folder" in adapted.getLink()) typeInfo = api.portal.get_tool('portal_types')['Folder'] # setting an icon self.invalidate_cache() typeInfo.icon_expr = 'string:${portal_url}/myContentIcon.png' self.assertFalse(u"contenttype-Folder" in adapted.getLink()) self.assertTrue(u"plone/myContentIcon.png" in adapted.getLink()) self.invalidate_cache() typeInfo.icon_expr = 'string:${portal_url}/++resource++package/myContentIcon.png' self.assertFalse(u"contenttype-Folder" in adapted.getLink()) self.assertTrue(u"plone/++resource++package/myContentIcon.png" in adapted.getLink()) self.invalidate_cache()
def getPrettyLink(self, obj): pl = IPrettyLink(obj) for k, v in self.params.items(): setattr(pl, k, v) return pl.getLink()