Changeset 7105 for main/waeup.sirp/trunk/src
- Timestamp:
- 13 Nov 2011, 17:50:26 (13 years ago)
- Location:
- main/waeup.sirp/trunk/src/waeup/sirp
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/applicants/applicant.py
r7103 r7105 146 146 return name == self.chooseName() 147 147 148 def chooseName(self, name=None, attr=None , ext=None):148 def chooseName(self, name=None, attr=None): 149 149 """Get a valid file id for applicant context. 150 150 -
main/waeup.sirp/trunk/src/waeup/sirp/imagestorage.py
r7103 r7105 223 223 return False 224 224 225 def chooseName(self, name, attr=None , ext=None):225 def chooseName(self, name, attr=None): 226 226 """Choose a unique valid file id for the object. 227 227 … … 233 233 234 234 For this default name chooser we return the given name if it 235 is valid or ``unknown_file`` else. The `attr` and the `ext` params236 are nottaken into account here.235 is valid or ``unknown_file`` else. The `attr` param is not 236 taken into account here. 237 237 """ 238 238 if self.checkName(name): … … 344 344 return fd 345 345 346 def getFileByContext(self, context, attr=None , ext=None):346 def getFileByContext(self, context, attr=None): 347 347 """Get a file for given context. 348 348 … … 355 355 id for the context and `attr` given. 356 356 357 `context`, `attr` and `ext` are used to find (`context`)357 Both, `context` and `attr` are used to find (`context`) 358 358 and feed (`attr`) an appropriate file name chooser. 359 359 … … 364 364 :class:`DefaultFileStoreHandler`. 365 365 """ 366 file_id = IFileStoreNameChooser(context).chooseName(attr=attr , ext=ext)366 file_id = IFileStoreNameChooser(context).chooseName(attr=attr) 367 367 return self.getFile(file_id) 368 368 … … 378 378 return 379 379 380 def deleteFileByContext(self, context, attr=None , ext=None):380 def deleteFileByContext(self, context, attr=None): 381 381 """Remove file identified by `context` and `attr` if it exists. 382 382 … … 385 385 id for the context and `attr` given. 386 386 387 `context`, `attr` and `ext` are used to find (`context`)387 Both, `context` and `attr` are used to find (`context`) 388 388 and feed (`attr`) an appropriate file name chooser. 389 389 … … 395 395 396 396 """ 397 file_id = IFileStoreNameChooser(context).chooseName(attr=attr , ext=ext)397 file_id = IFileStoreNameChooser(context).chooseName(attr=attr) 398 398 return self.deleteFile(file_id) 399 399 -
main/waeup.sirp/trunk/src/waeup/sirp/students/student.py
r7103 r7105 177 177 return name == self.chooseName() 178 178 179 def chooseName(self, name=None, attr=None , ext=u''):179 def chooseName(self, name=None, attr=None): 180 180 """Get a valid file id for student context. 181 181 182 182 *Example:* 183 183 184 For a student with student id ``'A123456'``, 185 with attr ``'nice_image'`` and an uploaded file named 186 `'anybasename.JPG'`` to be stored in 184 For a student with student id ``'A123456'`` and 185 with attr ``'nice_image'`` stored in 187 186 the students container this chooser would create: 188 187 … … 195 194 196 195 """ 197 if name and name.count('.') == 1:198 basename, ext = os.path.splitext(name)199 ext.lower()200 196 stud_id = self.context.student_id 201 marked_filename = '__%s__%s/%s/%s_%s %s' % (202 STUDENT_FILE_STORE_NAME, stud_id[0], stud_id, attr, stud_id , ext)197 marked_filename = '__%s__%s/%s/%s_%s.jpg' % ( 198 STUDENT_FILE_STORE_NAME, stud_id[0], stud_id, attr, stud_id) 203 199 return marked_filename 204 200 -
main/waeup.sirp/trunk/src/waeup/sirp/students/viewlets.py
r7103 r7105 198 198 return self.view.application_url() + rel_link 199 199 200 def handle_ file_upload(upload, context, view, max_size, attr=None):200 def handle_img_upload(upload, context, view, max_size, attr=None): 201 201 """Handle upload of applicant image. 202 202 … … 212 212 upload.seek(0) # file pointer moved when determining size 213 213 store = getUtility(IExtFileStore) 214 file_id = IFileStoreNameChooser( 215 context).chooseName(attr=attr, name=upload.filename) 214 file_id = IFileStoreNameChooser(context).chooseName(attr=attr) 216 215 store.createFile(file_id, upload) 217 216 return True … … 253 252 if upload: 254 253 # We got a fresh upload 255 file_changed = handle_ file_upload(254 file_changed = handle_img_upload( 256 255 upload, self.context, self.view, self.mus, self.attr) 257 256 if file_changed is False: # False is not None! … … 288 287 grok.baseclass() 289 288 attr = None 290 ext = u'.jpg'291 289 292 290 def render(self): … … 294 292 # for file storage. 295 293 image = getUtility(IExtFileStore).getFileByContext( 296 self.context, attr=self.attr , ext=self.ext)294 self.context, attr=self.attr) 297 295 self.response.setHeader( 298 296 'Content-Type', 'image/jpeg') … … 307 305 grok.name('birth_certificate.jpg') 308 306 attr = u'birth_certificate' 309 ext = u'.jpg' -
main/waeup.sirp/trunk/src/waeup/sirp/tests/test_imagestorage.py
r7103 r7105 158 158 self.context = context 159 159 160 def chooseName(self, name=None, attr=None , ext=None):160 def chooseName(self, name=None, attr=None): 161 161 # this name chooser returns different file ids depending on 162 162 # the `attr` parameter, a simple string.
Note: See TracChangeset for help on using the changeset viewer.