From ed33e9b1a8ae0029154adf5286638f1c5918f150 Mon Sep 17 00:00:00 2001 From: Thibaut Born Date: Tue, 23 Mar 2021 17:25:19 +0100 Subject: [PATCH 1/3] Problem: customizing tabular view is hard Solution: use views for table cells such that they can be overridden --- plone/app/contenttypes/browser/collection.py | 1 + plone/app/contenttypes/browser/configure.zcml | 16 ++++++ plone/app/contenttypes/browser/folder.py | 32 +++++++++++ plone/app/contenttypes/browser/tabular.py | 55 +++++++++++++++++++ .../browser/templates/creatorcell.pt | 5 ++ .../browser/templates/listing_tabular.pt | 50 +---------------- .../browser/templates/titlecell.pt | 19 +++++++ 7 files changed, 130 insertions(+), 48 deletions(-) create mode 100644 plone/app/contenttypes/browser/tabular.py create mode 100644 plone/app/contenttypes/browser/templates/creatorcell.pt create mode 100644 plone/app/contenttypes/browser/templates/titlecell.pt diff --git a/plone/app/contenttypes/browser/collection.py b/plone/app/contenttypes/browser/collection.py index a41b6959c..264c5640d 100644 --- a/plone/app/contenttypes/browser/collection.py +++ b/plone/app/contenttypes/browser/collection.py @@ -76,6 +76,7 @@ def album_folders(self): """ return self._album_results['folders'] + @property def tabular_fields(self): """Returns a list of all metadata fields from the catalog that were selected. diff --git a/plone/app/contenttypes/browser/configure.zcml b/plone/app/contenttypes/browser/configure.zcml index bcde01358..7f0010f07 100644 --- a/plone/app/contenttypes/browser/configure.zcml +++ b/plone/app/contenttypes/browser/configure.zcml @@ -258,4 +258,20 @@ + + + + diff --git a/plone/app/contenttypes/browser/folder.py b/plone/app/contenttypes/browser/folder.py index 6526f9b19..3c7716b58 100644 --- a/plone/app/contenttypes/browser/folder.py +++ b/plone/app/contenttypes/browser/folder.py @@ -15,6 +15,8 @@ from zope.component import getMultiAdapter from zope.component import getUtility from zope.contentprovider.interfaces import IContentProvider +from zope.component import queryMultiAdapter +from zope.i18n import translate import random @@ -31,6 +33,7 @@ class FolderView(BrowserView): _plone_view = None _portal_state = None _pas_member = None + _image_scale = None @property def plone_view(self): @@ -50,6 +53,16 @@ def portal_state(self): ) return self._portal_state + @property + def image_scale(self): + if not self._image_scale: + portal = self.portal_state.portal() + self._image_scale = getMultiAdapter( + (portal, self.request), + name=u'image_scale' + ) + return self._image_scale + @property def pas_member(self): if not self._pas_member: @@ -189,6 +202,21 @@ def tabular_fielddata(self, item, fieldname): 'value': value } + def render_cells(self, item): + result = [] + for field in self.tabular_fields: + if field == 'getIcon': + continue + cell_view = queryMultiAdapter((item, self.request), name=field) + if cell_view is not None: + cell_view.table_view = self + result.append(cell_view()) + else: + field_data = self.tabular_fielddata(item, field) + value = translate(field_data['value'], context=self.request) + result.append('%s' % value) + return ''.join(result) + def is_event(self, obj): if getattr(obj, 'getObject', False): obj = obj.getObject() @@ -265,6 +293,10 @@ def get_thumb_scale_table(self): return None return settings.thumb_scale_table + @property + def img_class(self): + return 'thumb-%s pull-right' % self.get_thumb_scale_table() + @memoize def get_thumb_scale_list(self): if getattr(self.context, 'suppress_thumbs', False): diff --git a/plone/app/contenttypes/browser/tabular.py b/plone/app/contenttypes/browser/tabular.py new file mode 100644 index 000000000..b7b907476 --- /dev/null +++ b/plone/app/contenttypes/browser/tabular.py @@ -0,0 +1,55 @@ +from Products.Five import BrowserView + +# BEWARE: the cell views are registered for ContentListingObject +# which are not acquisition aware. +# That precludes using Products.Five.ViewPageTemplateFile +# and imposes to use zope.browserpage.viewpagetemplatefile. +from zope.browserpage.viewpagetemplatefile import ViewPageTemplateFile +# BEWARE + +class TitleCell(BrowserView): + __call__ = ViewPageTemplateFile('templates/titlecell.pt') + + @property + def title(self): + return self.context.Title() or self.context.getId() + + @property + def link(self): + suffix = ( + '/view' + if self.context.PortalType in self.table_view.use_view_action + else '' + ) + return self.context.getURL() + suffix + + @property + def type_class(self): + return ('contenttype-' + + self.table_view.normalizeString(self.context.PortalType()) + if self.table_view.show_icons else '') + + @property + def wf_state_class(self): + return ('state-' + + self.table_view.normalizeString(self.context.review_state())) + + def render_image(self): + thumb_scale_table = self.table_view.get_thumb_scale_table() + img_class = self.table_view.img_class + return self.table_view.image_scale.tag( + self.context, 'image', + scale=thumb_scale_table, css_class=img_class + ) + + +class CreatorCell(BrowserView): + __call__ = ViewPageTemplateFile('templates/creatorcell.pt') + + @property + def author(self): + return self.table_view.pas_member.info(self.context.Creator) + + @property + def author_name(self): + return self.author['fullname'] or self.author['username'] diff --git a/plone/app/contenttypes/browser/templates/creatorcell.pt b/plone/app/contenttypes/browser/templates/creatorcell.pt new file mode 100644 index 000000000..52f1eb2c9 --- /dev/null +++ b/plone/app/contenttypes/browser/templates/creatorcell.pt @@ -0,0 +1,5 @@ + + Jos Henken + diff --git a/plone/app/contenttypes/browser/templates/listing_tabular.pt b/plone/app/contenttypes/browser/templates/listing_tabular.pt index b344c7c99..9a9dc8b2c 100644 --- a/plone/app/contenttypes/browser/templates/listing_tabular.pt +++ b/plone/app/contenttypes/browser/templates/listing_tabular.pt @@ -43,57 +43,11 @@ - - - - - - - - - - - Item Title - - - - - - - Jos Henken - - - + tal:attributes="class python: oddrow and 'even' or 'odd'" + tal:content="structure python:view.render_cells(item)"> - diff --git a/plone/app/contenttypes/browser/templates/titlecell.pt b/plone/app/contenttypes/browser/templates/titlecell.pt new file mode 100644 index 000000000..e354c6124 --- /dev/null +++ b/plone/app/contenttypes/browser/templates/titlecell.pt @@ -0,0 +1,19 @@ + + + + + Item Title + + + + + From 8452de8f8f1758581fde2b51e5c40cfb5cfdbf69 Mon Sep 17 00:00:00 2001 From: Godefroid Chapelle Date: Thu, 8 Apr 2021 11:14:12 +0200 Subject: [PATCH 2/3] Problem: buildout does not run anymore Solution: fix pinned versions, do not force installing ride and reload for robotframework --- buildout.cfg | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/buildout.cfg b/buildout.cfg index 5ee40fa55..29ebefb77 100644 --- a/buildout.cfg +++ b/buildout.cfg @@ -61,7 +61,7 @@ eggs = recipe = zc.recipe.egg eggs = ${test:eggs} - plone.app.robotframework[debug,ride,reload] + plone.app.robotframework[debug] [releaser] @@ -85,10 +85,9 @@ plone.app.contenttypes = # Temporarily until next Plone version is out: plone.app.querystring = 1.3.4 -robotframework = 2.8.4 +robotframework = 2.9.2 robotframework-ride = 1.3 robotframework-selenium2library = 1.6.0 robotsuite = 1.6.1 selenium = 2.46.0 coverage = 3.7.1 -pycodestyle = 2.3.1 From 0f3fa02beadd7ae4f7334a312a8e2547de5d520d Mon Sep 17 00:00:00 2001 From: Godefroid Chapelle Date: Thu, 8 Apr 2021 11:15:31 +0200 Subject: [PATCH 3/3] Problem: changelog missing Solution: add it --- news/customize-tabular.feature | 1 + 1 file changed, 1 insertion(+) create mode 100644 news/customize-tabular.feature diff --git a/news/customize-tabular.feature b/news/customize-tabular.feature new file mode 100644 index 000000000..451196464 --- /dev/null +++ b/news/customize-tabular.feature @@ -0,0 +1 @@ +Enable customization of tabular_view via views for fields of contentlisting items.