Changeset 7108
- Timestamp:
- 14 Nov 2011, 10:01:17 (13 years ago)
- Location:
- main/waeup.sirp/trunk/src/waeup/sirp/students
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/students/browser.py
r7107 r7108 70 70 changed_fields = reduce(lambda x,y: x+y, changed_fields.values()) 71 71 fields_string = ' + '.join(changed_fields) 72 view.context._p_changed = True72 #view.context._p_changed = True 73 73 view.flash('Form has been saved.') 74 74 if fields_string: 75 write_log_message(view, 'saved: % 75 write_log_message(view, 'saved: %s' % fields_string) 76 76 return 77 77 … … 470 470 title = 'Clearance Data' 471 471 pnav = 4 472 files_changed = []473 files_deleted = []474 472 475 473 form_fields['date_of_birth'].custom_widget = FriendlyDateWidget('le-year') … … 479 477 return super(StudentClearanceManageFormPage, self).update() 480 478 481 @grok.action('Save ')479 @grok.action('Save (no upload)') 482 480 def save(self, **data): 483 481 msave(self, **data) -
main/waeup.sirp/trunk/src/waeup/sirp/students/browser_templates/fileupload.pt
r7107 r7108 8 8 <span class="widget"> 9 9 <tal:file tal:condition="viewlet/file_exists"> 10 <input type="submit" id="delete"11 name="delete" value="Delete file" class="button" />12 10 <a tal:attributes="href viewlet/download_name" 13 11 tal:content="viewlet/download_name" … … 15 13 LINK 16 14 </a> 15 <input type="submit" id="delete" 16 name="delete" value="Delete" class="button" /> 17 17 <br /><br /> 18 18 </tal:file> 19 Upload new file:<br />20 19 <input type="file" tal:attributes="name viewlet/input_name"/> 20 <input type="submit" id="upload" 21 name="upload" value="Upload" class="button" /> 21 22 <br /> 22 23 <span i18n:translate=""> -
main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_browser.py
r7106 r7108 365 365 # as birth certificate 366 366 pseudo_image = StringIO('I pretend to be a graphics file') 367 ctrl = self.browser.getControl(name=' form.birth_certificate')367 ctrl = self.browser.getControl(name='birth_certificate') 368 368 file_ctrl = ctrl.mech_control 369 369 file_ctrl.add_file(pseudo_image, filename='myphoto.jpg') 370 self.browser.getControl("Save").click() # submit form 371 # Form has errors ... 372 self.assertTrue( 373 'Required input is missing' in self.browser.contents) 374 # ... but file has been uploaded and a correct <img> link included 375 self.assertTrue( 370 # The Save action does not upload files 371 self.browser.getControl("Save (no upload)").click() # submit form 372 self.assertFalse( 376 373 '<a target="image" href="birth_certificate.jpg">' in self.browser.contents) 374 # ... but the Upload submit button 375 import pdb; pdb.set_trace() 376 ctrl = self.browser.getControl(name='birth_certificate') 377 file_ctrl = ctrl.mech_control 378 file_ctrl.add_file(pseudo_image, filename='myphoto.jpg') 379 self.browser.getControl("Upload").click() # submit form 377 380 # There is a correct <img> link included 378 381 self.assertTrue( … … 388 391 photo_content = 'A' * 1024 * 151 # A string of 21 KB size 389 392 pseudo_image = StringIO(photo_content) 390 ctrl = self.browser.getControl(name=' form.birth_certificate')393 ctrl = self.browser.getControl(name='birth_certificate') 391 394 file_ctrl = ctrl.mech_control 392 395 file_ctrl.add_file(pseudo_image, filename='myphoto.jpg') -
main/waeup.sirp/trunk/src/waeup/sirp/students/viewlets.py
r7107 r7108 8 8 from waeup.sirp.browser import DEFAULT_IMAGE_PATH 9 9 from waeup.sirp.students.browser import ( 10 StudentClearanceDisplayFormPage, StudentClearanceManageFormPage) 10 StudentClearanceDisplayFormPage, StudentClearanceManageFormPage, 11 write_log_message) 11 12 from waeup.sirp.students.interfaces import IStudentClearance 12 13 … … 205 206 store = getUtility(IExtFileStore) 206 207 store.deleteFileByContext(context, attr=download_name) 208 write_log_message(view, 'deleted: %s' % download_name) 207 209 view.flash('File %s deleted.' % download_name) 208 210 return … … 227 229 ext.lower() 228 230 if ext != expected_ext: 229 view.flash('%s extension expected.' % expected_ext)231 view.flash('%s file extension expected.' % expected_ext) 230 232 return False 231 233 size = file_size(upload) … … 237 239 file_id = IFileStoreNameChooser(context).chooseName(attr=download_name) 238 240 store.createFile(file_id, upload) 241 write_log_message(view, 'uploaded: %s (%s)' % (download_name,upload.filename)) 242 view.flash('File %s uploaded.' % download_name) 239 243 return True 240 244 … … 276 280 grok.require('waeup.manageStudents') 277 281 mus = 1024 * 150 278 input_name = u'f orm.filename'282 input_name = u'filename' 279 283 280 284 def update(self): 281 285 self.max_upload_size = string_from_bytes(self.mus) 282 delete = self.request.form.get('delete', None) 283 if delete: 284 self.view.files_deleted += self.download_name 286 delete_button = self.request.form.get('delete', None) 287 if delete_button: 285 288 handle_file_delete( 286 289 context=self.context, view=self.view, … … 289 292 self.view.url(self.context, self.view.__name__)) 290 293 return 291 upload = self.request.form.get(self.input_name, None)292 if upload :293 # We got a fresh upload294 file_changed = handle_file_upload(295 upload, self.context, self.view, self.mus, self.download_name)296 if file_changed is False: # False is not None!297 self.view.redirect(298 self.view.url(self.context, self.view.__name__))299 return # error during file upload. Ignore other values300 else:301 self.view.files_changed += self.download_name294 upload_button = self.request.form.get('upload', None) 295 if upload_button: 296 upload = self.request.form.get(self.input_name, None) 297 if upload: 298 # We got a fresh upload 299 file_changed = handle_file_upload( 300 upload, self.context, self.view, self.mus, self.download_name) 301 if file_changed is False: # False is not None! 302 self.view.redirect( 303 self.view.url(self.context, self.view.__name__)) 304 return # error during file upload. Ignore other values 302 305 return 303 306 … … 313 316 """ 314 317 grok.order(1) 315 label = u'Birth Certificate (jp eg image):'318 label = u'Birth Certificate (jpg only):' 316 319 mus = 1024 * 150 317 320 download_name = u'birth_certificate.jpg' 318 input_name = u' form.birth_certificate'321 input_name = u'birth_certificate' 319 322 320 323 class Image(grok.View):
Note: See TracChangeset for help on using the changeset viewer.