Changeset 9124


Ignore:
Timestamp:
30 Aug 2012, 06:28:17 (12 years ago)
Author:
Henrik Bettermann
Message:

Add buttons and views for activating and deactivating student accounts.

Add history messages and log entries when students are being activated or deactivated.

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

Legend:

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

    r9028 r9124  
    4242from waeup.kofa.interfaces import (
    4343    IKofaObject, IUserAccount, IExtFileStore, IPasswordValidator, IContactForm,
    44     IKofaUtils, IUniversity)
     44    IKofaUtils, IUniversity, IObjectHistory)
    4545from waeup.kofa.interfaces import MessageFactory as _
    4646from waeup.kofa.widgets.datewidget import (
     
    299299    def label(self):
    300300        if self.context.suspended:
    301             return _('${a}: Base Data (account suspended)',
     301            return _('${a}: Base Data (account deactivated)',
    302302                mapping = {'a':self.context.display_fullname})
    303303        return  _('${a}: Base Data',
     
    353353    grok.name('manage_base')
    354354    grok.require('waeup.manageStudent')
    355     form_fields = grok.AutoFields(IStudentBase).omit('student_id', 'adm_code')
     355    form_fields = grok.AutoFields(IStudentBase).omit(
     356        'student_id', 'adm_code', 'suspended')
    356357    grok.template('basemanagepage')
    357358    label = _('Manage base data')
     
    414415        if fields_string:
    415416            self.context.writeLogMessage(self, 'saved: % s' % fields_string)
     417        return
     418
     419class StudentActivatePage(UtilityView, grok.View):
     420    """ Activate student account
     421    """
     422    grok.context(IStudent)
     423    grok.name('activate')
     424    grok.require('waeup.manageStudent')
     425
     426    def update(self):
     427        self.context.suspended = False
     428        self.context.writeLogMessage(self, 'account activated')
     429        history = IObjectHistory(self.context)
     430        history.addMessage('Student account activated')
     431        self.flash(_('Student account has been activated.'))
     432        self.redirect(self.url(self.context))
     433        return
     434
     435    def render(self):
     436        return
     437
     438class StudentDeactivatePage(UtilityView, grok.View):
     439    """ Deactivate student account
     440    """
     441    grok.context(IStudent)
     442    grok.name('deactivate')
     443    grok.require('waeup.manageStudent')
     444
     445    def update(self):
     446        self.context.suspended = True
     447        self.context.writeLogMessage(self, 'account deactivated')
     448        history = IObjectHistory(self.context)
     449        history.addMessage('Student account deactivated')
     450        self.flash(_('Student account has been deactivated.'))
     451        self.redirect(self.url(self.context))
     452        return
     453
     454    def render(self):
    416455        return
    417456
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py

    r9123 r9124  
    19181918        self.assertTrue('Employer' in self.browser.contents)
    19191919
     1920    def test_activate_deactivate_buttons(self):
     1921        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     1922        self.browser.open(self.student_path)
     1923        self.browser.getLink("Deactivate").click()
     1924        self.assertTrue(
     1925            'Student account has been deactivated.' in self.browser.contents)
     1926        self.assertTrue(
     1927            'Base Data (account deactivated)' in self.browser.contents)
     1928        self.assertTrue(self.student.suspended)
     1929        self.browser.getLink("Activate").click()
     1930        self.assertTrue(
     1931            'Student account has been activated.' in self.browser.contents)
     1932        self.assertFalse(
     1933            'Base Data (account deactivated)' in self.browser.contents)
     1934        self.assertFalse(self.student.suspended)
     1935        # History messages have been added ...
     1936        self.browser.getLink("History").click()
     1937        self.assertTrue(
     1938            'Student account deactivated by Manager<br />' in self.browser.contents)
     1939        self.assertTrue(
     1940            'Student account activated by Manager<br />' in self.browser.contents)
     1941        # ... and actions have been logged.
     1942        logfile = os.path.join(
     1943            self.app['datacenter'].storage, 'logs', 'students.log')
     1944        logcontent = open(logfile).read()
     1945        self.assertTrue('zope.mgr - students.browser.StudentDeactivatePage - '
     1946                        'K1000000 - account deactivated' in logcontent)
     1947        self.assertTrue('zope.mgr - students.browser.StudentActivatePage - '
     1948                        'K1000000 - account activated' in logcontent)
     1949
    19201950class StudentRequestPWTests(StudentsFullSetup):
    19211951    # Tests for student registration
  • main/waeup.kofa/trunk/src/waeup/kofa/students/viewlets.py

    r9070 r9124  
    166166    target = 'manage_base'
    167167
     168class StudentDeactivateActionButton(ManageActionButton):
     169    grok.order(5)
     170    grok.context(IStudent)
     171    grok.view(StudentBaseDisplayFormPage)
     172    grok.require('waeup.manageStudent')
     173    text = _('Deactivate account')
     174    target = 'deactivate'
     175    icon = 'actionicon_traffic_lights_red.png'
     176
     177    @property
     178    def target_url(self):
     179        if self.context.suspended:
     180            return ''
     181        return self.view.url(self.view.context, self.target)
     182
     183class StudentActivateActionButton(ManageActionButton):
     184    grok.order(5)
     185    grok.context(IStudent)
     186    grok.view(StudentBaseDisplayFormPage)
     187    grok.require('waeup.manageStudent')
     188    text = _('Activate account')
     189    target = 'activate'
     190    icon = 'actionicon_traffic_lights_green.png'
     191
     192    @property
     193    def target_url(self):
     194        if not self.context.suspended:
     195            return ''
     196        return self.view.url(self.view.context, self.target)
     197
    168198class StudentClearanceManageActionButton(ManageActionButton):
    169199    grok.order(1)
Note: See TracChangeset for help on using the changeset viewer.