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,
|
||||
custom_store=None,
|
||||
custom_retrieve=None,
|
||||
custom_retrieve_fileproperties=None,
|
||||
custom_delete=None,
|
||||
):
|
||||
self.db = None
|
||||
@@ -7562,6 +7563,7 @@ class Field(Expression):
|
||||
self.isattachment = True
|
||||
self.custom_store = custom_store
|
||||
self.custom_retrieve = custom_retrieve
|
||||
self.custom_retrieve_fileproperties = custom_retrieve_fileproperties
|
||||
self.custom_delete = custom_delete
|
||||
if self.label is None:
|
||||
self.label = fieldname.replace('_',' ').title()
|
||||
@@ -7624,14 +7626,11 @@ class Field(Expression):
|
||||
raise http.HTTP(404)
|
||||
if self.authorize and not self.authorize(row):
|
||||
raise http.HTTP(403)
|
||||
try:
|
||||
m = regex_content.match(name)
|
||||
if not m or not self.isattachment:
|
||||
raise TypeError, 'Can\'t retrieve %s' % name
|
||||
filename = base64.b16decode(m.group('name'), True)
|
||||
filename = regex_cleanup_fn.sub('_', filename)
|
||||
except (TypeError, AttributeError):
|
||||
filename = name
|
||||
m = regex_content.match(name)
|
||||
if not m or not self.isattachment:
|
||||
raise TypeError, 'Can\'t retrieve %s' % name
|
||||
fileproperties = self.retrieve_fileproperties(name,path)
|
||||
filename = fileproperties['filename']
|
||||
if isinstance(self.uploadfield, str): # ## if file is in DB
|
||||
return (filename, cStringIO.StringIO(row[self.uploadfield] or ''))
|
||||
elif isinstance(self.uploadfield,Field):
|
||||
@@ -7639,6 +7638,25 @@ class Field(Expression):
|
||||
query = self.uploadfield == name
|
||||
data = self.uploadfield.table(query)[blob_uploadfield_name]
|
||||
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:
|
||||
# ## if file is on filesystem
|
||||
if path:
|
||||
@@ -7652,7 +7670,8 @@ class Field(Expression):
|
||||
f = m.group('field')
|
||||
u = m.group('uuidkey')
|
||||
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):
|
||||
if value is None or not self.requires:
|
||||
|
||||
Reference in New Issue
Block a user