Ignore:
Timestamp:
25 Mar 2019, 17:59:03 (6 years ago)
Author:
Henrik Bettermann
Message:

Implement a library access switch.

Location:
main/waeup.uniben/trunk/src/waeup/uniben
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.uniben/trunk/src/waeup/uniben/permissions.py

    r15366 r15371  
    2323
    2424class ClearLibrary(grok.Permission):
    25     grok.name('waeup.clearForLibrary')
     25    grok.name('waeup.switchLibraryAccess')
    2626
    2727class PassportPictureManager(grok.Role):
     
    3737    grok.permissions('waeup.showStudents',
    3838                     'waeup.viewAcademics',
    39                      'waeup.clearForLibrary')
     39                     'waeup.switchLibraryAccess')
    4040
    4141class CRPUOfficer(CCOfficer):
  • main/waeup.uniben/trunk/src/waeup/uniben/students/browser.py

    r15352 r15371  
    5252    NigeriaStudentPersonalManageFormPage,
    5353    NigeriaStudentPersonalEditFormPage,
    54     NigeriaAccommodationManageFormPage
     54    NigeriaAccommodationManageFormPage,
     55    NigeriaStudentBaseDisplayFormPage,
    5556    )
    5657
     
    6667    ICustomStudentPersonalEdit)
    6768from waeup.uniben.interfaces import MessageFactory as _
     69
     70class CustomStudentBaseDisplayFormPage(NigeriaStudentBaseDisplayFormPage):
     71    """ Page to display student base data
     72    """
     73    form_fields = grok.AutoFields(ICustomStudentBase).omit(
     74        'password', 'suspended', 'suspended_comment',
     75        'flash_notice', 'provisionally_cleared')
     76    form_fields[
     77        'financial_clearance_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
     78
     79#class CustomStudentBaseManageFormPage(NigeriaStudentBaseManageFormPage):
     80#    """ View to manage student base data
     81#    """
     82#    form_fields = grok.AutoFields(ICustomStudentBase).omit(
     83#        'student_id', 'adm_code', 'suspended',
     84#        'financially_cleared_by', 'financial_clearance_date')
    6885
    6986class CustomOnlinePaymentDisplayFormPage(NigeriaOnlinePaymentDisplayFormPage):
     
    286303            note=self.note)
    287304
     305class SwitchLibraryAccessView(UtilityView, grok.View):
     306    """ Switch the library attribute
     307    """
     308    grok.context(ICustomStudent)
     309    grok.name('switch_library_access')
     310    grok.require('waeup.switchLibraryAccess')
     311
     312    def update(self):
     313        if self.context.library:
     314            self.context.library = False
     315            self.context.writeLogMessage(self, 'library access disabled')
     316            self.flash(_('Library access disabled'))
     317        else:
     318            self.context.library = True
     319            self.context.writeLogMessage(self, 'library access enabled')
     320            self.flash(_('Library access enabled'))
     321        self.redirect(self.url(self.context))
     322        return
     323
     324    def render(self):
     325        return
     326
    288327class ExportJHLIdCard(UtilityView, grok.View):
    289     """Deliver a an id card for the John Harris Library.
     328    """Deliver an id card for the John Harris Library.
    290329    """
    291330    grok.context(ICustomStudent)
     
    297336
    298337    omit_fields = (
    299         'suspended', 'email',
     338        'suspended', 'email', 'phone',
    300339        'adm_code', 'suspended_comment',
    301         'date_of_birth','reg_number',
     340        'date_of_birth',
    302341        'current_mode', 'certificate',
    303342        'entry_session',
     
    306345    form_fields = []
    307346
    308     def _signatures(self):
    309         return ([(
    310             'Current HD<br /> D. R. (Exams & Records)<br /> '
    311             'For: Registrar')],)
    312 
    313347    def _sigsInFooter(self):
     348        isStudent = getattr(
     349            self.request.principal, 'user_type', None) == 'student'
     350        if isStudent:
     351            return ''
    314352        return (_("Date, Reader's Signature"),
    315353                _("Date, Circulation Librarian's Signature"),
    316354                )
     355
     356    def update(self):
     357        if not self.context.library:
     358            self.flash(_('Forbidden!'), type="danger")
     359            self.redirect(self.url(self.context))
     360        return
    317361
    318362    @property
  • main/waeup.uniben/trunk/src/waeup/uniben/students/interfaces.py

    r14854 r15371  
    3333    """Representation of student base data.
    3434    """
     35
     36    library = schema.Bool(
     37        title = _(u'Library Id Card'),
     38        default = False,
     39        required = False,
     40        )
    3541
    3642class ICustomStudentPersonal(INigeriaStudentPersonal):
  • main/waeup.uniben/trunk/src/waeup/uniben/students/tests/test_browser.py

    r15352 r15371  
    4141    IExtFileStore, IFileStoreNameChooser)
    4242from waeup.kofa.students.interfaces import IStudentsUtils
     43from waeup.kofa.tests.test_authentication import SECRET
    4344from waeup.uniben.testing import FunctionalLayer
    4445
    4546SAMPLE_FPM = os.path.join(os.path.dirname(__file__), 'sample.fpm')
     47
     48class OfficerUITests(StudentsFullSetup):
     49    # Tests for Student class views and pages
     50
     51    layer = FunctionalLayer
     52
     53    def test_jhl_idcard_officer(self):
     54        # Create library officer
     55        self.app['users'].addUser('mrlibrary', SECRET)
     56        self.app['users']['mrlibrary'].email = 'library@foo.ng'
     57        self.app['users']['mrlibrary'].title = 'Carlo Pitter'
     58        prmglobal = IPrincipalRoleManager(self.app)
     59        prmglobal.assignRoleToPrincipal(
     60            'waeup.LibraryClearanceOfficer', 'mrlibrary')
     61        prmglobal.assignRoleToPrincipal(
     62            'waeup.StudentsOfficer', 'mrlibrary')
     63        self.browser.open(self.login_path)
     64        self.browser.getControl(name="form.login").value = 'mrlibrary'
     65        self.browser.getControl(name="form.password").value = SECRET
     66        self.browser.getControl("Login").click()
     67        self.assertMatches('...You logged in...', self.browser.contents)
     68        self.browser.open(self.student_path)
     69        self.assertFalse('JHL' in self.browser.contents)
     70        self.browser.getLink("Switch library access").click()
     71        self.assertTrue('Library access enabled' in self.browser.contents)
     72        self.assertTrue('JHL' in self.browser.contents)
     73        self.browser.getLink("Download JHL Id Card").click()
     74        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     75        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
     76        path = os.path.join(samples_dir(), 'jhl_idcard_officer.pdf')
     77        open(path, 'wb').write(self.browser.contents)
     78        print "Sample PDF jhl_idcard_officer.pdf written to %s" % path
    4679
    4780class StudentUITests(StudentsFullSetup):
     
    219252        self.browser.getControl(name="form.password").value = 'spwd'
    220253        self.browser.getControl("Login").click()
     254        self.assertFalse('JHL' in self.browser.contents)
     255        self.student.library = True
     256        self.browser.open(self.student_path)
     257        self.assertTrue('JHL' in self.browser.contents)
    221258        self.browser.getLink("Download JHL Id Card").click()
    222259        self.assertEqual(self.browser.headers['Status'], '200 Ok')
    223260        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
    224         path = os.path.join(samples_dir(), 'jhl_idcard.pdf')
     261        path = os.path.join(samples_dir(), 'jhl_idcard_student.pdf')
    225262        open(path, 'wb').write(self.browser.contents)
    226         print "Sample PDF jhl_idcard.pdf written to %s" % path
     263        print "Sample PDF jhl_idcard_student.pdf written to %s" % path
    227264
    228265    def test_jupeb_result_slip(self):
  • main/waeup.uniben/trunk/src/waeup/uniben/students/tests/test_export.py

    r14853 r15371  
    5656            'fst_sit_type,hq2_degree,hq2_disc,hq2_matric_no,hq2_school,'
    5757            'hq2_session,hq2_type,hq_degree,hq_disc,hq_fname,hq_matric_no,'
    58             'hq_school,hq_session,hq_type,is_staff,lastname,lga,'
     58            'hq_school,hq_session,hq_type,is_staff,lastname,lga,library,'
    5959            'marit_stat,matric_number,middlename,nationality,'
    6060            'next_kin_address,next_kin_name,next_kin_phone,next_kin_relation,'
     
    6868            '"[(\'printing_craft_practice\', \'A1\')]",my clr code,1981-02-04#,,,'
    6969            'anna@sample.com,,,,,,,,,,,,,Anna,,,,,,"[(\'printing_craft_practice\', \'A1\')]"'
    70             ',,,,,,,,,,,,,,,,Tester,,,234,M.,NG,,,,,,,,,,'
     70            ',,,,,,,,,,,,,,,,Tester,,,,234,M.,NG,,,,,,,,,,'
    7171            '"Studentroad 21\nLagos 123456\n",,+234-123-12345#,,,123,,,,,'
    7272            '"[(\'printing_craft_practice\', \'A1\')]",,f,A111111,0,,,created,'
  • main/waeup.uniben/trunk/src/waeup/uniben/students/viewlets.py

    r15354 r15371  
    3232from kofacustom.nigeria.interfaces import MessageFactory as _
    3333
     34class SwitchLibraryAccessActionButton(ManageActionButton):
     35    grok.order(7)
     36    grok.context(ICustomStudent)
     37    grok.view(StudentBaseDisplayFormPage)
     38    grok.require('waeup.switchLibraryAccess')
     39    text = _('Switch library access')
     40    target = 'switch_library_access'
     41    icon = 'actionicon_book.png'
     42
    3443class StudyCourseEditActionButton(ManageActionButton):
    3544    grok.order(1)
     
    122131    @property
    123132    def target_url(self):
    124         # temporarily disabled
    125         return ''
    126         return self.view.url(self.view.context, self.target)
     133        if self.context.library:
     134            return self.view.url(self.view.context, self.target)
     135        return
    127136
    128137class JUPEBResultSlipActionButton(ManageActionButton):
Note: See TracChangeset for help on using the changeset viewer.