- Timestamp:
- 18 Jan 2010, 09:06:22 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
waeup/branches/ulif-importers/src/waeup/browser/pages.py
r4848 r4852 6 6 import grok 7 7 import os 8 import re 8 9 import sys 9 10 from hurry import yui … … 270 271 try: 271 272 filename = uploadfile.filename 272 target = os.path.join(self.context.storage, filename) 273 target = os.path.join(self.context.storage, 274 self.getNormalizedFileName(filename)) 273 275 open(target, 'wb').write(uploadfile.read()) 274 276 except IOError: … … 278 280 self.redirect(self.url(self.context)) 279 281 282 def getNormalizedFileName(self, filename): 283 """Build sane filename. 284 285 An uploaded file foo.csv will be stored as foo_USERNAME.csv 286 where username is the principal id of the currently logged in 287 user. 288 289 Spaces in filename are replaced by underscore. 290 """ 291 username = self.request.principal.id 292 filename = filename.replace(' ', '_') 293 # Only accept typical filname chars... 294 filtered_username = ''.join(re.findall('[a-zA-Z0-9_\.\-]', username)) 295 base, ext = os.path.splitext(filename) 296 return '%s_%s%s' % (base, filtered_username, ext.lower()) 280 297 281 298 class DataCenterImportCSVPage(WAeUPPage):
Note: See TracChangeset for help on using the changeset viewer.