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.relation.interfaces import IRelationRegistry
|
||||
from cybertools.text import mimetypes
|
||||
from cybertools.typology.interfaces import IType, ITypeManager
|
||||
from loops.interfaces import IView
|
||||
from loops.resource import Resource
|
||||
|
@ -173,6 +174,17 @@ class BaseView(GenericView):
|
|||
def typeTitle(self):
|
||||
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
|
||||
def typeUrl(self):
|
||||
provider = self.typeProvider
|
||||
|
|
|
@ -91,22 +91,23 @@
|
|||
<th i18n:translate="label_modifdate">Modification Date</th>
|
||||
</tr>
|
||||
<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">
|
||||
<td valign="top">
|
||||
<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>
|
||||
</a>
|
||||
</td>
|
||||
<td><span tal:replace="related/typeTitle">Type</span></td>
|
||||
<td><span tal:replace="related/longTypeTitle">Type</span></td>
|
||||
<td style="text-align: right">
|
||||
<span tal:replace="related/context/sizeForDisplay">Type</span>
|
||||
</td>
|
||||
<td><span tal:replace="related/modified">Type</span></td>
|
||||
</tr>
|
||||
<tr tal:define="description related/description"
|
||||
tal:condition="description"
|
||||
<tr tal:condition="nothing"
|
||||
tal:attributes="class class">
|
||||
<td colspan="4" style="padding-left: 7em">
|
||||
<i tal:content="description">describing...</i>
|
||||
|
|
|
@ -249,6 +249,13 @@
|
|||
class=".resource.ResourceView"
|
||||
attribute="show" />
|
||||
|
||||
<page
|
||||
for="loops.interfaces.IResource"
|
||||
name="download.html"
|
||||
permission="zope.View"
|
||||
class=".resource.ResourceView"
|
||||
attribute="download" />
|
||||
|
||||
<zope:adapter
|
||||
for="loops.interfaces.IResource
|
||||
zope.publisher.interfaces.browser.IBrowserRequest"
|
||||
|
@ -596,6 +603,14 @@
|
|||
permission="zope.View"
|
||||
/>
|
||||
|
||||
<page
|
||||
name="download.html"
|
||||
for="loops.interfaces.INode"
|
||||
class=".node.NodeView"
|
||||
attribute="targetDownload"
|
||||
permission="zope.View"
|
||||
/>
|
||||
|
||||
<!-- vocabulary, traversing, and other stuff -->
|
||||
|
||||
<zope:adapter factory="loops.browser.common.LoopsTerms"
|
||||
|
|
|
@ -255,11 +255,10 @@ class NodeView(BaseView):
|
|||
|
||||
# virtual target support
|
||||
|
||||
def targetDefaultView(self):
|
||||
def targetView(self, name='index.html', methodName='show'):
|
||||
target = self.virtualTargetObject
|
||||
if target is not None:
|
||||
ti = IType(target).typeInterface
|
||||
name = zapi.getDefaultViewName(target, self.request)
|
||||
targetView = None
|
||||
if ti is not None:
|
||||
adapted = ti(target)
|
||||
|
@ -270,9 +269,22 @@ class NodeView(BaseView):
|
|||
name=name)
|
||||
if name == 'index.html' and hasattr(targetView, 'show'):
|
||||
return targetView.show()
|
||||
method = getattr(targetView, methodName, None)
|
||||
if method:
|
||||
return method()
|
||||
return targetView()
|
||||
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
|
||||
def virtualTargetObject(self):
|
||||
target = self.request.annotations.get('loops.view', {}).get('target')
|
||||
|
|
|
@ -120,8 +120,12 @@ class ResourceView(BaseView):
|
|||
return DocumentView(context, self.request)
|
||||
return self
|
||||
|
||||
def show(self):
|
||||
def show(self, useAttachment=False):
|
||||
""" show means: "download"..."""
|
||||
#data = self.openForView()
|
||||
#response.setHeader('Content-Disposition',
|
||||
# 'attachment; filename=%s' % zapi.getName(self.context))
|
||||
#return data
|
||||
context = self.context
|
||||
ti = IType(context).typeInterface
|
||||
if ti is not None:
|
||||
|
@ -130,11 +134,16 @@ class ResourceView(BaseView):
|
|||
response = self.request.response
|
||||
response.setHeader('Content-Type', context.contentType)
|
||||
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',
|
||||
'attachment; filename=%s' % zapi.getName(self.context))
|
||||
return data
|
||||
|
||||
def download(self):
|
||||
""" Force download, e.g. of a PDF file """
|
||||
return self.show(True)
|
||||
|
||||
def getActions(self, category='object'):
|
||||
renderer = node_macros.macros['external_edit']
|
||||
node = self.request.annotations.get('loops.view', {}).get('node')
|
||||
|
|
|
@ -46,6 +46,11 @@
|
|||
<h3 tal:content="item/title">Title</h3>
|
||||
<p><i tal:content="item/description">Description</i></p>
|
||||
<p>
|
||||
<a href="#"
|
||||
tal:condition="nothing"
|
||||
tal:attributes="href string:${view/url}/.target${view/targetId}/download.html">
|
||||
Download
|
||||
</a>
|
||||
<a href="#"
|
||||
tal:attributes="href string:${view/url}/.target${view/targetId}/view">
|
||||
Download
|
||||
|
|
|
@ -56,20 +56,21 @@
|
|||
</thead>
|
||||
<tbody>
|
||||
<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">
|
||||
<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" />
|
||||
</td>
|
||||
<td tal:content="row/typeTitle">Type</td>
|
||||
<td tal:content="row/longTypeTitle">Type</td>
|
||||
<td style="text-align: right">
|
||||
<span tal:replace="row/context/sizeForDisplay|string:">Size</span>
|
||||
</td>
|
||||
<td><span tal:replace="row/modified">modified</span></td>
|
||||
</tr>
|
||||
<tr tal:define="description row/description"
|
||||
tal:condition="description"
|
||||
<tr tal:condition="nothing"
|
||||
tal:attributes="class class">
|
||||
<td colspan="3" style="padding-left: 7em">
|
||||
<i tal:content="description">describing...</i>
|
||||
|
|
Loading…
Add table
Reference in a new issue