Ignore:
Timestamp:
26 Apr 2020, 09:22:35 (4 years ago)
Author:
Henrik Bettermann
Message:

Customize saveCourses.

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

Legend:

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

    r16071 r16075  
    2020import grok
    2121import os
    22 from zope.component import getUtility
     22from zope.component import getUtility, queryUtility
     23from zope.catalog.interfaces import ICatalog
    2324from zope.formlib.textwidgets import BytesDisplayWidget
    2425from waeup.kofa.interfaces import (
     
    6768    'special_application',
    6869    #'jamb_subjects_list',
    69     'programme_type')
     70    'programme_type',
     71    'course1',
     72    'course2',)
    7073UG_OMIT_EDIT_FIELDS = UG_OMIT_MANAGE_FIELDS + OMIT_DISPLAY_FIELDS + (
    7174    'student_id',
     
    7881    #'jamb_score',
    7982    #'jamb_reg_number',
    80     'aggregate')
     83    'aggregate',
     84    )
    8185
    8286# PG has its own interface
     
    106110    'emp2_end',
    107111    'emp2_reason',
     112    'course1',
     113    'course2',
    108114    )
    109115PG_OMIT_EDIT_FIELDS = PG_OMIT_MANAGE_FIELDS + PG_OMIT_DISPLAY_FIELDS + (
     
    161167    """
    162168
    163     @property
    164     def certs(self):
     169    def getCerts(self, coursex):
     170        yield(dict(code='', title='--', selected=''))
    165171        appcatcertificatesource = AppCatCertificateSource().factory
    166         for code in appcatcertificatesource.getValues(self.context):
    167             title = appcatcertificatesource.getTitle(self.context, code)
    168             yield(code, title)
     172        for cert in appcatcertificatesource.getValues(self.context):
     173            selected = ''
     174            course = getattr(self.context, coursex)
     175            if course is not None and course.code == cert.code:
     176                selected = 'selected'
     177            title = appcatcertificatesource.getTitle(self.context, cert)
     178            yield(dict(code=cert.code, title=title, selected=selected))
     179
     180    def saveCourses(self, changed_fields):
     181        """In custom packages we needed to customize the certificate
     182        select widget. We just save course1 and course2 if these customized
     183        fields appear in the form.
     184        """
     185        form = self.request.form
     186        course1 = form.get('custom.course1', None)
     187        course2 = form.get('custom.course2', None)
     188        cat = queryUtility(ICatalog, name='certificates_catalog')
     189        if course1:
     190            results = list(
     191                cat.searchResults(code=(course1, course1)))
     192            self.context.course1 = results[0]
     193            changed_fields.append('course1')
     194        if course2:
     195            results = list(
     196                cat.searchResults(code=(course2, course2)))
     197            self.context.course2 = results[0]
     198            changed_fields.append('course2')
     199        return changed_fields
    169200
    170201    @property
     
    192223    """
    193224
    194     @property
    195     def certs(self):
     225    def getCerts(self, coursex):
     226        yield(dict(code='', title='--', selected=''))
    196227        appcatcertificatesource = AppCatCertificateSource().factory
    197         for code in appcatcertificatesource.getValues(self.context):
    198             title = appcatcertificatesource.getTitle(self.context, code)
    199             yield(code, title)
     228        for cert in appcatcertificatesource.getValues(self.context):
     229            selected = ''
     230            course = getattr(self.context, coursex)
     231            if course is not None and course.code == cert.code:
     232                selected = 'selected'
     233            title = appcatcertificatesource.getTitle(self.context, cert)
     234            yield(dict(code=cert.code, title=title, selected=selected))
     235
     236    def saveCourses(self):
     237        """In custom packages we needed to customize the certificate
     238        select widget. We just save course1 and course2 if these customized
     239        fields appear in the form.
     240        """
     241        form = self.request.form
     242        course1 = form.get('custom.course1', None)
     243        course2 = form.get('custom.course2', None)
     244        cat = queryUtility(ICatalog, name='certificates_catalog')
     245        if course1:
     246            results = list(
     247                cat.searchResults(code=(course1, course1)))
     248            self.context.course1 = results[0]
     249        if course2:
     250            results = list(
     251                cat.searchResults(code=(course2, course2)))
     252            self.context.course2 = results[0]
     253        return
    200254
    201255    def display_fileupload(self, filename):
     
    219273            if not store.getFileByContext(self.context, attr=u'passport.jpg'):
    220274                return _('No passport picture uploaded.')
    221             if not self.request.form.get('confirm_passport', False):
    222                 return _('Passport picture confirmation box not ticked.')
    223275        if self.context.subtype == 'transfer' and \
    224276            not store.getFileByContext(self.context, attr=u'res_stat.pdf'):
  • main/kofacustom.iuokada/trunk/src/kofacustom/iuokada/applicants/browser_templates/applicanteditpage.pt

    r16070 r16075  
    2424
    2525      <tr>
    26         <td class="separator" colspan="2">For Demonstration Purposes Only!! <<<<</td>
     26        <td class="separator" colspan="2">
     27          Programmes/Courses Desired
     28        </td>
    2729      </tr>
    2830      <tr>
    2931        <td class="fieldname" i18n:translate="">
    30           Certificate:
     32          1st Choice Course of Study:
    3133        </td>
    3234        <td>
    3335          <input id="filterbox" class="kofa-filterbox form-control half"
    34                  placeholder="Enter search text, then select item below."
     36                 placeholder="Enter search text, then select course below."
    3537                 type="text" i18n:translate=""/>
    3638          <br />
    37           <select id="filteredselect" name="course1"
     39          <select id="filteredselect" name="custom.course1"
    3840                  class="form-control" size=5>
    39               <span tal:repeat="item view/certs"
    40                   tal:omit-tag="">
    41               <option tal:attributes="value python:item[0]">
    42                 <span tal:replace="python:item[1]">TITLE</span>
    43               </option>
    44             </span>
     41            <option tal:repeat="item python:view.getCerts('course1')"
     42                    tal:attributes="value item/code; selected item/selected">
     43              <span tal:replace="item/title">TITLE</span>
     44            </option>
    4545          </select>
    4646        </td>
    4747      </tr>
    48 
    49       <tr>
    50         <td class="separator" colspan="2">>>>></td>
     48      <tr>
     49        <td class="fieldname" i18n:translate="">
     50          2nd Choice Course of Study:
     51        </td>
     52        <td>
     53          <input id="filterbox" class="kofa-filterbox form-control half"
     54                 placeholder="Enter search text, then select course below."
     55                 type="text" i18n:translate=""/>
     56          <br />
     57          <select id="filteredselect" name="custom.course2"
     58                  class="form-control" size=5>
     59            <option tal:repeat="item python:view.getCerts('course2')"
     60                    tal:attributes="value item/code; selected item/selected">
     61              <span tal:replace="item/title">TITLE</span>
     62            </option>
     63          </select>
     64        </td>
     65      </tr>
     66
     67      <tr>
     68        <td class="separator" colspan="2">
     69          File Uploads
     70        </td>
    5171      </tr>
    5272
     
    129149  </table>
    130150
    131   <div tal:condition="python: not view.manage_applications
    132                               and context.__parent__.with_picture">
    133     <input id="confirm_passport" name="confirm_passport"
    134            type="checkbox" value="True"/>&nbsp;&nbsp;
    135     <span i18n:translate="">
    136     I confirm that the Passport Photograph uploaded on this form is a
    137     true picture of me.
    138     </span>
    139   </div>
     151  <p style="color:red"
     152      tal:condition="python: view.target in ('pg',)
     153                     and not view.manage_applications">
    140154  <br />
     155  Note: Your admission will not be processed until at least 2 of your expected
     156  3 referees have returned their assessment, while awaiting the 3rd referee, and
     157  until your transcript has been sent to the address below:<br /><br />
     158  The Office of the Secretary<br />
     159  School of Post Graduate Studies & Research (Main Campus)<br />
     160  Igbinedion University, Okada<br />
     161  Edo State, Nigeria<br /><br />
     162  </p>
    141163
    142164  <div tal:condition="view/availableActions">
  • main/kofacustom.iuokada/trunk/src/kofacustom/iuokada/applicants/tests/test_browser.py

    r15947 r16075  
    8585    layer = FunctionalLayer
    8686
    87     def test_application_slip(self):
     87    def fill_correct_values(self):
     88        # Fill the edit form with suitable values
     89        self.browser.getControl(name="form.firstname").value = 'John'
     90        self.browser.getControl(name="form.middlename").value = 'Anthony'
     91        self.browser.getControl(name="form.lastname").value = 'Tester'
     92        self.browser.getControl(name="custom.course1").value = ['CERT1']
     93        self.browser.getControl(name="form.date_of_birth").value = '09/09/1988'
     94        self.browser.getControl(name="form.sex").value = ['m']
     95        self.browser.getControl(name="form.email").value = 'xx@yy.zz'
     96
     97    def test_manage_application(self):
    8898        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
    8999        self.slip_path = self.view_path + '/application_slip.pdf'
     
    92102        self.fill_correct_values()
    93103        self.browser.getControl("Save").click()
     104        self.assertEqual(self.applicant.course1, self.certificate)
     105        self.assertEqual(self.applicant.course2, None)
    94106        IWorkflowState(self.applicant).setState('submitted')
    95107        self.browser.open(self.manage_path)
     
    101113        open(path, 'wb').write(self.browser.contents)
    102114        print "Sample application_slip.pdf written to %s" % path
     115        # Log entries have been added
     116        logfile = os.path.join(
     117            self.app['datacenter'].storage, 'logs', 'applicants.log')
     118        logcontent = open(logfile).read()
     119        self.assertTrue(
     120            'zope.mgr - kofacustom.iuokada.applicants.browser.CustomApplicantManageFormPage - '
     121            '%s - saved: firstname + middlename + lastname + date_of_birth '
     122            '+ sex + email + course1'
     123            % (self.applicant.applicant_id)
     124            in logcontent)
    103125
    104126    def test_upload_res_stat_by_manager(self):
Note: See TracChangeset for help on using the changeset viewer.