Changeset 6705


Ignore:
Timestamp:
9 Sep 2011, 22:58:35 (13 years ago)
Author:
uli
Message:

Create password setters that harmonize better with the regular formlib/form techniques.

Location:
main/waeup.sirp/branches/uli-studentpw/src/waeup/sirp/students
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/branches/uli-studentpw/src/waeup/sirp/students/browser.py

    r6701 r6705  
    6363    WAeUPObjectWidget, WAeUPObjectDisplayWidget)
    6464from waeup.sirp.students.interfaces import (
    65     IStudentsContainer, IStudent, IStudentClearance,
     65    IStudentsContainer, IStudent, IStudentClearance, IStudentPasswordSetting,
    6666    IStudentPersonal, IStudentBase, IStudentStudyCourse,
    6767    IStudentPayments, IStudentAccommodation, IStudentNavigation,
     
    159159        self.acseries = self.request.form.get('form.acseries', None)
    160160        self.acnumber = self.request.form.get('form.acnumber', None)
    161        
     161
    162162        if SUBMIT is None:
    163163            return
     
    286286    grok.require('waeup.viewStudent')
    287287    grok.template('basepage')
    288     form_fields = grok.AutoFields(IStudentBase)  #.omit('password')
     288    form_fields = grok.AutoFields(IStudentBase).omit('password')
    289289    pnav = 4
    290290    title = 'Base Data'
     
    533533    target = 'bedit'
    534534
     535class StudentPasswordSetting(grok.Adapter):
     536    """Adapt IStudent to data needed for password settings.
     537
     538    We provide password getters/setters for the attached context (an
     539    IStudent object) that cooperate seamless with the usual
     540    formlib/form techniques.
     541    """
     542    grok.context(IStudent)
     543    grok.provides(IStudentPasswordSetting)
     544
     545    def __init__(self, context):
     546        self.name = context.name
     547        self.password_repeat = context.password
     548        self.context = context
     549        return
     550
     551    def getPassword(self):
     552        return self.context.password
     553
     554    def setPassword(self, password):
     555        IUserAccount(self.context).setPassword(password)
     556        return
     557
     558    password = property(getPassword, setPassword)
     559
    535560class StudentBaseEditFormPage(WAeUPEditFormPage):
    536561    """ View to edit student base data by student
     
    539564    grok.name('bedit')
    540565    grok.require('waeup.handleStudent')
    541     form_fields = grok.AutoFields(IStudentBaseEdit).omit(
    542         'student_id', 'reg_number')
     566    form_fields = grok.AutoFields(IStudentPasswordSetting)
    543567    grok.template('baseeditpage')
    544568    label = 'Change password'
     
    547571
    548572    def update(self):
    549         datepicker.need() # Enable jQuery datepicker in date fields.
     573        #datepicker.need() # Enable jQuery datepicker in date fields.
    550574        super(StudentBaseEditFormPage, self).update()
    551575        self.wf_info = IWorkflowInfo(self.context)
     
    554578    @grok.action('Save')
    555579    def save(self, **data):
     580        print "PW1: ", self.context.password
    556581        form = self.request.form
    557582        ob_class = self.__implemented__.__name__.replace('waeup.sirp.','')
    558         if form.has_key('password') and form['password']:
    559             if form['password'] != form['control_password']:
    560                 self.flash('Passwords do not match.')
    561                 return
    562             IUserAccount(self.context).setPassword(form['password'])
    563             self.context.loggerInfo(ob_class, 'password changed')
    564583        changed_fields = self.applyData(self.context, **data)
    565584        changed_fields = changed_fields.values()
    566         fields_string = '+'.join(' + '.join(str(i) for i in b) for b in changed_fields)
    567         self.context._p_changed = True
     585        fields_string = '+'.join(' + '.join(
     586                str(i) for i in b) for b in changed_fields)
    568587        self.flash('Form has been saved.')
    569588        if fields_string:
    570589            self.context.loggerInfo(ob_class, 'saved: % s' % fields_string)
     590        print "PW2: ", self.context.password
    571591        return
    572592
     
    585605    grok.name('cedit')
    586606    grok.require('waeup.handleStudent')
    587     form_fields = grok.AutoFields(IStudentClearanceEdit).omit('clearance_locked')
     607    form_fields = grok.AutoFields(
     608        IStudentClearanceEdit).omit('clearance_locked')
    588609    #grok.template('clearanceeditpage')
    589610    label = 'Edit clerance data'
  • main/waeup.sirp/branches/uli-studentpw/src/waeup/sirp/students/browser_templates/baseeditpage.pt

    r6701 r6705  
    3838        </tr>
    3939      </tal:block>
     40<!--
    4041      <tr>
    41         <td class="label"><label>Password:</label></td>
     42        <td class="label"><label>New password:</label></td>
    4243        <td>
    4344          <input name="password" type="password"/>
     
    4546      </tr>
    4647      <tr>
    47         <td class="label"><label>Retype password:</label></td>
     48        <td class="label"><label>Retype new password:</label></td>
    4849        <td>
    4950          <input name="control_password" type="password" />
    5051        </td>
    5152      </tr>
     53-->
    5254    </tbody>
    5355  </table>
  • main/waeup.sirp/branches/uli-studentpw/src/waeup/sirp/students/interfaces.py

    r6699 r6705  
    5656        """
    5757
     58class IStudentPasswordSetting(IWAeUPObject):
     59    """Data needed for password setting.
     60    """
     61    name = schema.TextLine(
     62        title = u'Full Name',
     63        default = u'Nobody',
     64        required = True,
     65        )
     66
     67    password = schema.Password(
     68        title = u'New password',
     69        required = False,
     70        )
     71
     72    password_repeat = schema.Password(
     73        title = u'Retype new password',
     74        required = False,
     75        )
     76
    5877class IStudentBase(IWAeUPObject):
    5978    """Representation of student base data.
     
    6180    history = Attribute('Object history, a list of messages.')
    6281    state = Attribute('Returns the registration state of a student')
    63     #student_id = Attribute('Randomly generated id')
    6482    password = Attribute('Encrypted password of a student')
     83
     84    password = schema.Password(
     85        title = u'Password',
     86        required = False,
     87        )
    6588
    6689    def loggerInfo(ob_class, comment):
Note: See TracChangeset for help on using the changeset viewer.