minor improvements on resource listings and download
git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@1631 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
59a7039d36
commit
a45f2311f0
7 changed files with 69 additions and 14 deletions
|
@ -44,6 +44,7 @@ from zope.traversing.api import getName
|
||||||
|
|
||||||
from cybertools.browser.view import GenericView
|
from cybertools.browser.view import GenericView
|
||||||
from cybertools.relation.interfaces import IRelationRegistry
|
from cybertools.relation.interfaces import IRelationRegistry
|
||||||
|
from cybertools.text import mimetypes
|
||||||
from cybertools.typology.interfaces import IType, ITypeManager
|
from cybertools.typology.interfaces import IType, ITypeManager
|
||||||
from loops.interfaces import IView
|
from loops.interfaces import IView
|
||||||
from loops.resource import Resource
|
from loops.resource import Resource
|
||||||
|
@ -173,6 +174,17 @@ class BaseView(GenericView):
|
||||||
def typeTitle(self):
|
def typeTitle(self):
|
||||||
return self.type.title
|
return self.type.title
|
||||||
|
|
||||||
|
@Lazy
|
||||||
|
def longTypeTitle(self):
|
||||||
|
t = self.typeTitle
|
||||||
|
ct = getattr(self.context, 'contentType')
|
||||||
|
if ct:
|
||||||
|
ext = mimetypes.extensions.get(ct)
|
||||||
|
if ext:
|
||||||
|
#return '%s (%s)' % (t, ext.upper())
|
||||||
|
return ext.upper()
|
||||||
|
return t
|
||||||
|
|
||||||
@Lazy
|
@Lazy
|
||||||
def typeUrl(self):
|
def typeUrl(self):
|
||||||
provider = self.typeProvider
|
provider = self.typeProvider
|
||||||
|
|
|
@ -91,22 +91,23 @@
|
||||||
<th i18n:translate="label_modifdate">Modification Date</th>
|
<th i18n:translate="label_modifdate">Modification Date</th>
|
||||||
</tr>
|
</tr>
|
||||||
<tal:items repeat="related resources">
|
<tal:items repeat="related resources">
|
||||||
<tal:item define="class python: repeat['related'].odd() and 'even' or 'odd'">
|
<tal:item define="class python: repeat['related'].odd() and 'even' or 'odd';
|
||||||
|
description related/description">
|
||||||
<tr tal:attributes="class class">
|
<tr tal:attributes="class class">
|
||||||
<td valign="top">
|
<td valign="top">
|
||||||
<a href="#"
|
<a href="#"
|
||||||
tal:attributes="href string:${view/url}/.target${related/uniqueId}">
|
tal:attributes="href string:${view/url}/.target${related/uniqueId};
|
||||||
|
title description">
|
||||||
<span tal:replace="related/title">Resource Title</span>
|
<span tal:replace="related/title">Resource Title</span>
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
<td><span tal:replace="related/typeTitle">Type</span></td>
|
<td><span tal:replace="related/longTypeTitle">Type</span></td>
|
||||||
<td style="text-align: right">
|
<td style="text-align: right">
|
||||||
<span tal:replace="related/context/sizeForDisplay">Type</span>
|
<span tal:replace="related/context/sizeForDisplay">Type</span>
|
||||||
</td>
|
</td>
|
||||||
<td><span tal:replace="related/modified">Type</span></td>
|
<td><span tal:replace="related/modified">Type</span></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr tal:define="description related/description"
|
<tr tal:condition="nothing"
|
||||||
tal:condition="description"
|
|
||||||
tal:attributes="class class">
|
tal:attributes="class class">
|
||||||
<td colspan="4" style="padding-left: 7em">
|
<td colspan="4" style="padding-left: 7em">
|
||||||
<i tal:content="description">describing...</i>
|
<i tal:content="description">describing...</i>
|
||||||
|
|
|
@ -249,6 +249,13 @@
|
||||||
class=".resource.ResourceView"
|
class=".resource.ResourceView"
|
||||||
attribute="show" />
|
attribute="show" />
|
||||||
|
|
||||||
|
<page
|
||||||
|
for="loops.interfaces.IResource"
|
||||||
|
name="download.html"
|
||||||
|
permission="zope.View"
|
||||||
|
class=".resource.ResourceView"
|
||||||
|
attribute="download" />
|
||||||
|
|
||||||
<zope:adapter
|
<zope:adapter
|
||||||
for="loops.interfaces.IResource
|
for="loops.interfaces.IResource
|
||||||
zope.publisher.interfaces.browser.IBrowserRequest"
|
zope.publisher.interfaces.browser.IBrowserRequest"
|
||||||
|
@ -596,6 +603,14 @@
|
||||||
permission="zope.View"
|
permission="zope.View"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<page
|
||||||
|
name="download.html"
|
||||||
|
for="loops.interfaces.INode"
|
||||||
|
class=".node.NodeView"
|
||||||
|
attribute="targetDownload"
|
||||||
|
permission="zope.View"
|
||||||
|
/>
|
||||||
|
|
||||||
<!-- vocabulary, traversing, and other stuff -->
|
<!-- vocabulary, traversing, and other stuff -->
|
||||||
|
|
||||||
<zope:adapter factory="loops.browser.common.LoopsTerms"
|
<zope:adapter factory="loops.browser.common.LoopsTerms"
|
||||||
|
|
|
@ -255,11 +255,10 @@ class NodeView(BaseView):
|
||||||
|
|
||||||
# virtual target support
|
# virtual target support
|
||||||
|
|
||||||
def targetDefaultView(self):
|
def targetView(self, name='index.html', methodName='show'):
|
||||||
target = self.virtualTargetObject
|
target = self.virtualTargetObject
|
||||||
if target is not None:
|
if target is not None:
|
||||||
ti = IType(target).typeInterface
|
ti = IType(target).typeInterface
|
||||||
name = zapi.getDefaultViewName(target, self.request)
|
|
||||||
targetView = None
|
targetView = None
|
||||||
if ti is not None:
|
if ti is not None:
|
||||||
adapted = ti(target)
|
adapted = ti(target)
|
||||||
|
@ -270,9 +269,22 @@ class NodeView(BaseView):
|
||||||
name=name)
|
name=name)
|
||||||
if name == 'index.html' and hasattr(targetView, 'show'):
|
if name == 'index.html' and hasattr(targetView, 'show'):
|
||||||
return targetView.show()
|
return targetView.show()
|
||||||
|
method = getattr(targetView, methodName, None)
|
||||||
|
if method:
|
||||||
|
return method()
|
||||||
return targetView()
|
return targetView()
|
||||||
return u''
|
return u''
|
||||||
|
|
||||||
|
def targetDefaultView(self):
|
||||||
|
target = self.virtualTargetObject
|
||||||
|
if target is not None:
|
||||||
|
name = zapi.getDefaultViewName(target, self.request)
|
||||||
|
return self.targetView(name)
|
||||||
|
return u''
|
||||||
|
|
||||||
|
def targetDownload(self):
|
||||||
|
return self.targetView('download.html', 'download')
|
||||||
|
|
||||||
@Lazy
|
@Lazy
|
||||||
def virtualTargetObject(self):
|
def virtualTargetObject(self):
|
||||||
target = self.request.annotations.get('loops.view', {}).get('target')
|
target = self.request.annotations.get('loops.view', {}).get('target')
|
||||||
|
|
|
@ -120,8 +120,12 @@ class ResourceView(BaseView):
|
||||||
return DocumentView(context, self.request)
|
return DocumentView(context, self.request)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def show(self):
|
def show(self, useAttachment=False):
|
||||||
""" show means: "download"..."""
|
""" show means: "download"..."""
|
||||||
|
#data = self.openForView()
|
||||||
|
#response.setHeader('Content-Disposition',
|
||||||
|
# 'attachment; filename=%s' % zapi.getName(self.context))
|
||||||
|
#return data
|
||||||
context = self.context
|
context = self.context
|
||||||
ti = IType(context).typeInterface
|
ti = IType(context).typeInterface
|
||||||
if ti is not None:
|
if ti is not None:
|
||||||
|
@ -130,11 +134,16 @@ class ResourceView(BaseView):
|
||||||
response = self.request.response
|
response = self.request.response
|
||||||
response.setHeader('Content-Type', context.contentType)
|
response.setHeader('Content-Type', context.contentType)
|
||||||
response.setHeader('Content-Length', len(data))
|
response.setHeader('Content-Length', len(data))
|
||||||
if not context.contentType.startswith('image/'):
|
ct = context.contentType
|
||||||
|
if useAttachment or (not ct.startswith('image/') and ct != 'application/pdf'):
|
||||||
response.setHeader('Content-Disposition',
|
response.setHeader('Content-Disposition',
|
||||||
'attachment; filename=%s' % zapi.getName(self.context))
|
'attachment; filename=%s' % zapi.getName(self.context))
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
def download(self):
|
||||||
|
""" Force download, e.g. of a PDF file """
|
||||||
|
return self.show(True)
|
||||||
|
|
||||||
def getActions(self, category='object'):
|
def getActions(self, category='object'):
|
||||||
renderer = node_macros.macros['external_edit']
|
renderer = node_macros.macros['external_edit']
|
||||||
node = self.request.annotations.get('loops.view', {}).get('node')
|
node = self.request.annotations.get('loops.view', {}).get('node')
|
||||||
|
|
|
@ -46,6 +46,11 @@
|
||||||
<h3 tal:content="item/title">Title</h3>
|
<h3 tal:content="item/title">Title</h3>
|
||||||
<p><i tal:content="item/description">Description</i></p>
|
<p><i tal:content="item/description">Description</i></p>
|
||||||
<p>
|
<p>
|
||||||
|
<a href="#"
|
||||||
|
tal:condition="nothing"
|
||||||
|
tal:attributes="href string:${view/url}/.target${view/targetId}/download.html">
|
||||||
|
Download
|
||||||
|
</a>
|
||||||
<a href="#"
|
<a href="#"
|
||||||
tal:attributes="href string:${view/url}/.target${view/targetId}/view">
|
tal:attributes="href string:${view/url}/.target${view/targetId}/view">
|
||||||
Download
|
Download
|
||||||
|
|
|
@ -56,20 +56,21 @@
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tal:items tal:repeat="row view/results">
|
<tal:items tal:repeat="row view/results">
|
||||||
<tal:item define="class python: repeat['row'].odd() and 'even' or 'odd'">
|
<tal:item define="class python: repeat['row'].odd() and 'even' or 'odd';
|
||||||
|
description row/description">
|
||||||
<tr tal:attributes="class class">
|
<tr tal:attributes="class class">
|
||||||
<td>
|
<td>
|
||||||
<a tal:attributes="href string:${view/url}/.target${row/uniqueId}"
|
<a tal:attributes="href string:${view/url}/.target${row/uniqueId};
|
||||||
|
title description"
|
||||||
tal:content="row/title" />
|
tal:content="row/title" />
|
||||||
</td>
|
</td>
|
||||||
<td tal:content="row/typeTitle">Type</td>
|
<td tal:content="row/longTypeTitle">Type</td>
|
||||||
<td style="text-align: right">
|
<td style="text-align: right">
|
||||||
<span tal:replace="row/context/sizeForDisplay|string:">Size</span>
|
<span tal:replace="row/context/sizeForDisplay|string:">Size</span>
|
||||||
</td>
|
</td>
|
||||||
<td><span tal:replace="row/modified">modified</span></td>
|
<td><span tal:replace="row/modified">modified</span></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr tal:define="description row/description"
|
<tr tal:condition="nothing"
|
||||||
tal:condition="description"
|
|
||||||
tal:attributes="class class">
|
tal:attributes="class class">
|
||||||
<td colspan="3" style="padding-left: 7em">
|
<td colspan="3" style="padding-left: 7em">
|
||||||
<i tal:content="description">describing...</i>
|
<i tal:content="description">describing...</i>
|
||||||
|
|
Loading…
Add table
Reference in a new issue