custom_retrieve_field_properties, thanks Guyris, issue 710
This commit is contained in:
@@ -1 +1 @@
|
|||||||
Version 1.99.7 (2012-03-28 21:01:13) dev
|
Version 1.99.7 (2012-03-28 21:37:42) dev
|
||||||
|
|||||||
+28
-9
@@ -7517,6 +7517,7 @@ class Field(Expression):
|
|||||||
compute=None,
|
compute=None,
|
||||||
custom_store=None,
|
custom_store=None,
|
||||||
custom_retrieve=None,
|
custom_retrieve=None,
|
||||||
|
custom_retrieve_fileproperties=None,
|
||||||
custom_delete=None,
|
custom_delete=None,
|
||||||
):
|
):
|
||||||
self.db = None
|
self.db = None
|
||||||
@@ -7562,6 +7563,7 @@ class Field(Expression):
|
|||||||
self.isattachment = True
|
self.isattachment = True
|
||||||
self.custom_store = custom_store
|
self.custom_store = custom_store
|
||||||
self.custom_retrieve = custom_retrieve
|
self.custom_retrieve = custom_retrieve
|
||||||
|
self.custom_retrieve_fileproperties = custom_retrieve_fileproperties
|
||||||
self.custom_delete = custom_delete
|
self.custom_delete = custom_delete
|
||||||
if self.label is None:
|
if self.label is None:
|
||||||
self.label = fieldname.replace('_',' ').title()
|
self.label = fieldname.replace('_',' ').title()
|
||||||
@@ -7624,14 +7626,11 @@ class Field(Expression):
|
|||||||
raise http.HTTP(404)
|
raise http.HTTP(404)
|
||||||
if self.authorize and not self.authorize(row):
|
if self.authorize and not self.authorize(row):
|
||||||
raise http.HTTP(403)
|
raise http.HTTP(403)
|
||||||
try:
|
m = regex_content.match(name)
|
||||||
m = regex_content.match(name)
|
if not m or not self.isattachment:
|
||||||
if not m or not self.isattachment:
|
raise TypeError, 'Can\'t retrieve %s' % name
|
||||||
raise TypeError, 'Can\'t retrieve %s' % name
|
fileproperties = self.retrieve_fileproperties(name,path)
|
||||||
filename = base64.b16decode(m.group('name'), True)
|
filename = fileproperties['filename']
|
||||||
filename = regex_cleanup_fn.sub('_', filename)
|
|
||||||
except (TypeError, AttributeError):
|
|
||||||
filename = name
|
|
||||||
if isinstance(self.uploadfield, str): # ## if file is in DB
|
if isinstance(self.uploadfield, str): # ## if file is in DB
|
||||||
return (filename, cStringIO.StringIO(row[self.uploadfield] or ''))
|
return (filename, cStringIO.StringIO(row[self.uploadfield] or ''))
|
||||||
elif isinstance(self.uploadfield,Field):
|
elif isinstance(self.uploadfield,Field):
|
||||||
@@ -7639,6 +7638,25 @@ class Field(Expression):
|
|||||||
query = self.uploadfield == name
|
query = self.uploadfield == name
|
||||||
data = self.uploadfield.table(query)[blob_uploadfield_name]
|
data = self.uploadfield.table(query)[blob_uploadfield_name]
|
||||||
return (filename, cStringIO.StringIO(data))
|
return (filename, cStringIO.StringIO(data))
|
||||||
|
else:
|
||||||
|
# ## if file is on filesystem
|
||||||
|
return (filename, open(os.path.join(fileproperties['path'], name), 'rb'))
|
||||||
|
|
||||||
|
def retrieve_fileproperties(self, name, path=None):
|
||||||
|
if self.custom_retrieve_fileproperties:
|
||||||
|
return self.custom_retrieve_fileproperties(name, path)
|
||||||
|
try:
|
||||||
|
m = regex_content.match(name)
|
||||||
|
if not m or not self.isattachment:
|
||||||
|
raise TypeError, 'Can\'t retrieve %s fileproperties' % name
|
||||||
|
filename = base64.b16decode(m.group('name'), True)
|
||||||
|
filename = regex_cleanup_fn.sub('_', filename)
|
||||||
|
except (TypeError, AttributeError):
|
||||||
|
filename = name
|
||||||
|
if isinstance(self.uploadfield, str): # ## if file is in DB
|
||||||
|
return dict(path=None,filename=filename)
|
||||||
|
elif isinstance(self.uploadfield,Field):
|
||||||
|
return dict(path=None,filename=filename)
|
||||||
else:
|
else:
|
||||||
# ## if file is on filesystem
|
# ## if file is on filesystem
|
||||||
if path:
|
if path:
|
||||||
@@ -7652,7 +7670,8 @@ class Field(Expression):
|
|||||||
f = m.group('field')
|
f = m.group('field')
|
||||||
u = m.group('uuidkey')
|
u = m.group('uuidkey')
|
||||||
path = os.path.join(path,"%s.%s" % (t,f),u[:2])
|
path = os.path.join(path,"%s.%s" % (t,f),u[:2])
|
||||||
return (filename, open(os.path.join(path, name), 'rb'))
|
return dict(path=path,filename=filename)
|
||||||
|
|
||||||
|
|
||||||
def formatter(self, value):
|
def formatter(self, value):
|
||||||
if value is None or not self.requires:
|
if value is None or not self.requires:
|
||||||
|
|||||||
Reference in New Issue
Block a user