Ignore:
Timestamp:
7 Sep 2020, 12:28:14 (4 years ago)
Author:
Henrik Bettermann
Message:

Use Applicant.createStudent method also to create graduated
students from transcript application data (not used in base package).

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  
    6868        ]
    6969
     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
    7080    def __init__(self):
    7181        super(Applicant, self).__init__()
     
    152162        return
    153163
    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):
    155173        """Create a student, fill with base data, create an application slip,
    156174        copy applicant data and files.
     
    158176        site = grok.getSite()
    159177        # 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
    162188        # Does registration number exist?
    163189        student = createObject(u'waeup.Student')
     
    168194            site['students']._curr_stud_id -= 1
    169195            return False, _('Registration Number exists.')
    170         # Has the course_admitted field been properly filled?
    171         if self.course_admitted is None:
     196        # Has the course_admitted/course_studied field been properly filled?
     197        if certificate is None:
    172198            # Reset _curr_stud_id
    173199            site['students']._curr_stud_id -= 1
    174             return False, _('No course admitted provided.')
     200            return False, _('No study course provided.')
    175201        # Set student attributes
    176202        try:
    177             for item in self.applicant_student_mapping:
     203            for item in mapping:
    178204                setattr(student, item[1], getattr(self, item[0], None))
    179205        except RequiredMissing, err:
     
    185211        # Prove if the certificate still exists
    186212        try:
    187             StudentStudyCourse().certificate = self.course_admitted
     213            StudentStudyCourse().certificate = certificate
    188214        except ConstraintNotSatisfied, err:
    189215            # Reset _curr_stud_id
    190216            site['students']._curr_stud_id -= 1
    191             return False, 'ConstraintNotSatisfied: %s' % self.course_admitted.code
     217            return False, 'ConstraintNotSatisfied: %s' % certificate.code
    192218        # Finally prove if an application slip can be created
    193219        try:
     
    210236        # Save student_id
    211237        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'])
    215249        # Set password
    216250        IUserAccount(student).setPassword(self.application_number)
    217         # Save the certificate and set study course attributes
    218         self._setStudyCourseAttributes(student['studycourse'])
    219251        self._copyPassportImage(student)
    220252        self._copyFiles(student)
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/interfaces.py

    r16215 r16228  
    491491        """
    492492
    493     def createStudent():
     493    def createStudent(view, graduated):
    494494        """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        """
    498500class ISpecialApplicant(IKofaObject):
    499501    """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  
    5656        return
    5757
    58     def test_copier(self):
     58    def test_applicant_student_copier(self):
    5959        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
    6060        self.prepare_applicant()
     
    8080        # Current student_id has not changed.
    8181        self.assertEqual(self.app['students']._curr_stud_id, 1000000)
    82         self.assertTrue(msg == 'No course admitted provided.')
     82        self.assertTrue(msg == 'No study course provided.')
    8383        self.browser.open(self.manage_path)
    8484        self.browser.getControl(name="form.course_admitted").value = ['CERT1']
     
    158158        self.assertEqual(student['studycourse'].current_level, 100)
    159159
     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
    160262    def test_batch_copying(self):
    161263        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     
    184286        notify(grok.ObjectModifiedEvent(self.applicant))
    185287        self.browser.open(self.container_path + '/createallstudents')
    186         self.assertTrue('No course admitted provided' in self.browser.contents)
     288        self.assertTrue('No study course provided' in self.browser.contents)
    187289        self.assertFalse('Successfully created records' in self.browser.contents)
    188290        self.assertTrue('Failed records' in self.browser.contents)
     
    215317        notify(grok.ObjectModifiedEvent(self.applicant))
    216318        self.browser.open(self.root_path + '/createallstudents')
    217         self.assertTrue('No course admitted provided' in self.browser.contents)
     319        self.assertTrue('No study course provided' in self.browser.contents)
    218320        self.applicant.course_admitted = self.certificate
    219321        self.browser.open(self.root_path + '/createallstudents')
Note: See TracChangeset for help on using the changeset viewer.