# HG changeset patch # User Thierry Florac # Date 1570208991 -7200 # Node ID ebef14b037b39fed973dc67b157ab1e0f4d8e704 # Parent 445f6edc944d2304090641b18bdcad03560c6015 Updated portlet renderer settings diff -r 445f6edc944d -r ebef14b037b3 src/pyams_default_theme/features/search/portlet/__init__.py --- a/src/pyams_default_theme/features/search/portlet/__init__.py Fri Oct 04 19:08:38 2019 +0200 +++ b/src/pyams_default_theme/features/search/portlet/__init__.py Fri Oct 04 19:09:51 2019 +0200 @@ -22,7 +22,8 @@ from pyams_default_theme.features.search.portlet.interfaces import ISearchResultHeader, \ ISearchResultRenderer, ISearchResultTarget, ISearchResultTitle, \ ISearchResultsPortletDefaultRendererSettings, ISearchResultsPortletPanelsRendererSettings, \ - ISearchResultsPortletRendererBaseSettings + ISearchResultsPortletRendererBaseSettings, HIDDEN_HEADER_DISPLAY, START_HEADER_DISPLAY, \ + FULL_HEADER_DISPLAY from pyams_default_theme.interfaces import ISearchResultsPanelView, ISearchResultsView from pyams_default_theme.shared.common.interfaces import ISharedContentHeadViewletManager from pyams_i18n.interfaces import II18n @@ -33,6 +34,7 @@ from pyams_template.template import template_config from pyams_utils.adapter import NullAdapter, adapter_config from pyams_utils.factory import factory_config +from pyams_utils.text import get_text_start from pyams_utils.url import canonical_url, relative_url from pyams_viewlet.viewlet import ViewContentProvider, Viewlet, viewlet_config @@ -119,6 +121,9 @@ class SearchResultsPortletPanelsRendererSettings(SearchResultsPortletRendererBaseSettings): """Search results portlet panel renderer settings""" + header_display_mode = FieldProperty( + ISearchResultsPortletPanelsRendererSettings['header_display_mode']) + start_length = FieldProperty(ISearchResultsPortletPanelsRendererSettings['start_length']) button_title = FieldProperty(ISearchResultsPortletPanelsRendererSettings['button_title']) @@ -190,8 +195,17 @@ @property def header(self): - return self.request.registry.queryMultiAdapter((self.context, self.request, self.view), - ISearchResultHeader) + display_mode = FULL_HEADER_DISPLAY + settings = self.view.renderer_settings + if ISearchResultsPortletPanelsRendererSettings.providedBy(settings): + display_mode = settings.header_display_mode + if display_mode == HIDDEN_HEADER_DISPLAY: + return '' + header = self.request.registry.queryMultiAdapter((self.context, self.request, self.view), + ISearchResultHeader) + if display_mode == START_HEADER_DISPLAY: + header = get_text_start(header, settings.start_length) + return header @adapter_config(context=(IWfSharedContent, IPyAMSUserLayer, ISearchResultsPanelView), diff -r 445f6edc944d -r ebef14b037b3 src/pyams_default_theme/features/search/portlet/interfaces.py --- a/src/pyams_default_theme/features/search/portlet/interfaces.py Fri Oct 04 19:08:38 2019 +0200 +++ b/src/pyams_default_theme/features/search/portlet/interfaces.py Fri Oct 04 19:09:51 2019 +0200 @@ -9,15 +9,19 @@ # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # FOR A PARTICULAR PURPOSE. # + +from collections import OrderedDict + +from zope.contentprovider.interfaces import IContentProvider +from zope.interface import Attribute, Interface +from zope.schema import Bool, Choice, Int +from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm + from pyams_i18n.schema import I18nTextLineField __docformat__ = 'restructuredtext' -from zope.contentprovider.interfaces import IContentProvider -from zope.interface import Interface, Attribute -from zope.schema import Bool - from pyams_default_theme import _ @@ -64,9 +68,35 @@ """Search results portlet default renderer settings interface""" +FULL_HEADER_DISPLAY = 'full' +START_HEADER_DISPLAY = 'start' +HIDDEN_HEADER_DISPLAY = 'none' + +PANELS_HEADER_DISPLAY_MODES = OrderedDict(( + (FULL_HEADER_DISPLAY, _("Display full header")), + (START_HEADER_DISPLAY, _("Display only header start")), + (HIDDEN_HEADER_DISPLAY, _("Hide header")) +), ) + +PANELS_HEADER_DISPLAY_MODES_VOCABULARY = SimpleVocabulary( + [SimpleTerm(k, title=v) for k, v in PANELS_HEADER_DISPLAY_MODES.items()]) + + class ISearchResultsPortletPanelsRendererSettings(ISearchResultsPortletRendererBaseSettings): """Search results portlet panels renderer settings interface""" + header_display_mode = Choice(title=_("Header display mode"), + description=_("Defines how results headers will be rendered"), + required=True, + vocabulary=PANELS_HEADER_DISPLAY_MODES_VOCABULARY, + default=FULL_HEADER_DISPLAY) + + start_length = Int(title=_("Start length"), + description=_("If you choose to display only header start, you can specify " + "maximum text length"), + required=True, + default=120) + button_title = I18nTextLineField(title=_("Button's title"), description=_("Navigation button's title is normally defined " "based on target's content type; you can " diff -r 445f6edc944d -r ebef14b037b3 src/pyams_default_theme/features/search/portlet/templates/search-panel.pt --- a/src/pyams_default_theme/features/search/portlet/templates/search-panel.pt Fri Oct 04 19:08:38 2019 +0200 +++ b/src/pyams_default_theme/features/search/portlet/templates/search-panel.pt Fri Oct 04 19:09:51 2019 +0200 @@ -20,7 +20,7 @@
- ${structure:tales:html(header)} + ${structure:header}
diff -r 445f6edc944d -r ebef14b037b3 src/pyams_default_theme/shared/view/portlet/__init__.py --- a/src/pyams_default_theme/shared/view/portlet/__init__.py Fri Oct 04 19:08:38 2019 +0200 +++ b/src/pyams_default_theme/shared/view/portlet/__init__.py Fri Oct 04 19:09:51 2019 +0200 @@ -16,15 +16,18 @@ from zope.schema.fieldproperty import FieldProperty from pyams_content.shared.view.portlet.interfaces import IViewItemsPortletSettings +from pyams_default_theme.features.search.portlet import HIDDEN_HEADER_DISPLAY, START_HEADER_DISPLAY from pyams_default_theme.shared.view.portlet.interfaces import \ IViewItemsPortletHorizontalRendererSettings, IViewItemsPortletSummaryRendererSettings, \ IViewItemsPortletVerticalRendererSettings +from pyams_i18n.interfaces import II18n from pyams_portal.interfaces import IPortalContext, IPortletRenderer from pyams_portal.portlet import PortletRenderer from pyams_skin.layer import IPyAMSLayer from pyams_template.template import template_config from pyams_utils.adapter import adapter_config from pyams_utils.factory import factory_config +from pyams_utils.text import get_text_start from pyams_utils.url import canonical_url, relative_url @@ -121,6 +124,9 @@ IViewItemsPortletSummaryRendererSettings['thumbnails_selection']) paginate = FieldProperty(IViewItemsPortletSummaryRendererSettings['paginate']) page_size = FieldProperty(IViewItemsPortletSummaryRendererSettings['page_size']) + header_display_mode = FieldProperty( + IViewItemsPortletSummaryRendererSettings['header_display_mode']) + start_length = FieldProperty(IViewItemsPortletSummaryRendererSettings['start_length']) @adapter_config(name='summary', @@ -134,3 +140,13 @@ weight = 3 settings_interface = IViewItemsPortletSummaryRendererSettings + + def get_header(self, item): + settings = self.renderer_settings + display_mode = settings.header_display_mode + if display_mode == HIDDEN_HEADER_DISPLAY: + return '' + header = II18n(item).query_attribute('header', request=self.request) + if display_mode == START_HEADER_DISPLAY: + header = get_text_start(header, settings.start_length) + return header diff -r 445f6edc944d -r ebef14b037b3 src/pyams_default_theme/shared/view/portlet/interfaces.py --- a/src/pyams_default_theme/shared/view/portlet/interfaces.py Fri Oct 04 19:08:38 2019 +0200 +++ b/src/pyams_default_theme/shared/view/portlet/interfaces.py Fri Oct 04 19:09:51 2019 +0200 @@ -14,6 +14,10 @@ from zope.schema import Bool, Choice, Int from zope.schema.vocabulary import SimpleTerm, SimpleVocabulary +from pyams_default_theme.features.search.portlet import FULL_HEADER_DISPLAY +from pyams_default_theme.features.search.portlet.interfaces import \ + PANELS_HEADER_DISPLAY_MODES_VOCABULARY + __docformat__ = 'restructuredtext' @@ -101,3 +105,15 @@ description=_("Number of items per page, if pagination is enabled"), required=False, default=9) + + header_display_mode = Choice(title=_("Header display mode"), + description=_("Defines how results headers will be rendered"), + required=True, + vocabulary=PANELS_HEADER_DISPLAY_MODES_VOCABULARY, + default=FULL_HEADER_DISPLAY) + + start_length = Int(title=_("Start length"), + description=_("If you choose to display only header start, you can specify " + "maximum text length"), + required=True, + default=120) diff -r 445f6edc944d -r ebef14b037b3 src/pyams_default_theme/shared/view/portlet/templates/view-items-summary.pt --- a/src/pyams_default_theme/shared/view/portlet/templates/view-items-summary.pt Fri Oct 04 19:08:38 2019 +0200 +++ b/src/pyams_default_theme/shared/view/portlet/templates/view-items-summary.pt Fri Oct 04 19:09:51 2019 +0200 @@ -28,8 +28,9 @@

${i18n:item.title}

- ${structure:tales:html(header)} + tal:define="header view.get_header(item)" + tal:condition="header"> + ${structure:header}