Added "resource" shared content specificities
authorThierry Florac <thierry.florac@onf.fr>
Fri, 28 Dec 2018 10:50:56 +0100
changeset 316 c12f6c3ac809
parent 315 91448e576861
child 317 46c78cc30b74
Added "resource" shared content specificities
src/pyams_default_theme/shared/resource/__init__.py
src/pyams_default_theme/shared/resource/templates/search-result.pt
src/pyams_default_theme/shared/resource/templates/specificities.pt
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_default_theme/shared/resource/__init__.py	Fri Dec 28 10:50:56 2018 +0100
@@ -0,0 +1,56 @@
+#
+# Copyright (c) 2008-2018 Thierry Florac <tflorac AT ulthar.net>
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+
+__docformat__ = 'restructuredtext'
+
+from zope.interface import Interface
+
+from pyams_content.shared.resource import IResourceInfo, IWfResource
+from pyams_default_theme import lightbox
+from pyams_default_theme.features.search.portlet import ISearchResultRenderer, WfSharedContentSearchResultRenderer
+from pyams_default_theme.interfaces import ISearchResultsView
+from pyams_default_theme.shared.common.interfaces import ICustomContentSpecificitiesParagraphRenderer, \
+    ICustomContentSpecificitiesRenderer
+from pyams_i18n.interfaces import II18n
+from pyams_skin.layer import IPyAMSUserLayer
+from pyams_template.template import template_config
+from pyams_utils.adapter import adapter_config
+from pyams_utils.text import text_to_html
+from pyams_viewlet.viewlet import ViewContentProvider
+
+
+@adapter_config(context=(IWfResource, IPyAMSUserLayer, Interface),
+                provides=ICustomContentSpecificitiesRenderer)
+@adapter_config(context=(IWfResource, IPyAMSUserLayer, Interface),
+                provides=ICustomContentSpecificitiesParagraphRenderer)
+@template_config(template='templates/specificities.pt', layer=IPyAMSUserLayer)
+class ResourceSpecificitiesPortletRenderer(ViewContentProvider):
+    """Resource specificities portlet renderer"""
+
+    resources = (lightbox,)
+
+    @property
+    def resource_info(self):
+        return IResourceInfo(self.context)
+
+
+@adapter_config(context=(IWfResource, IPyAMSUserLayer, ISearchResultsView), provides=ISearchResultRenderer)
+@template_config(template='templates/search-result.pt', layer=IPyAMSUserLayer)
+class WfResourceSearchResultRenderer(WfSharedContentSearchResultRenderer):
+    """Resource search result renderer"""
+
+    @property
+    def header(self):
+        header = II18n(self.context).query_attribute('header', request=self.request)
+        if header:
+            return text_to_html(header)
+        return ''
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_default_theme/shared/resource/templates/search-result.pt	Fri Dec 28 10:50:56 2018 +0100
@@ -0,0 +1,25 @@
+<tal:var define="target view.get_url(context)"
+		 i18n:domain="pyams_default_theme">
+	<div class="thumbnail pull-left col-lg-2 col-md-2 col-sm-3 hidden-xs"
+		 tal:define="illustration tales:pyams_illustration(context)"
+		 tal:condition="illustration">
+		<a href="${target}">
+			<tal:if define="image i18n:illustration.data;
+							alt i18n:illustration.alt_title;"
+					condition="image">
+				${structure:tales:picture(image, lg_width=2, md_width=2, sm_width=3,
+										  xs_width=0, alt=alt, css_class='result_media')}
+			</tal:if>
+		</a>
+	</div>
+	<div>
+		<a href="${target}">
+			<h3>${i18n:context.title}</h3>
+		</a>
+		<div class="tags">${structure:tales:tags(context)}</div>
+		<div class="header"
+			 tal:define="header i18n:context.header">
+			${structure:tales:html(header)}
+		</div>
+	</div>
+</tal:var>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_default_theme/shared/resource/templates/specificities.pt	Fri Dec 28 10:50:56 2018 +0100
@@ -0,0 +1,150 @@
+<div i18n:domain="pyams_default_theme"
+	 tal:define="resource_info view.resource_info;
+				 country resource_info.original_country;
+				 author resource_info.author;
+				 drawer resource_info.drawer;
+				 colourist resource_info.colourist;
+				 lettering resource_info.lettering;
+				 producer resource_info.producer;
+				 director resource_info.director;
+				 actors resource_info.actors;
+				 editor resource_info.editor;
+				 collection resource_info.collection;
+				 series resource_info.series;
+				 volume resource_info.volume;
+				 format resource_info.format;
+				 release_year resource_info.release_year;
+				 awards i18n:resource_info.awards;
+				 nb_pages resource_info.nb_pages;
+				 editor_reference resource_info.editor_reference;
+				 isbn_number resource_info.isbn_number;
+				 source_url resource_info.source_url;
+				 price resource_info.price;
+				 summary i18n:resource_info.summary;
+				 synopsis i18n:resource_info.synopsis;
+				 publisher_words i18n:resource_info.publisher_words;
+				 field_names context.field_names;">
+	<tal:if define="illustration tales:pyams_illustration(context)"
+			condition="illustration">
+		<div class="pull-right col-lg-3 col-md-3 col-sm-4 col-xs-5"
+			 tal:define="data i18n:illustration.data;
+						 alt i18n:illustration.alt_title;"
+			 tal:condition="data">
+			<a data-toggle="lightbox"
+			   data-type="image"
+			   data-title="${i18n:illustration.title}"
+			   data-footer="${i18n:illustration.author}"
+			   href="${tales:absolute_url(data)}">
+				${structure:tales:picture(data, lg_width=3, md_width=3, sm_width=4,
+										  xs_width=5, css_class='img_responsive', alt=alt)}
+			</a>
+		</div>
+	</tal:if>
+	<dl class="dl-horizontal col-lg-9 col-md-9 col-sm-8 col-xs-7">
+		<tal:loop repeat="field field_names">
+			<tal:case switch="field">
+				<tal:if case="'original_country'" condition="country">
+					<dt i18n:translate="">Original country:</dt>
+					<dd>${country}</dd>
+				</tal:if>
+				<tal:if case="'author'" condition="author">
+					<dt i18n:translate="">Author:</dt>
+					<dd>${author}</dd>
+				</tal:if>
+				<tal:if case="'drawer'" condition="drawer">
+					<dt i18n:translate="">Drawer:</dt>
+					<dd>${drawer}</dd>
+				</tal:if>
+				<tal:if case="'colourist'" condition="colourist">
+					<dt i18n:translate="">Colourist:</dt>
+					<dd>${colourist}</dd>
+				</tal:if>
+				<tal:if case="'lettering'" condition="lettering">
+					<dt i18n:translate="">Lettering:</dt>
+					<dd>${lettering}</dd>
+				</tal:if>
+				<tal:if case="'producer'" condition="producer">
+					<dt i18n:translate="">Producer:</dt>
+					<dd>${producer}</dd>
+				</tal:if>
+				<tal:if case="'director'" condition="director">
+					<dt i18n:translate="">Director:</dt>
+					<dd>${director}</dd>
+				</tal:if>
+				<tal:if case="'actors'" condition="actors">
+					<dt i18n:translate="">Actors:</dt>
+					<dd>${actors}</dd>
+				</tal:if>
+				<tal:if case="'editor'" condition="editor">
+					<dt i18n:translate="">Editor:</dt>
+					<dd>${editor}</dd>
+				</tal:if>
+				<tal:if case="'collection'" condition="collection">
+					<dt i18n:translate="">Collection:</dt>
+					<dd>${collection}</dd>
+				</tal:if>
+				<tal:if case="'series'" condition="series">
+					<dt i18n:translate="">Series:</dt>
+					<dd>${series}</dd>
+				</tal:if>
+				<tal:if case="'volume'" condition="volume">
+					<dt i18n:translate="">Volume:</dt>
+					<dd>${volume}</dd>
+				</tal:if>
+				<tal:if case="'format'" condition="format">
+					<dt i18n:translate="">Format:</dt>
+					<dd>${format}</dd>
+				</tal:if>
+				<tal:if case="'release_year'" condition="release_year">
+					<dt i18n:translate="">Release year:</dt>
+					<dd>${release_year}</dd>
+				</tal:if>
+				<tal:if case="'awards'" condition="awards">
+					<dt i18n:translate="">Awards:</dt>
+					<dd>
+						<ul>
+							<li tal:repeat="line awards.split('\n')">${line}</li>
+						</ul>
+					</dd>
+				</tal:if>
+				<tal:if case="'nb_pages'" condition="nb_pages">
+					<dt i18n:translate="">Number of pages:</dt>
+					<dd>${nb_pages}</dd>
+				</tal:if>
+				<tal:if case="'editor_reference'" condition="editor_reference">
+					<dt i18n:translate="">Editor reference:</dt>
+					<dd>${editor_reference}</dd>
+				</tal:if>
+				<tal:if case="'isbn_number'" condition="isbn_number">
+					<dt i18n:translate="">ISBN number:</dt>
+					<dd>${isbn_number}</dd>
+				</tal:if>
+				<tal:if case="'price'" condition="price">
+					<dt i18n:translate="">Price:</dt>
+					<dd i18n:translate="">€ <i18n:var name="price">${'{0:.2f}'.format(price)}</i18n:var></dd>
+				</tal:if>
+			</tal:case>
+		</tal:loop>
+	</dl>
+	<div class="clearfix"></div>
+	<blockquote class="small"
+				tal:condition="('summary'in field_names) and summary">
+		<strong i18n:translate="">Summary</strong>
+		<div>${structure:tales:html(summary, 'oid_to_href;glossary')}</div>
+	</blockquote>
+	<blockquote class="small"
+				tal:condition="('synopsis'in field_names) and synopsis">
+		<strong i18n:translate="">Synopsis</strong>
+		<div>${structure:tales:html(synopsis, 'oid_to_href;glossary')}</div>
+	</blockquote>
+	<blockquote class="small"
+				tal:condition="('publisher_words'in field_names) and publisher_words">
+		<strong i18n:translate="">Publisher's words</strong>
+		<div>${structure:tales:html(publisher_words, 'oid_to_href;glossary')}</div>
+	</blockquote>
+	<dl class="dl-horizontal"
+		tal:condition="('source_url' in field_names) and source_url">
+		<dt i18n:translate="">More resource info:</dt>
+		<dd><a href="${source_url}" target="_blank">${source_url}</a></dd>
+	</dl>
+</div>
\ No newline at end of file