no name chooser necessary for generating filenames; allow '-' in normalized names
This commit is contained in:
parent
bb25f17ecc
commit
2ed2bdb76e
3 changed files with 6 additions and 8 deletions
|
@ -47,7 +47,7 @@ from loops.browser.common import EditForm, BaseView
|
||||||
from loops.browser.concept import BaseRelationView, ConceptRelationView
|
from loops.browser.concept import BaseRelationView, ConceptRelationView
|
||||||
from loops.browser.concept import ConceptConfigureView
|
from loops.browser.concept import ConceptConfigureView
|
||||||
from loops.browser.node import NodeView, node_macros
|
from loops.browser.node import NodeView, node_macros
|
||||||
from loops.common import adapted, NameChooser
|
from loops.common import adapted, NameChooser, normalizeName
|
||||||
from loops.interfaces import IBaseResource, IDocument, ITextDocument
|
from loops.interfaces import IBaseResource, IDocument, ITextDocument
|
||||||
from loops.interfaces import IMediaAsset as legacy_IMediaAsset
|
from loops.interfaces import IMediaAsset as legacy_IMediaAsset
|
||||||
from loops.interfaces import ITypeConcept
|
from loops.interfaces import ITypeConcept
|
||||||
|
@ -214,7 +214,8 @@ class ResourceView(BaseView):
|
||||||
if self.typeOptions('no_normalize_download_filename'):
|
if self.typeOptions('no_normalize_download_filename'):
|
||||||
filename = '"%s"' % filename
|
filename = '"%s"' % filename
|
||||||
else:
|
else:
|
||||||
filename = NameChooser(getParent(self.context)).normalizeName(filename)
|
#filename = NameChooser(getParent(self.context)).normalizeName(filename)
|
||||||
|
filename = normalizeName(filename)
|
||||||
response.setHeader('Content-Disposition',
|
response.setHeader('Content-Disposition',
|
||||||
'attachment; filename=%s' % filename)
|
'attachment; filename=%s' % filename)
|
||||||
response.setHeader('Content-Length', len(data))
|
response.setHeader('Content-Length', len(data))
|
||||||
|
|
|
@ -250,7 +250,7 @@ def normalizeName(baseName):
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
result.append('_')
|
result.append('_')
|
||||||
continue
|
continue
|
||||||
if c in '._':
|
if c in '._-':
|
||||||
# separator and special characters to keep
|
# separator and special characters to keep
|
||||||
result.append(c)
|
result.append(c)
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# Copyright (c) 2008 Helmut Merz helmutm@cy55.de
|
# Copyright (c) 2013 Helmut Merz helmutm@cy55.de
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
@ -20,12 +20,9 @@
|
||||||
Views for displaying media assets.
|
Views for displaying media assets.
|
||||||
|
|
||||||
Authors: Johann Schimpf, Erich Seifert.
|
Authors: Johann Schimpf, Erich Seifert.
|
||||||
|
|
||||||
$Id$
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from zope.app.pagetemplate import ViewPageTemplateFile
|
from zope.app.pagetemplate import ViewPageTemplateFile
|
||||||
from zope.app.container.contained import NameChooser
|
|
||||||
from zope.cachedescriptors.property import Lazy
|
from zope.cachedescriptors.property import Lazy
|
||||||
from zope.security.interfaces import Unauthorized
|
from zope.security.interfaces import Unauthorized
|
||||||
from zope.traversing.api import getParent
|
from zope.traversing.api import getParent
|
||||||
|
@ -64,7 +61,7 @@ class MediaAssetView(ResourceView):
|
||||||
if useAttachment:
|
if useAttachment:
|
||||||
filename = obj.localFilename or getName(self.context)
|
filename = obj.localFilename or getName(self.context)
|
||||||
#filename = urllib.quote(filename)
|
#filename = urllib.quote(filename)
|
||||||
filename = NameChooser(getParent(self.context)).chooseName(filename, self.context)
|
filename = normalizeName(filename)
|
||||||
response.setHeader('Content-Disposition',
|
response.setHeader('Content-Disposition',
|
||||||
'attachment; filename=%s' % filename)
|
'attachment; filename=%s' % filename)
|
||||||
return data
|
return data
|
||||||
|
|
Loading…
Add table
Reference in a new issue