[gen] Pod field: bugfix: too long filenames were generated for downloadable pod results.

This commit is contained in:
Gaetan Delannay 2014-07-11 12:38:24 +02:00
parent 1c2936d76d
commit 811388078f

View file

@ -188,9 +188,9 @@ class Pod(Field):
# Parameter "getChecked" can specify the name of a Ref field belonging # Parameter "getChecked" can specify the name of a Ref field belonging
# to the same gen class. If it is the case, the context of the pod # to the same gen class. If it is the case, the context of the pod
# template will contain an additional object, name "_checked", and # template will contain an additional object, name "_checked", and
# "_checked.<name of the Ref field>" will contain the list of the UIDs # "_checked.<name of the Ref field>" will contain the list of the
# of the referred objects via the Ref field that are currently selected # objects linked via the Ref field that are currently selected in the
# in the user interface. # user interface.
self.getChecked = getChecked self.getChecked = getChecked
if not formats: if not formats:
# Compute default ones # Compute default ones
@ -227,13 +227,15 @@ class Pod(Field):
def getDownloadName(self, obj, template, format, queryRelated): def getDownloadName(self, obj, template, format, queryRelated):
'''Gets the name of the pod result as will be seen by the user that will '''Gets the name of the pod result as will be seen by the user that will
download it.''' download it. Ensure the returned name is not too long for the OS that
fileName = self.getTemplateName(obj, template) will store the downloaded file with this name.'''
norm = obj.tool.normalize
fileName = norm(self.getTemplateName(obj, template))[:100]
if not queryRelated: if not queryRelated:
# This is a POD for a single object: personalize the file name with # This is a POD for a single object: personalize the file name with
# the object title. # the object title.
fileName = '%s-%s' % (obj.title, fileName) fileName = '%s-%s' % (norm(obj.title)[:140], fileName)
return obj.tool.normalize(fileName) + '.' + format return fileName + '.' + format
def getVisibleTemplates(self, obj): def getVisibleTemplates(self, obj):
'''Returns, among self.template, the template(s) that can be shown.''' '''Returns, among self.template, the template(s) that can be shown.'''
@ -470,18 +472,23 @@ class Pod(Field):
if customParams: if customParams:
paramsDict = eval(customParams) paramsDict = eval(customParams)
res.update(paramsDict) res.update(paramsDict)
# Compute the selected UIDS if self.getChecked is specified. # Compute the selected linked objects if self.getChecked is specified
if self.getChecked: # and if the user can read this Ref field.
if self.getChecked and \
obj.allows(obj.getField(self.getChecked).readPermission):
# Get the UIDs specified in the request # Get the UIDs specified in the request
reqUids = rq['checkedUids'] and rq['checkedUids'].split(',') or [] reqUids = rq['checkedUids'] and rq['checkedUids'].split(',') or []
unchecked = rq['checkedSem'] == 'unchecked' unchecked = rq['checkedSem'] == 'unchecked'
uids = {} objects = []
tool = obj.tool
for uid in getattr(obj.o.aq_base, self.getChecked, ()): for uid in getattr(obj.o.aq_base, self.getChecked, ()):
if unchecked: condition = uid not in reqUids if unchecked: condition = uid not in reqUids
else: condition = uid in reqUids else: condition = uid in reqUids
if condition: uids[uid] = None if condition:
tied = tool.getObject(uid)
if tied.allows('read'): objects.append(tied)
res['_checked'] = Object() res['_checked'] = Object()
setattr(res['_checked'], self.getChecked, uids) setattr(res['_checked'], self.getChecked, objects)
return res return res
def onUiRequest(self, obj, rq): def onUiRequest(self, obj, rq):