Changeset 16228 for main/waeup.kofa/trunk/src/waeup/kofa/applicants
- Timestamp:
- 7 Sep 2020, 12:28:14 (4 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa/applicants
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/applicants/applicant.py
r16016 r16228 68 68 ] 69 69 70 applicant_graduated_mapping = [ 71 ('firstname', 'firstname'), 72 ('middlename', 'middlename'), 73 ('lastname', 'lastname'), 74 ('sex', 'sex'), 75 ('date_of_birth', 'date_of_birth'), 76 ('email', 'email'), 77 ('phone', 'phone'), 78 ] 79 70 80 def __init__(self): 71 81 super(Applicant, self).__init__() … … 152 162 return 153 163 154 def createStudent(self, view=None): 164 def _setGraduatedStudyCourseAttributes(self, studycourse): 165 studycourse.entry_mode = self.course_studied.study_mode 166 studycourse.current_level = self.course_studied.start_level 167 studycourse.certificate = self.course_studied 168 studycourse.entry_session = self.__parent__.year 169 studycourse.current_session = self.__parent__.year 170 return 171 172 def createStudent(self, view=None, graduated=False): 155 173 """Create a student, fill with base data, create an application slip, 156 174 copy applicant data and files. … … 158 176 site = grok.getSite() 159 177 # Is applicant in the correct state? 160 if self.state != 'admitted': 161 return False, _('Applicant has not yet been admitted.') 178 if graduated: 179 if self.state != 'processed': 180 return False, _('Applicant has not yet been processed.') 181 certificate = getattr(self, 'course_studied', None) 182 mapping = self.applicant_graduated_mapping 183 else: 184 if self.state != 'admitted': 185 return False, _('Applicant has not yet been admitted.') 186 certificate = getattr(self, 'course_admitted', None) 187 mapping = self.applicant_student_mapping 162 188 # Does registration number exist? 163 189 student = createObject(u'waeup.Student') … … 168 194 site['students']._curr_stud_id -= 1 169 195 return False, _('Registration Number exists.') 170 # Has the course_admitted field been properly filled?171 if self.course_admittedis None:196 # Has the course_admitted/course_studied field been properly filled? 197 if certificate is None: 172 198 # Reset _curr_stud_id 173 199 site['students']._curr_stud_id -= 1 174 return False, _('No course admittedprovided.')200 return False, _('No study course provided.') 175 201 # Set student attributes 176 202 try: 177 for item in self.applicant_student_mapping:203 for item in mapping: 178 204 setattr(student, item[1], getattr(self, item[0], None)) 179 205 except RequiredMissing, err: … … 185 211 # Prove if the certificate still exists 186 212 try: 187 StudentStudyCourse().certificate = self.course_admitted213 StudentStudyCourse().certificate = certificate 188 214 except ConstraintNotSatisfied, err: 189 215 # Reset _curr_stud_id 190 216 site['students']._curr_stud_id -= 1 191 return False, 'ConstraintNotSatisfied: %s' % self.course_admitted.code217 return False, 'ConstraintNotSatisfied: %s' % certificate.code 192 218 # Finally prove if an application slip can be created 193 219 try: … … 210 236 # Save student_id 211 237 self.student_id = student.student_id 212 # Fire transitions 213 IWorkflowInfo(self).fireTransition('create') 214 IWorkflowInfo(student).fireTransition('admit') 238 if graduated: 239 # Set state 240 IWorkflowState(student).setState('graduated') 241 # Save the certificate and set study course attributes 242 self._setGraduatedStudyCourseAttributes(student['studycourse']) 243 else: 244 # Fire transitions 245 IWorkflowInfo(self).fireTransition('create') 246 IWorkflowInfo(student).fireTransition('admit') 247 # Save the certificate and set study course attributes 248 self._setStudyCourseAttributes(student['studycourse']) 215 249 # Set password 216 250 IUserAccount(student).setPassword(self.application_number) 217 # Save the certificate and set study course attributes218 self._setStudyCourseAttributes(student['studycourse'])219 251 self._copyPassportImage(student) 220 252 self._copyFiles(student) -
main/waeup.kofa/trunk/src/waeup/kofa/applicants/interfaces.py
r16215 r16228 491 491 """ 492 492 493 def createStudent( ):493 def createStudent(view, graduated): 494 494 """Create a student object from applicant data and copy 495 passport image and application slip. 496 """ 497 495 passport image and application slip. If graduated is set True, 496 a graduated student is being created. This method is supposed 497 to be used for transcript applicants. It is tested but not 498 used in the base package. 499 """ 498 500 class ISpecialApplicant(IKofaObject): 499 501 """This reduced interface is for former students or students who are not -
main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_applicantcopier.py
r15941 r16228 56 56 return 57 57 58 def test_ copier(self):58 def test_applicant_student_copier(self): 59 59 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') 60 60 self.prepare_applicant() … … 80 80 # Current student_id has not changed. 81 81 self.assertEqual(self.app['students']._curr_stud_id, 1000000) 82 self.assertTrue(msg == 'No course admittedprovided.')82 self.assertTrue(msg == 'No study course provided.') 83 83 self.browser.open(self.manage_path) 84 84 self.browser.getControl(name="form.course_admitted").value = ['CERT1'] … … 158 158 self.assertEqual(student['studycourse'].current_level, 100) 159 159 160 def test_applicant_graduated_copier(self): 161 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') 162 self.prepare_applicant() 163 storage = getUtility(IExtFileStore) 164 # The stored image can be fetched 165 file_id = IFileStoreNameChooser(self.applicant).chooseName() 166 fd = storage.getFile(file_id) 167 file_len_orig = len(fd.read()) 168 # We store a test pdf file 169 dummy_file = StringIO('test file') 170 testfile_id = IFileStoreNameChooser( 171 self.applicant).chooseName(attr='testfile.pdf') 172 test_file = storage.createFile(testfile_id, dummy_file) 173 # The stored file can be fetched 174 fd = storage.getFile(testfile_id) 175 testfile_len_orig = len(fd.read()) 176 self.assertEqual(self.app['students']._curr_stud_id, 1000000) 177 # Let's try to create the student 178 (success, msg) = self.applicant.createStudent(graduated=True) 179 self.assertTrue(msg == 'Applicant has not yet been processed.') 180 IWorkflowState(self.applicant).setState('processed') 181 (success, msg) = self.applicant.createStudent(graduated=True) 182 # Current student_id has not changed. 183 self.assertEqual(self.app['students']._curr_stud_id, 1000000) 184 self.assertTrue(msg == 'No study course provided.') 185 # The course_studied field is not used in the base package. Thus we 186 # have to set the attribute manually. 187 self.applicant.course_studied = self.certificate 188 self.browser.open(self.manage_path) 189 self.browser.getControl("Save").click() 190 # Maybe the certificate has meanwhile been removed 191 del self.app['faculties']['fac1']['dep1'].certificates['CERT1'] 192 (success, msg) = self.applicant.createStudent(graduated=True) 193 self.assertFalse(success) 194 self.assertTrue('ConstraintNotSatisfied: CERT1' in msg) 195 # Current student_id has not changed. 196 self.assertEqual(self.app['students']._curr_stud_id, 1000000) 197 # Ok, lets add the certificate and try again 198 self.app['faculties']['fac1']['dep1'].certificates.addCertificate( 199 self.certificate) 200 # Managers are not allowed to trigger the create transition manually 201 self.assertFalse('<option value="create">' in self.browser.contents) 202 # Graduated student can be created 203 (success, msg) = self.applicant.createStudent(graduated=True) 204 self.assertTrue('created' in msg) 205 # Current student_id has not changed. 206 self.assertEqual(self.app['students']._curr_stud_id, 1000001) 207 student_id = translate(msg, 'waeup.kofa').split()[1] 208 # View student container just created 209 student = self.app['students'][student_id] 210 student_path = 'http://localhost/app/students/%s' % student_id 211 self.browser.open(student_path) 212 self.assertEqual(self.browser.headers['Status'], '200 Ok') 213 self.assertEqual(self.browser.url, student_path) 214 # Student is in state graduated 215 self.assertEqual(student.state, 'graduated') 216 # Attributes properly set? 217 self.assertEqual(student.email, 'xx@yy.zz') 218 self.assertEqual(student.firstname, 'John') 219 self.assertEqual(student.middlename, 'Anthony') 220 self.assertEqual(student.lastname, 'Tester') 221 # student_id set in application record? 222 self.assertEqual(self.applicant.student_id, student.student_id) 223 # Check if passport image has been copied 224 file_id = IFileStoreNameChooser(student).chooseName(attr='passport.jpg') 225 fd = storage.getFile(file_id) 226 file_len = len(fd.read()) 227 self.assertEqual(file_len_orig, file_len) 228 # Check if test file has been copied too (new) 229 file_id = IFileStoreNameChooser(student).chooseName(attr='testfile.jpg') 230 fd = storage.getFile(file_id) 231 file_len = len(fd.read()) 232 self.assertEqual(testfile_len_orig, file_len) 233 # Check if application slip exists and is a PDF file 234 file_id = IFileStoreNameChooser( 235 student).chooseName(attr='application_slip.pdf') 236 pdf = storage.getFile(file_id).read() 237 self.assertTrue(len(pdf) > 0) 238 self.assertEqual(pdf[:8], '%PDF-1.4') 239 path = os.path.join(samples_dir(), 'application_slip.pdf') 240 open(path, 'wb').write(pdf) 241 print "Sample PDF application_slip.pdf written to %s" % path 242 # Check if there is an application slip link in UI 243 self.assertTrue('Application Slip' in self.browser.contents) 244 self.browser.getLink("Application Slip").click() 245 self.assertEqual(self.browser.headers['Status'], '200 Ok') 246 self.assertEqual(self.browser.headers['Content-Type'], 247 'application/pdf') 248 # Has the student been properly indexed? 249 # Yes, we can find the student in department 250 self.browser.open('http://localhost/app/students') 251 self.browser.getControl(name="searchtype").value = ['depcode'] 252 self.browser.getControl(name="searchterm").value = 'dep1' 253 self.browser.getControl("Find student(s)").click() 254 self.assertMatches('...John Anthony Tester...', self.browser.contents) 255 # Has the student studycourse the correct attributes? 256 self.assertEqual(student['studycourse'].certificate.code, 'CERT1') 257 self.assertEqual(student['studycourse'].entry_session, session) 258 self.assertEqual(student['studycourse'].entry_mode, 'ug_ft') 259 self.assertEqual(student['studycourse'].current_session, session) 260 self.assertEqual(student['studycourse'].current_level, 100) 261 160 262 def test_batch_copying(self): 161 263 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') … … 184 286 notify(grok.ObjectModifiedEvent(self.applicant)) 185 287 self.browser.open(self.container_path + '/createallstudents') 186 self.assertTrue('No course admittedprovided' in self.browser.contents)288 self.assertTrue('No study course provided' in self.browser.contents) 187 289 self.assertFalse('Successfully created records' in self.browser.contents) 188 290 self.assertTrue('Failed records' in self.browser.contents) … … 215 317 notify(grok.ObjectModifiedEvent(self.applicant)) 216 318 self.browser.open(self.root_path + '/createallstudents') 217 self.assertTrue('No course admittedprovided' in self.browser.contents)319 self.assertTrue('No study course provided' in self.browser.contents) 218 320 self.applicant.course_admitted = self.certificate 219 321 self.browser.open(self.root_path + '/createallstudents')
Note: See TracChangeset for help on using the changeset viewer.