Changeset 7123
- Timestamp:
- 17 Nov 2011, 07:42:42 (13 years ago)
- Location:
- main/waeup.sirp/trunk/src/waeup/sirp/students
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/students/student.py
r7122 r7123 231 231 """ 232 232 ext = os.path.splitext(filename)[1].lower() 233 if ext not in ['.jpg', '.png']:234 raise ValueError('Only .jpg and .png allowed')235 233 # call super method to ensure that any old files with 236 234 # different filename extension are deleted. -
main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_browser.py
r7122 r7123 364 364 # No birth certificate has been uploaded yet 365 365 # Browsing the link shows a placerholder image 366 self.browser.open('birth_certificate .jpg')366 self.browser.open('birth_certificate') 367 367 self.assertEqual( 368 368 self.browser.headers['content-type'], 'image/jpeg') … … 378 378 self.browser.getControl("Save (no upload)").click() # submit form 379 379 self.assertFalse( 380 '<a target="image" href="birth_certificate .jpg">'380 '<a target="image" href="birth_certificate">' 381 381 in self.browser.contents) 382 382 # ... but the correct upload submit button does … … 389 389 # There is a correct <img> link included 390 390 self.assertTrue( 391 '<a target="image" href="birth_certificate .jpg">'391 '<a target="image" href="birth_certificate">' 392 392 in self.browser.contents) 393 393 394 394 # Browsing the link shows a real image 395 self.browser.open('birth_certificate .jpg')395 self.browser.open('birth_certificate') 396 396 self.assertEqual( 397 397 self.browser.headers['content-type'], 'image/jpeg') … … 428 428 self.browser.getControl( 429 429 name='upload_birthcertificateuploadmanage').click() 430 self.assertTrue('.jpg file extension expected' in self.browser.contents) 430 self.assertTrue('Only the following extension are allowed' 431 in self.browser.contents) 431 432 # Managers can delete files 432 433 self.browser.getControl(name='delete_birthcertificateuploadmanage').click() 433 434 self.assertTrue( 434 'File birth_certificate.jpg deleted' 435 in self.browser.contents) 435 'birth_certificate deleted' in self.browser.contents) 436 436 # Managers can add and delete second file 437 437 self.browser.open(self.edit_clearance_student_path) … … 443 443 name='upload_acceptanceletteruploadmanage').click() 444 444 self.assertFalse( 445 '<a target="image" href="acceptance_letter .jpg">'445 '<a target="image" href="acceptance_letter">' 446 446 in self.browser.contents) 447 447 ctrl = self.browser.getControl(name='acceptanceletteruploadmanage') … … 451 451 name='upload_acceptanceletteruploadmanage').click() 452 452 self.assertTrue( 453 '<a target="image" href="acceptance_letter .jpg">'453 '<a target="image" href="acceptance_letter">' 454 454 in self.browser.contents) 455 455 self.browser.getControl( 456 456 name='delete_acceptanceletteruploadmanage').click() 457 457 self.assertTrue( 458 'File acceptance_letter.jpg deleted' 458 'acceptance_letter deleted' 459 in self.browser.contents) 460 # Managers can upload a file via the StudentBaseManageFormPage 461 self.browser.open(self.manage_student_path) 462 pseudo_image = StringIO('I pretend to be a graphics file') 463 ctrl = self.browser.getControl(name='passportuploadmanage') 464 file_ctrl = ctrl.mech_control 465 file_ctrl.add_file(pseudo_image, filename='my_photo.bmp') 466 self.browser.getControl( 467 name='upload_passportuploadmanage').click() 468 self.assertTrue('jpg file extension expected' 469 in self.browser.contents) 470 ctrl = self.browser.getControl(name='passportuploadmanage') 471 file_ctrl = ctrl.mech_control 472 file_ctrl.add_file(pseudo_image, filename='my_photo.jpg') 473 self.browser.getControl( 474 name='upload_passportuploadmanage').click() 475 self.assertTrue( 476 '<img align="middle" height="125px" src="passport.jpg" />' 459 477 in self.browser.contents) 460 478 -
main/waeup.sirp/trunk/src/waeup/sirp/students/viewlets.py
r7117 r7123 16 16 grok.templatedir('browser_templates') 17 17 18 ALLOWED_FILE_EXTENSIONS = ('jpg', 'png', 'pdf', 'tif') 19 18 20 class StudentManageSidebar(grok.ViewletManager): 19 21 grok.name('left_studentmanage') … … 202 204 store.deleteFileByContext(context, attr=download_name) 203 205 write_log_message(view, 'deleted: %s' % download_name) 204 view.flash(' File%s deleted.' % download_name)206 view.flash('%s deleted.' % download_name) 205 207 return 206 208 … … 223 225 dummy, ext = os.path.splitext(upload.filename) 224 226 ext.lower() 225 if ext != expected_ext: 226 view.flash('%s file extension expected.' % expected_ext) 227 return False 227 if expected_ext: 228 if ext != expected_ext: 229 view.flash('%s file extension expected.' % 230 expected_ext.replace('.','')) 231 return False 232 else: 233 if not ext.replace('.','') in ALLOWED_FILE_EXTENSIONS: 234 view.flash( 235 'Only the following extension are allowed: %s' % 236 ', '.join(ALLOWED_FILE_EXTENSIONS)) 237 return False 238 download_name += ext 228 239 size = file_size(upload) 229 240 if size > max_size: … … 341 352 grok.order(1) 342 353 label = u'Birth Certificate:' 343 download_name = u'birth_certificate .jpg'354 download_name = u'birth_certificate' 344 355 345 356 class BirthCertificateUploadManage(FileUpload): … … 347 358 """ 348 359 grok.order(1) 349 label = u'Birth Certificate (jpg only):'360 label = u'Birth Certificate:' 350 361 mus = 1024 * 150 351 download_name = u'birth_certificate .jpg'362 download_name = u'birth_certificate' 352 363 353 364 class AcceptanceLetterDisplay(FileDisplay): … … 356 367 grok.order(1) 357 368 label = u'Acceptance Letter:' 358 download_name = u'acceptance_letter .jpg'369 download_name = u'acceptance_letter' 359 370 360 371 class AcceptanceLetterUploadManage(FileUpload): … … 362 373 """ 363 374 grok.order(2) 364 label = u'Acceptance Letter (jpg only):'375 label = u'Acceptance Letter:' 365 376 mus = 1024 * 150 366 download_name = u'acceptance_letter .jpg'377 download_name = u'acceptance_letter' 367 378 368 379 class BirthCertificateUploadEdit(BirthCertificateUploadManage): … … 390 401 image = getUtility(IExtFileStore).getFileByContext( 391 402 self.context, attr=self.download_name) 392 # We expect that image is a jpeg pictures393 self.response.setHeader(394 'Content-Type', 'image/jpeg')395 403 if image is None: 396 404 # show placeholder image 405 self.response.setHeader('Content-Type', 'image/jpeg') 397 406 return open(DEFAULT_IMAGE_PATH, 'rb').read() 407 dummy,ext = os.path.splitext(image.name) 408 if ext == '.jpg': 409 self.response.setHeader('Content-Type', 'image/jpeg') 410 elif ext == '.png': 411 self.response.setHeader('Content-Type', 'image/png') 412 elif ext == '.pdf': 413 self.response.setHeader('Content-Type', 'application/pdf') 414 elif ext == '.tif': 415 self.response.setHeader('Content-Type', 'image/tiff') 398 416 return image 399 417 … … 408 426 """Renders birth certificate jpeg scan. 409 427 """ 410 grok.name('birth_certificate .jpg')411 download_name = u'birth_certificate .jpg'428 grok.name('birth_certificate') 429 download_name = u'birth_certificate' 412 430 413 431 class AcceptanceLetterImage(Image): 414 432 """Renders acceptance letter jpeg scan. 415 433 """ 416 grok.name('acceptance_letter .jpg')417 download_name = u'acceptance_letter .jpg'434 grok.name('acceptance_letter') 435 download_name = u'acceptance_letter'
Note: See TracChangeset for help on using the changeset viewer.