[Products.Silva][Sylvain Viollon] Add an information portlet for...
[email protected] Mon, 11 Nov 2013 16:55:39 +0100
| Newsgroups | gmane.comp.web.zope.silva.cvs |
|---|---|
| Message-ID | <[email protected]> |
author: Sylvain Viollon
date: Mon Nov 11 16:55:32 2013 +0100
revision: 11879:01355a2a8b4e in Products.Silva
branch: 2.4
details: https://hg.infrae.com/Products.Silva?cmd=changeset;node=01355a2a8b4e
modified: Products/Silva/File/smi.py Products/Silva/File/smi_templates/infoportlet.cpt Products/Silva/GhostAsset/content.py Products/Silva/GhostAsset/smi.py Products/Silva/GhostAsset/smi_templates/ghostassetportlet.cpt Products/Silva/GhostAsset/views.py Products/Silva/GhostFolder/smi.py
added: Products/Silva/GhostAsset/smi_templates/ghostassetportlet.cpt
removed:
log: Add an information portlet for ghost asset.
diffstat:
Products/Silva/File/smi.py | 3 +
Products/Silva/File/smi_templates/infoportlet.cpt | 4 +-
Products/Silva/GhostAsset/content.py | 21 +++++++-
Products/Silva/GhostAsset/smi.py | 15 +++++-
Products/Silva/GhostAsset/smi_templates/ghostassetportlet.cpt | 27 +++++++++++
Products/Silva/GhostAsset/views.py | 5 +-
Products/Silva/GhostFolder/smi.py | 2 +-
7 files changed, 67 insertions(+), 10 deletions(-)
diffs (175 lines):
diff -r eb61cd1d2344 -r 01355a2a8b4e Products/Silva/File/smi.py
--- a/Products/Silva/File/smi.py Mon Nov 11 15:01:46 2013 +0100
+++ b/Products/Silva/File/smi.py Mon Nov 11 16:55:32 2013 +0100
@@ -102,6 +102,9 @@
grok.context(IFile)
def update(self):
+ self.filename = self.context.get_filename()
+ self.download_url = self.context.get_download_url(
+ preview=True, request=self.request)
self.mime_type = self.context.get_mime_type()
self.content_encoding = self.context.get_content_encoding()
diff -r eb61cd1d2344 -r 01355a2a8b4e Products/Silva/File/smi_templates/infoportlet.cpt
--- a/Products/Silva/File/smi_templates/infoportlet.cpt Mon Nov 11 15:01:46 2013 +0100
+++ b/Products/Silva/File/smi_templates/infoportlet.cpt Mon Nov 11 16:55:32 2013 +0100
@@ -3,8 +3,8 @@
<h4 i18n:translate="">Link to file</h4>
<p>
<a title="Download" target="_blank"
- tal:content="context.get_filename()"
- tal:attributes="href context.get_download_url(preview=True)"
+ tal:content="viewlet.filename"
+ tal:attributes="href viewlet.download_url"
i18n:attributes="title">
link
</a>
diff -r eb61cd1d2344 -r 01355a2a8b4e Products/Silva/GhostAsset/content.py
--- a/Products/Silva/GhostAsset/content.py Mon Nov 11 15:01:46 2013 +0100
+++ b/Products/Silva/GhostAsset/content.py Mon Nov 11 16:55:32 2013 +0100
@@ -1,8 +1,11 @@
+
+import time
# Zope 3
from five import grok
from zeam.component import component
from zope.interface import noLongerProvides, alsoProvides
+from zope.component import getMultiAdapter
# Zope 2
from AccessControl import ClassSecurityInfo
@@ -14,13 +17,13 @@
from Products.Silva.Ghost import GhostBase
from Products.Silva.Ghost import GhostBaseManipulator, GhostBaseManager
+from silva.core.interfaces import IAssetPayload, IGhostManager
from silva.core.interfaces import IGhostAsset, IAsset
-from silva.core.interfaces import IAssetPayload, IGhostManager
from silva.core.interfaces import IImage, IImageIncluable
from silva.core.interfaces.errors import AssetInvalidTarget
-
+from silva.core.references.reference import DeleteSourceReferenceValue
from silva.core.references.reference import get_content_from_id, get_content_id
-from silva.core.references.reference import DeleteSourceReferenceValue
+from silva.core.views.interfaces import IContentURL
class ImageDeleteSourceReferenceValue(DeleteSourceReferenceValue):
@@ -85,6 +88,18 @@
return asset.get_mime_type()
return 'application/octet-stream'
+ security.declareProtected(
+ SilvaPermissions.View, 'get_download_url')
+ def get_download_url(self, preview=False, request=None):
+ if request is None:
+ request = self.REQUEST
+ url = getMultiAdapter((self, request), IContentURL).url(preview=preview)
+ if preview:
+ # In case of preview we add something that change at the
+ # end of the url to prevent caching from the browser.
+ url += '?' + str(int(time.time()))
+ return url
+
def get_quota_usage(self):
# Ghost Assets don't use any quota.
return -1
diff -r eb61cd1d2344 -r 01355a2a8b4e Products/Silva/GhostAsset/smi.py
--- a/Products/Silva/GhostAsset/smi.py Mon Nov 11 15:01:46 2013 +0100
+++ b/Products/Silva/GhostAsset/smi.py Mon Nov 11 16:55:32 2013 +0100
@@ -5,11 +5,11 @@
# Silva
from Products.Silva.Ghost import TargetValidator
-from Products.Silva.Asset import AssetEditTab
+from Products.Silva.Asset import AssetEditTab, SMIAssetPortlet
from silva.core.conf.interfaces import IIdentifiedContent
+from silva.core.interfaces import IAsset, IGhostAsset, IImageIncluable
from silva.core.references.reference import Reference
-from silva.core.interfaces import IAsset, IGhostAsset
from silva.translations import translate as _
from zeam.form import silva as silvaforms
@@ -54,3 +54,14 @@
silvaforms.CancelEditAction(),
silvaforms.EditAction())
+
+class GhostAssetPortlet(SMIAssetPortlet):
+ grok.context(IGhostAsset)
+ grok.order(10)
+
+ def update(self):
+ self.is_image = IImageIncluable.providedBy(self.context)
+ self.filename = self.context.get_filename()
+ self.mime_type = self.context.get_mime_type()
+ self.download_url = self.context.get_download_url(
+ preview=True, request=self.request)
diff -r eb61cd1d2344 -r 01355a2a8b4e Products/Silva/GhostAsset/smi_templates/ghostassetportlet.cpt
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Products/Silva/GhostAsset/smi_templates/ghostassetportlet.cpt Mon Nov 11 16:55:32 2013 +0100
@@ -0,0 +1,27 @@
+<tal:info i18n:domain="silva">
+ <div class="portlet"
+ tal:condition="viewlet.is_image"
+ i18n:domain="silva">
+ <h4 i18n:translate="">Inclusion in documents</h4>
+ <p i18n:translate="">
+ This asset can be included as an image inside documents.
+ </p>
+ </div>
+
+ <div class="portlet">
+ <h4 i18n:translate="">Link to file</h4>
+ <p>
+ <a title="Download" target="_blank"
+ tal:content="viewlet.filename"
+ tal:attributes="href viewlet.download_url"
+ i18n:attributes="title">
+ link
+ </a>
+ </p>
+ </div>
+
+ <div class="portlet" tal:condition="viewlet.mime_type">
+ <h4 i18n:translate="">File mime type</h4>
+ <p tal:content="viewlet.mime_type">mime type</p>
+ </div>
+</tal:info>
diff -r eb61cd1d2344 -r 01355a2a8b4e Products/Silva/GhostAsset/views.py
--- a/Products/Silva/GhostAsset/views.py Mon Nov 11 15:01:46 2013 +0100
+++ b/Products/Silva/GhostAsset/views.py Mon Nov 11 16:55:32 2013 +0100
@@ -12,11 +12,11 @@
from AccessControl import Unauthorized
# Silva
+from silva.core.interfaces import IGhostAsset, IDownloableAsset
from silva.core.views import views as silvaviews
-from silva.core.interfaces import IGhostAsset, IDownloableAsset
-from silva.translations import translate as _
from silva.core.views.httpheaders import HTTPResponseHeaders
from silva.core.views.interfaces import IHTTPResponseHeaders
+from silva.translations import translate as _
class GhostAssetView(silvaviews.View):
@@ -71,3 +71,4 @@
(self.request, haunted),
IHTTPResponseHeaders)
headers.other_headers(headers)
+
diff -r eb61cd1d2344 -r 01355a2a8b4e Products/Silva/GhostFolder/smi.py
--- a/Products/Silva/GhostFolder/smi.py Mon Nov 11 15:01:46 2013 +0100
+++ b/Products/Silva/GhostFolder/smi.py Mon Nov 11 16:55:32 2013 +0100
@@ -65,7 +65,7 @@
""" Edit form Ghost Folder
"""
grok.context(IGhostFolder)
- grok.name('silva.ui.edit')
+ grok.name('edit')
fields = silvaforms.Fields(IGhostFolderSchema).omit('id')
dataValidators = [TargetValidator('haunted', IContainer, adding=False)]