Changeset 7111
- Timestamp:
- 14 Nov 2011, 12:17:54 (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/browser_templates/fileupload.pt
r7108 r7111 13 13 LINK 14 14 </a> 15 <input type="submit" id="delete" 16 name="delete" value="Delete" class="button" /> 17 <br /><br /> 15 <input type="submit" 16 tal:attributes="id python:('delete_%s' % viewlet.input_name); 17 name python:('delete_%s' % viewlet.input_name)" 18 value="Delete" class="button" /> 19 <br /> 18 20 </tal:file> 19 21 <input type="file" tal:attributes="name viewlet/input_name"/> 20 <input type="submit" id="upload" 21 name="upload" value="Upload" class="button" /> 22 <input type="submit" 23 tal:attributes="id python:('upload_%s' % viewlet.input_name); 24 name python:('upload_%s' % viewlet.input_name)" 25 value="Upload" class="button" /> 22 26 <br /> 23 27 <span i18n:translate=""> -
main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_browser.py
r7110 r7111 374 374 ctrl = self.browser.getControl(name='birth_certificate') 375 375 file_ctrl = ctrl.mech_control 376 file_ctrl.add_file(pseudo_image, filename='my photo.jpg')376 file_ctrl.add_file(pseudo_image, filename='my_birth_certificate.jpg') 377 377 # The Save action does not upload files 378 378 self.browser.getControl("Save (no upload)").click() # submit form … … 380 380 '<a target="image" href="birth_certificate.jpg">' 381 381 in self.browser.contents) 382 # ... but the Upload submit button does382 # ... but the correct upload submit button does 383 383 pseudo_image = StringIO('I pretend to be a graphics file') 384 384 ctrl = self.browser.getControl(name='birth_certificate') 385 385 file_ctrl = ctrl.mech_control 386 file_ctrl.add_file(pseudo_image, filename='my photo.jpg')387 self.browser.getControl( "Upload").click()386 file_ctrl.add_file(pseudo_image, filename='my_birth_certificate.jpg') 387 self.browser.getControl(name='upload_birth_certificate').click() 388 388 # There is a correct <img> link included 389 389 self.assertTrue( … … 401 401 ctrl = self.browser.getControl(name='birth_certificate') 402 402 file_ctrl = ctrl.mech_control 403 file_ctrl.add_file(pseudo_image, filename='my photo.jpg')404 self.browser.getControl( "Upload").click()403 file_ctrl.add_file(pseudo_image, filename='my_birth_certificate.jpg') 404 self.browser.getControl(name='upload_birth_certificate').click() 405 405 self.assertTrue( 406 406 'Uploaded file is too big' in self.browser.contents) … … 410 410 file_ctrl = ctrl.mech_control 411 411 file_ctrl.add_file(pseudo_image, filename='my.photo.jpg') 412 self.browser.getControl( "Upload").click()412 self.browser.getControl(name='upload_birth_certificate').click() 413 413 self.assertTrue('File name contains more than one dot' 414 414 in self.browser.contents) 415 415 ctrl = self.browser.getControl(name='birth_certificate') 416 416 file_ctrl = ctrl.mech_control 417 file_ctrl.add_file(pseudo_image, filename='my photo')418 self.browser.getControl( "Upload").click()417 file_ctrl.add_file(pseudo_image, filename='my_birth_certificate') 418 self.browser.getControl(name='upload_birth_certificate').click() 419 419 self.assertTrue('File name has no extension' in self.browser.contents) 420 420 ctrl = self.browser.getControl(name='birth_certificate') 421 421 file_ctrl = ctrl.mech_control 422 file_ctrl.add_file(pseudo_image, filename='my photo.bmp')423 self.browser.getControl( "Upload").click()422 file_ctrl.add_file(pseudo_image, filename='my_birth_certificate.bmp') 423 self.browser.getControl(name='upload_birth_certificate').click() 424 424 self.assertTrue('.jpg file extension expected' in self.browser.contents) 425 425 # Managers can delete files 426 self.browser.getControl( "Delete").click()426 self.browser.getControl(name='delete_birth_certificate').click() 427 427 self.assertTrue( 428 428 'File birth_certificate.jpg deleted' 429 in self.browser.contents) 430 # Managers can add and delete second file 431 self.browser.open(self.edit_clearance_student_path) 432 pseudo_image = StringIO('I pretend to be a graphics file') 433 ctrl = self.browser.getControl(name='birth_certificate') 434 file_ctrl = ctrl.mech_control 435 file_ctrl.add_file(pseudo_image, filename='my_acceptance_letter.jpg') 436 self.browser.getControl(name='upload_acceptance_letter').click() 437 self.assertFalse( 438 '<a target="image" href="acceptance_letter.jpg">' 439 in self.browser.contents) 440 ctrl = self.browser.getControl(name='acceptance_letter') 441 file_ctrl = ctrl.mech_control 442 file_ctrl.add_file(pseudo_image, filename='my_acceptance_letter.jpg') 443 self.browser.getControl(name='upload_acceptance_letter').click() 444 self.assertTrue( 445 '<a target="image" href="acceptance_letter.jpg">' 446 in self.browser.contents) 447 self.browser.getControl(name='delete_acceptance_letter').click() 448 self.assertTrue( 449 'File acceptance_letter.jpg deleted' 429 450 in self.browser.contents) 430 451 -
main/waeup.sirp/trunk/src/waeup/sirp/students/viewlets.py
r7110 r7111 278 278 def update(self): 279 279 self.max_upload_size = string_from_bytes(self.mus) 280 delete_button = self.request.form.get('delete', None) 280 delete_button = self.request.form.get('delete_%s' % self.input_name, None) 281 upload_button = self.request.form.get('upload_%s' % self.input_name, None) 281 282 if delete_button: 282 283 handle_file_delete( … … 286 287 self.view.url(self.context, self.view.__name__)) 287 288 return 288 upload_button = self.request.form.get('upload', None)289 289 if upload_button: 290 290 upload = self.request.form.get(self.input_name, None) 291 291 if upload: 292 292 # We got a fresh upload 293 file_changed = handle_file_upload( 294 upload, self.context, self.view, self.mus, self.download_name) 295 if file_changed is False: # False is not None! 296 self.view.redirect( 297 self.view.url(self.context, self.view.__name__)) 298 return # error during file upload. Ignore other values 293 handle_file_upload(upload, 294 self.context, self.view, self.mus, self.download_name) 295 self.view.redirect( 296 self.view.url(self.context, self.view.__name__)) 299 297 return 300 298 … … 314 312 download_name = u'birth_certificate.jpg' 315 313 input_name = u'birth_certificate' 314 315 class AcceptanceLetterDisplay(FileDisplay): 316 """Acceptance Letter upload viewlet. 317 """ 318 grok.order(1) 319 label = u'Acceptance Letter:' 320 download_name = u'acceptance_letter.jpg' 321 322 class AcceptanceLetterUpload(FileUpload): 323 """AcceptanceLetter upload viewlet. 324 """ 325 grok.order(1) 326 label = u'Acceptance Letter (jpg only):' 327 mus = 1024 * 150 328 download_name = u'acceptance_letter.jpg' 329 input_name = u'acceptance_letter' 316 330 317 331 class Image(grok.View): … … 338 352 339 353 class BirthCertificateImage(Image): 340 """Renders birth certificate jpeg image.354 """Renders birth certificate jpeg scan. 341 355 """ 342 356 grok.name('birth_certificate.jpg') 343 357 download_name = u'birth_certificate.jpg' 358 359 class AcceptanceLetterImage(Image): 360 """Renders acceptance letter jpeg scan. 361 """ 362 grok.name('acceptance_letter.jpg') 363 download_name = u'acceptance_letter.jpg'
Note: See TracChangeset for help on using the changeset viewer.