Changeset 12395 for main/waeup.kofa/trunk/src
- Timestamp:
- 4 Jan 2015, 17:19:06 (10 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa/applicants
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/applicants/applicant.py
r12394 r12395 144 144 except: 145 145 return False, 'Unknown Error' 146 # Finally prove if the certificate still exists146 # Prove if the certificate still exists 147 147 try: 148 148 StudentStudyCourse().certificate = self.course_admitted 149 149 except ConstraintNotSatisfied, err: 150 150 return False, 'ConstraintNotSatisfied: %s' % self.course_admitted.code 151 # Finally prove if an application slip can be created 152 try: 153 applicant_slip = getAdapter(self, IPDF, name='application_slip')( 154 view=view) 155 except IOError: 156 return False, _('IOError: Application Slip could not be created.') 151 157 # Add student 152 158 site = grok.getSite() … … 165 171 notify(grok.ObjectModifiedEvent(student)) 166 172 # Save application slip 167 try: 168 self._createApplicationPDF(student, view=view) 169 return True, _('Student ${a} created', mapping = {'a':student.student_id}) 170 except IOError: 171 return False, _('IOError: Application Slip could not be created.') 172 173 def _createApplicationPDF(self, student, view=None): 173 self._saveApplicationPDF(student, applicant_slip, view=view) 174 return True, _('Student ${a} created', mapping = {'a':student.student_id}) 175 176 def _saveApplicationPDF(self, student, applicant_slip, view=None): 174 177 """Create an application slip as PDF and store it in student folder. 175 178 """ 176 179 file_store = getUtility(IExtFileStore) 177 applicant_slip = getAdapter(self, IPDF, name='application_slip')(178 view=view)179 180 file_id = IFileStoreNameChooser(student).chooseName( 180 181 attr="application_slip.pdf") -
main/waeup.kofa/trunk/src/waeup/kofa/applicants/browser.py
r12247 r12395 764 764 765 765 def render(self): 766 pdfstream = getAdapter(self.context, IPDF, name='application_slip')( 767 view=self) 766 try: 767 pdfstream = getAdapter(self.context, IPDF, name='application_slip')( 768 view=self) 769 except IOError: 770 self.flash( 771 _('Your image file is corrupted. ' 772 'Please replace.'), type='danger') 773 return self.redirect(self.url(self.context)) 768 774 self.response.setHeader( 769 775 'Content-Type', 'application/pdf') -
main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_applicantcopier.py
r11482 r12395 202 202 (success, msg) = self.applicant.createStudent() 203 203 self.assertTrue('created' in msg) 204 205 def test_copier_with_defective_passport_image(self): 206 IWorkflowState(self.applicant).setState('admitted') 207 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') 208 self.browser.open(self.manage_path) 209 self.fill_correct_values() 210 self.browser.getControl("Save").click() 211 # Upload a passport picture 212 ctrl = self.browser.getControl(name='form.passport') 213 # This file has really been uploaded by KwaraPoly student 214 # Until 4/1/15 these files resulted a traceback when opening 215 # the createallstudents page. The traceback is now catched. 216 file_obj = open( 217 os.path.join(os.path.dirname(__file__), 'fake_image.jpg'),'rb') 218 file_ctrl = ctrl.mech_control 219 file_ctrl.add_file(file_obj, filename='my_photo.jpg') 220 self.browser.getControl(name="form.course_admitted").value = ['CERT1'] 221 self.browser.getControl("Save").click() # submit form 222 (success, msg) = self.applicant.createStudent() 223 self.assertTrue(msg == 'IOError: Application Slip could not be created.') 224 # The same in the UI 225 self.browser.open(self.manage_container_path) 226 ctrl = self.browser.getControl(name='val_id') 227 ctrl.getControl(value=self.applicant.application_number).selected = True 228 self.browser.getControl("Create students from selected", index=0).click() 229 self.assertTrue('No student could be created.' in self.browser.contents) 230 self.browser.open(self.container_path + '/createallstudents') 231 self.assertTrue('No student could be created' in self.browser.contents) 232 logfile = os.path.join(self.app['datacenter'].storage, 'logs', 'applicants.log') 233 logcontent = open(logfile).read() 234 self.assertTrue('IOError: Application Slip could not be created.' in logcontent) -
main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_browser.py
r11738 r12395 781 781 in logcontent) 782 782 783 def test_application_slip_with_non_jpg_image(self): 784 IWorkflowState(self.applicant).setState('submitted') 785 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') 786 self.browser.open(self.manage_path) 787 # Create a pseudo image file and select it to be uploaded in form 788 photo_content = 'A' * 1024 * 5 # A string of 5 KB size 789 pseudo_image = StringIO(photo_content) 790 ctrl = self.browser.getControl(name='form.passport') 791 file_ctrl = ctrl.mech_control 792 file_ctrl.add_file(pseudo_image, filename='myphoto.jpg') 793 self.browser.getControl("Save").click() # submit form 794 self.browser.open(self.manage_path) 795 self.browser.getLink("Download application slip").click() 796 self.assertEqual(self.browser.headers['Status'], '200 Ok') 797 self.assertMatches( 798 '...Your image file is corrupted. Please replace...', 799 self.browser.contents) 800 783 801 def test_pay_portal_application_fee(self): 784 802 self.login()
Note: See TracChangeset for help on using the changeset viewer.