Ignore:
Timestamp:
28 Aug 2020, 08:36:00 (4 years ago)
Author:
Henrik Bettermann
Message:

Modify and adjust saveCourses.

Location:
main/kofacustom.iuokada/trunk/src/kofacustom/iuokada/applicants
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/kofacustom.iuokada/trunk/src/kofacustom/iuokada/applicants/browser.py

    r16209 r16220  
    203203        yield(dict(code=cert.code, title=title, selected=selected))
    204204
    205 def saveCourses(view, changed_fields=[]):
     205def saveCourses(view):
    206206    """In custom packages we needed to customize the certificate
    207207    select widget. We just save course1 and course2 if these customized
    208208    fields appear in the form.
    209209    """
     210    changed_courses = []
    210211    form = view.request.form
    211212    course1 = form.get('custom.course1', None)
     213    if not course1:
     214        return 'Please select your 1st Choice Course of Study.', None
     215    cat = queryUtility(ICatalog, name='certificates_catalog')
     216    results = list(
     217        cat.searchResults(code=(course1, course1)))
     218    new_course1 = results[0]
     219    old_course1 = view.context.course1
     220    if old_course1 != new_course1:
     221        view.context.course1 = new_course1
     222        changed_courses.append('course1')
     223    new_course2 = None
     224    old_course2 = view.context.course2
    212225    course2 = form.get('custom.course2', None)
    213     cat = queryUtility(ICatalog, name='certificates_catalog')
    214     if course1:
    215         results = list(
    216             cat.searchResults(code=(course1, course1)))
    217         view.context.course1 = results[0]
    218         changed_fields.append('course1')
    219226    if course2:
    220227        results = list(
    221228            cat.searchResults(code=(course2, course2)))
    222         view.context.course2 = results[0]
    223         changed_fields.append('course2')
    224     return changed_fields
     229        new_course2 = results[0]
     230    if old_course2 != new_course2:
     231        view.context.course2 = new_course2
     232        changed_courses.append('course2')
     233    return None, changed_courses
    225234
    226235def display_fileupload(view, filename):
     
    247256        return getCerts(self, coursex)
    248257
    249     def saveCourses(self, changed_fields):
    250         return saveCourses(self, changed_fields)
     258    def saveCourses(self):
     259        return saveCourses(self)
    251260
    252261    def display_fileupload(self, filename):
  • main/kofacustom.iuokada/trunk/src/kofacustom/iuokada/applicants/tests/test_browser.py

    r16075 r16220  
    9090        self.browser.getControl(name="form.middlename").value = 'Anthony'
    9191        self.browser.getControl(name="form.lastname").value = 'Tester'
    92         self.browser.getControl(name="custom.course1").value = ['CERT1']
    9392        self.browser.getControl(name="form.date_of_birth").value = '09/09/1988'
    9493        self.browser.getControl(name="form.sex").value = ['m']
     
    101100        self.assertEqual(self.browser.headers['Status'], '200 Ok')
    102101        self.fill_correct_values()
     102        self.browser.getControl(name="custom.course1").value = ['']
     103        self.browser.getControl("Save").click()
     104        self.assertTrue('Please select your 1st Choice Course of Study.'
     105            in self.browser.contents)
     106        self.browser.getControl(name="custom.course1").value = ['CERT1']
    103107        self.browser.getControl("Save").click()
    104108        self.assertEqual(self.applicant.course1, self.certificate)
     
    113117        open(path, 'wb').write(self.browser.contents)
    114118        print "Sample application_slip.pdf written to %s" % path
    115         # Log entries have been added
     119        # Log entries have been added (course1 is missing because it was already stored)
    116120        logfile = os.path.join(
    117121            self.app['datacenter'].storage, 'logs', 'applicants.log')
     
    120124            'zope.mgr - kofacustom.iuokada.applicants.browser.CustomApplicantManageFormPage - '
    121125            '%s - saved: firstname + middlename + lastname + date_of_birth '
    122             '+ sex + email + course1'
     126            '+ sex + email'
    123127            % (self.applicant.applicant_id)
    124128            in logcontent)
Note: See TracChangeset for help on using the changeset viewer.