Ignore:
Timestamp:
23 Aug 2015, 10:07:31 (9 years ago)
Author:
Henrik Bettermann
Message:

Take unused records instead of creating new records during self-registration.

Location:
main/waeup.kofa/trunk/src/waeup/kofa/applicants
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/browser.py

    r13177 r13215  
    11501150            return
    11511151        if self.context.mode == 'create':
    1152             # Add applicant
    1153             applicant = createObject(u'waeup.Applicant')
     1152            # Check if there are unused records which can be taken
     1153            cat = getUtility(ICatalog, name='applicants_catalog')
     1154            results = list(
     1155               cat.searchResults(record_used=(False, False)))
     1156            if results:
     1157                applicant = results[0]
     1158            else:
     1159                # Add applicant
     1160                applicant = createObject(u'waeup.Applicant')
     1161                self.context.addApplicant(applicant)
    11541162            self.applyData(applicant, **data)
    1155             self.context.addApplicant(applicant)
    11561163            applicant.reg_number = applicant.applicant_id
    11571164            notify(grok.ObjectModifiedEvent(applicant))
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_browser.py

    r13123 r13215  
    144144        # reg_number is the only field which has to be preset here
    145145        # because managers are allowed to edit this required field
     146        self.applicant.firstname = u'Joan'
    146147        self.applicant.reg_number = u'1234'
    147148        self.applicant.course1 = certificate
     
    11991200
    12001201    def test_register_applicant_create(self):
     1202        self.assertEqual(len(self.app['applicants'][container_name_1]), 1)
    12011203        # An applicant can register himself.
    12021204        self.browser.open(self.container_path)
     
    12121214        self.assertEqual(self.browser.url,
    12131215            self.container_path + '/registration_complete?email=xx%40yy.zz')
     1216        # A new applicant has been created
     1217        self.assertEqual(len(self.app['applicants'][container_name_1]), 2)
    12141218        # The new applicant can be found in the catalog via the email address
    12151219        cat = getUtility(ICatalog, name='applicants_catalog')
     
    12251229            reg_number=(applicant.reg_number, applicant.reg_number)))
    12261230        self.assertEqual(applicant,results[0])
     1231        return
     1232
     1233    def test_register_applicant_take_unused_record(self):
     1234        # Create an unused record
     1235        uu_applicant = createObject('waeup.Applicant')
     1236        self.app['applicants'][container_name_1].addApplicant(uu_applicant)
     1237        self.assertFalse(uu_applicant.record_used)
     1238        self.assertEqual(len(self.app['applicants'][container_name_1]), 2)
     1239        self.browser.open(self.container_path)
     1240        self.browser.getLink("Register for application").click()
     1241        # Fill the edit form with suitable values
     1242        self.browser.getControl(name="form.firstname").value = 'Anna'
     1243        self.browser.getControl(name="form.lastname").value = 'Kurios'
     1244        self.browser.getControl(name="form.email").value = 'xx@yy.zz'
     1245        self.browser.getControl(name="form.phone.country").value = ['+234']
     1246        self.browser.getControl(name="form.phone.area").value = '555'
     1247        self.browser.getControl(name="form.phone.ext").value = '6666666'
     1248        self.browser.getControl("Send login credentials").click()
     1249        # No applicant has been created ...
     1250        self.assertEqual(len(self.app['applicants'][container_name_1]), 2)
     1251        # ... and the existing, formerly unused record has been used instead
     1252        self.assertEqual(uu_applicant.lastname, 'Kurios')
     1253        self.assertTrue(uu_applicant.record_used)
    12271254        return
    12281255
Note: See TracChangeset for help on using the changeset viewer.