Changeset 6694 for main/waeup.sirp


Ignore:
Timestamp:
8 Sep 2011, 16:35:05 (13 years ago)
Author:
Henrik Bettermann
Message:

Add student base data edit page including interfaces and page template. This page will be only used for changing the password. All other data will be readonly for students.

The browser tests fail because students are being logged out after having changed the password. This shouldn't be.

Location:
main/waeup.sirp/trunk/src/waeup/sirp/students
Files:
1 added
4 edited

Legend:

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

    r6682 r6694  
    6565    IStudentsContainer, IStudent, IStudentClearance,
    6666    IStudentPersonal, IStudentBase, IStudentStudyCourse,
    67     IStudentPayments, IStudentAccommodation, IStudentNavigation
     67    IStudentPayments, IStudentAccommodation, IStudentNavigation,
     68    IStudentBaseEdit,
    6869    )
    6970from waeup.sirp.students.student import Student
     
    233234    grok.require('waeup.viewStudent')
    234235    grok.template('studentpage')
    235     form_fields = grok.AutoFields(IStudentBase)
     236    form_fields = grok.AutoFields(IStudentBase).omit('password')
    236237    pnav = 4
    237238    title = 'Base Data'
     
    447448    def label(self):
    448449        return '%s: History' % self.context.name
     450
     451# Pages for students only
     452
     453class StudentBaseEditActionButton(ManageActionButton):
     454    grok.order(1)
     455    grok.context(IStudent)
     456    grok.view(StudentBaseDisplayFormPage)
     457    grok.require('waeup.handleStudent')
     458    text = 'Change password'
     459    target = 'bedit'
     460
     461class StudentBaseEditFormPage(WAeUPEditFormPage):
     462    """ View to edit student base data by student
     463    """
     464    grok.context(IStudent)
     465    grok.name('bedit')
     466    grok.require('waeup.handleStudent')
     467    form_fields = grok.AutoFields(IStudentBaseEdit).omit('student_id')
     468    grok.template('studentbaseeditpage')
     469    label = 'Change password'
     470    title = 'Base Data'
     471    pnav = 4
     472
     473    def update(self):
     474        datepicker.need() # Enable jQuery datepicker in date fields.
     475        super(StudentBaseEditFormPage, self).update()
     476        self.wf_info = IWorkflowInfo(self.context)
     477        return
     478
     479    @grok.action('Save')
     480    def save(self, **data):
     481        changed_fields = self.applyData(self.context, **data)
     482        changed_fields = changed_fields.values()
     483        fields_string = '+'.join(' + '.join(str(i) for i in b) for b in changed_fields)
     484        self.context._p_changed = True
     485        self.flash('Form has been saved.')
     486        form = self.request.form
     487        ob_class = self.__implemented__.__name__.replace('waeup.sirp.','')
     488        if fields_string:
     489            self.context.loggerInfo(ob_class, 'saved: % s' % fields_string)
     490        if 'password' in fields_string:
     491            IUserAccount(self.context).setPassword(form['form.password'])
     492        return
  • main/waeup.sirp/trunk/src/waeup/sirp/students/interfaces.py

    r6692 r6694  
    6161    history = Attribute('Object history, a list of messages.')
    6262    state = Attribute('Returns the registration state of a student')
    63     student_id = Attribute('Randomly generated id')
     63    #student_id = Attribute('Randomly generated id')
    6464
    6565    def loggerInfo(ob_class, comment):
     
    7878        )
    7979
    80     password = schema.TextLine(
     80    password = schema.Password(
    8181        title = u'Password',
    8282        )
     
    126126    """
    127127
     128# Interfaces for students only
     129
     130class IStudentBaseEdit(IStudentBase):
     131    """Interface needed for editing of student base data by students.
     132    """
     133
     134    name = schema.TextLine(
     135        title = u'Full Name',
     136        default = u'Nobody',
     137        required = True,
     138        readonly = True,
     139        )
     140
     141IStudentBaseEdit['name'].order =  IStudentBase['name'].order
     142
     143class IStudentClearanceEdit(IStudentClearance):
     144    """Interface needed for restricted editing of student clearance data.
     145    """
     146
     147class IStudentPersonalEdit(IStudentPersonal):
     148    """Interface needed for restricted editing of student personal data.
     149    """
  • main/waeup.sirp/trunk/src/waeup/sirp/students/student.py

    r6666 r6694  
    2323from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState
    2424from waeup.sirp.interfaces import IObjectHistory
    25 from waeup.sirp.students.interfaces import IStudent, IStudentNavigation
     25from waeup.sirp.students.interfaces import (
     26    IStudent, IStudentNavigation, IStudentBaseEdit,
     27    )
    2628from waeup.sirp.utils.helpers import attrs_to_fields
    2729from waeup.sirp.students.utils import generate_student_id
     
    3133    owned by students.
    3234    """
    33     grok.implements(IStudent, IStudentNavigation)
     35    grok.implements(IStudent, IStudentNavigation,
     36        IStudentBaseEdit)
    3437    grok.provides(IStudent)
    3538
  • main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_browser.py

    r6667 r6694  
    3939from waeup.sirp.university.faculty import Faculty
    4040from waeup.sirp.university.department import Department
     41from waeup.sirp.interfaces import IUserAccount
    4142
    4243PH_LEN = 2059  # Length of placeholder file
     
    7576        student.name = u'Anna Tester'
    7677        self.test_student_id = self.app['students'].addStudent(student)
    77 
     78        # Set password
     79        IUserAccount(self.app['students'][self.test_student_id]).setPassword('spwd')
     80
     81        self.login_path = 'http://localhost/app/login'
    7882        self.container_path = 'http://localhost/app/students'
    7983        self.manage_container_path = self.container_path + '/@@manage'
     
    244248        self.assertMatches('...Student admitted by zope.mgr...',
    245249                           self.browser.contents)
    246 
    247         return
     250        return
     251
     252    def test_student_access(self):
     253        # Students can access their own objects
     254        # and can perform actions
     255
     256        self.browser.open(self.login_path)
     257        self.browser.getControl(name="form.login").value = self.test_student_id
     258        self.browser.getControl(name="form.password").value = 'spwd'
     259        self.browser.getControl("Login").click()
     260        self.assertEqual(self.browser.url, self.student_path)
     261        self.assertTrue('You logged in' in self.browser.contents)
     262        # Change password
     263        self.browser.getLink("Change password").click()
     264        self.browser.getControl(name="form.password").value = 'new_password'
     265        self.browser.getControl("Save").click()
     266        self.assertTrue('Form has been saved' in self.browser.contents)
     267        # We are still logged in. Changing the password hasn't thrown us out.
     268        self.browser.getLink("My Data").click()
     269        self.assertEqual(self.browser.url, self.student_path)
     270        # We can logout
     271        self.browser.getLink("Logout").click()
     272        self.assertTrue('You have been logged out' in self.browser.contents)
     273        self.assertEqual(self.browser.url, 'http://localhost/app')
     274        # We can login again with the new password
     275        self.browser.getLink("Login").click()
     276        #self.browser.open(self.login_path)
     277        self.browser.getControl(name="form.login").value = self.test_student_id
     278        self.browser.getControl(name="form.password").value = 'new_password'
     279        self.browser.getControl("Login").click()
     280        self.assertEqual(self.browser.url, self.student_path)
     281        self.assertTrue('You logged in' in self.browser.contents)
     282        return
Note: See TracChangeset for help on using the changeset viewer.