Changeset 13331 for main/waeup.kwarapoly


Ignore:
Timestamp:
15 Oct 2015, 17:18:41 (9 years ago)
Author:
Henrik Bettermann
Message:

Apply getMultiAdapter to collect all file registered viewlets and make upload of these files compulsory.

Location:
main/waeup.kwarapoly/trunk/src/waeup/kwarapoly/students
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kwarapoly/trunk/src/waeup/kwarapoly/students/browser.py

    r13308 r13331  
    1919from zope.i18n import translate
    2020from zope.formlib.textwidgets import BytesDisplayWidget
    21 from zope.component import getUtility
     21from zope.component import getUtility, getMultiAdapter
     22from zope.viewlet.interfaces import IViewletManager
    2223from waeup.kofa.interfaces import IKofaUtils
    2324from waeup.kofa.browser.layout import UtilityView
     
    4849    NigeriaStudentBaseEditFormPage
    4950    )
    50 
     51from kofacustom.nigeria.students.viewlets import show_viewlet
    5152from waeup.kwarapoly.students.interfaces import (
    5253    ICustomStudent,
     
    188189
    189190    def dataNotComplete(self):
    190         store = getUtility(IExtFileStore)
    191         #if not store.getFileByContext(self.context, attr=u'birth_certificate.jpg'):
    192         #    return _('No birth certificate uploaded.')
    193         #if not store.getFileByContext(self.context, attr=u'ref_let.jpg'):
    194         #    return _('No guarantor/referee letter uploaded.')
    195         #if not store.getFileByContext(self.context, attr=u'acc_let.jpg'):
    196         #    return _('No acceptance letter uploaded.')
    197         #if not store.getFileByContext(self.context, attr=u'fst_sit_scan.jpg'):
    198         #    return _('No first sitting result uploaded.')
    199         if not store.getFileByContext(self.context, attr=u'stat_dec'):
    200             return _('No affidavit of good conduct uploaded.')
     191        mgr = getMultiAdapter(
     192            (self.context, self.request, self), IViewletManager,'files')
     193        mgr.update()
     194        missing_files = []
     195        for viewlet in mgr.viewlets:
     196            if viewlet.show_viewlet and not viewlet.file_exists:
     197                missing_files += (viewlet.label, )
     198        if missing_files:
     199            return "Missing: %s" % ', '.join(missing_files)
    201200        return False
    202201
  • main/waeup.kwarapoly/trunk/src/waeup/kwarapoly/students/tests/test_browser.py

    r13307 r13331  
    562562                        'W1000000 - ND/15/dep1/FT/001 assigned' in logcontent)
    563563        return
     564
     565    def test_student_fileupload(self):
     566        # Students can edit clearance data
     567        IWorkflowState(self.student).setState('clearance started')
     568        self.browser.open(self.login_path)
     569        self.browser.getControl(name="form.login").value = self.student_id
     570        self.browser.getControl(name="form.password").value = 'spwd'
     571        self.browser.getControl("Login").click()
     572        self.browser.getLink("Clearance Data").click()
     573        self.browser.getLink("Edit").click()
     574        self.browser.getControl("Save and request clearance").click()
     575        self.assertMatches('...Required input is missing...',
     576                           self.browser.contents)
     577        self.student.nationality = u'DE'
     578        self.browser.open(self.edit_clearance_path)
     579        self.browser.getControl("Save and request clearance").click()
     580        self.assertTrue(
     581            'Missing: Birth Certificate, Acceptance Letter, LGA Identification, '
     582            'First Sitting Result, Second Sitting Result, '
     583            'Higher Qualification Result, Advanced Level Result, Certificate, '
     584            'Evidence of Name, Result Statement, Guarantor/Referee Letter, '
     585            'Affidavit of Good Conduct'
     586            in self.browser.contents)
     587        # Students can upload documents
     588        ctrl = self.browser.getControl(name='birthcertificateupload')
     589        file_obj = open(SAMPLE_IMAGE, 'rb')
     590        file_ctrl = ctrl.mech_control
     591        file_ctrl.add_file(file_obj, filename='my_birth_certificate.jpg')
     592        self.browser.getControl(
     593            name='upload_birthcertificateupload').click()
     594        self.assertTrue(
     595            'href="http://localhost/app/students/W1000000/birth_certificate"'
     596            in self.browser.contents)
     597        # The list of missing files is now slightly shorter
     598        self.browser.getControl("Save and request clearance").click()
     599        self.assertTrue(
     600            'Missing: Acceptance Letter, LGA Identification, '
     601            'First Sitting Result, Second Sitting Result, '
     602            'Higher Qualification Result, Advanced Level Result, Certificate, '
     603            'Evidence of Name, Result Statement, Guarantor/Referee Letter, '
     604            'Affidavit of Good Conduct'
     605            in self.browser.contents)
     606        return
Note: See TracChangeset for help on using the changeset viewer.