simplified upload logic
This commit is contained in:
@@ -1 +1 @@
|
|||||||
Version 2.6.0-development+timestamp.2013.08.08.03.23.58
|
Version 2.6.0-development+timestamp.2013.08.08.14.19.43
|
||||||
|
|||||||
+23
-26
@@ -253,7 +253,7 @@ REGEX_TYPE = re.compile('^([\w\_\:]+)')
|
|||||||
REGEX_DBNAME = re.compile('^(\w+)(\:\w+)*')
|
REGEX_DBNAME = re.compile('^(\w+)(\:\w+)*')
|
||||||
REGEX_W = re.compile('^\w+$')
|
REGEX_W = re.compile('^\w+$')
|
||||||
REGEX_TABLE_DOT_FIELD = re.compile('^(\w+)\.(\w+)$')
|
REGEX_TABLE_DOT_FIELD = re.compile('^(\w+)\.(\w+)$')
|
||||||
REGEX_UPLOAD_PATTERN = re.compile('(?P<table>[\w\-]+)\.(?P<field>[\w\-]+)\.(?P<uuidkey>[\w\-]+)\.(?P<name>\w+)\.\w+$')
|
REGEX_UPLOAD_PATTERN = re.compile('(?P<table>[\w\-]+)\.(?P<field>[\w\-]+)\.(?P<uuidkey>[\w\-]+)(\.(?P<name>\w+))?\.\w+$')
|
||||||
REGEX_CLEANUP_FN = re.compile('[\'"\s;]+')
|
REGEX_CLEANUP_FN = re.compile('[\'"\s;]+')
|
||||||
REGEX_UNPACK = re.compile('(?<!\|)\|(?!\|)')
|
REGEX_UNPACK = re.compile('(?<!\|)\|(?!\|)')
|
||||||
REGEX_PYTHON_KEYWORDS = re.compile('^(and|del|from|not|while|as|elif|global|or|with|assert|else|if|pass|yield|break|except|import|print|class|exec|in|raise|continue|finally|is|return|def|for|lambda|try)$')
|
REGEX_PYTHON_KEYWORDS = re.compile('^(and|del|from|not|while|as|elif|global|or|with|assert|else|if|pass|yield|break|except|import|print|class|exec|in|raise|continue|finally|is|return|def|for|lambda|try)$')
|
||||||
@@ -9442,9 +9442,6 @@ 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)
|
||||||
m = REGEX_UPLOAD_PATTERN.match(name)
|
|
||||||
if not m or not self.isattachment:
|
|
||||||
raise TypeError('Can\'t retrieve %s' % name)
|
|
||||||
file_properties = self.retrieve_file_properties(name,path)
|
file_properties = self.retrieve_file_properties(name,path)
|
||||||
filename = file_properties['filename']
|
filename = file_properties['filename']
|
||||||
if isinstance(self_uploadfield, str): # ## if file is in DB
|
if isinstance(self_uploadfield, str): # ## if file is in DB
|
||||||
@@ -9468,35 +9465,35 @@ class Field(Expression):
|
|||||||
return (filename, stream)
|
return (filename, stream)
|
||||||
|
|
||||||
def retrieve_file_properties(self, name, path=None):
|
def retrieve_file_properties(self, name, path=None):
|
||||||
|
m = REGEX_UPLOAD_PATTERN.match(name)
|
||||||
|
if not m or not self.isattachment:
|
||||||
|
raise TypeError('Can\'t retrieve %s file properties' % name)
|
||||||
self_uploadfield = self.uploadfield
|
self_uploadfield = self.uploadfield
|
||||||
if self.custom_retrieve_file_properties:
|
if self.custom_retrieve_file_properties:
|
||||||
return self.custom_retrieve_file_properties(name, path)
|
return self.custom_retrieve_file_properties(name, path)
|
||||||
try:
|
if m.group('name'):
|
||||||
m = REGEX_UPLOAD_PATTERN.match(name)
|
try:
|
||||||
if not m or not self.isattachment:
|
filename = base64.b16decode(m.group('name'), True)
|
||||||
raise TypeError('Can\'t retrieve %s file properties' % name)
|
filename = REGEX_CLEANUP_FN.sub('_', filename)
|
||||||
filename = base64.b16decode(m.group('name'), True)
|
except (TypeError, AttributeError):
|
||||||
filename = REGEX_CLEANUP_FN.sub('_', filename)
|
filename = name
|
||||||
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
|
filename = name
|
||||||
if path:
|
# ## if file is in DB
|
||||||
pass
|
if isinstance(self_uploadfield, (str, Field)):
|
||||||
elif self.uploadfolder:
|
return dict(path=None,filename=filename)
|
||||||
|
# ## if file is on filesystem
|
||||||
|
if not path:
|
||||||
|
if self.uploadfolder:
|
||||||
path = self.uploadfolder
|
path = self.uploadfolder
|
||||||
else:
|
else:
|
||||||
path = pjoin(self.db._adapter.folder, '..', 'uploads')
|
path = pjoin(self.db._adapter.folder, '..', 'uploads')
|
||||||
if self.uploadseparate:
|
if self.uploadseparate:
|
||||||
t = m.group('table')
|
t = m.group('table')
|
||||||
f = m.group('field')
|
f = m.group('field')
|
||||||
u = m.group('uuidkey')
|
u = m.group('uuidkey')
|
||||||
path = pjoin(path,"%s.%s" % (t,f),u[:2])
|
path = pjoin(path,"%s.%s" % (t,f),u[:2])
|
||||||
return dict(path=path,filename=filename)
|
return dict(path=path,filename=filename)
|
||||||
|
|
||||||
|
|
||||||
def formatter(self, value):
|
def formatter(self, value):
|
||||||
|
|||||||
Reference in New Issue
Block a user