Changeset 7144 for main/waeup.sirp/trunk/src/waeup/sirp/students/browser.py
- Timestamp:
- 19 Nov 2011, 17:26:18 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/students/browser.py
r7141 r7144 40 40 from waeup.sirp.university.vocabularies import study_modes 41 41 from waeup.sirp.students.interfaces import ( 42 IStudentsContainer, IStudent, IStudentClearance, IStudentPasswordSetting,42 IStudentsContainer, IStudent, IStudentClearance, 43 43 IStudentPersonal, IStudentBase, IStudentStudyCourse, 44 44 IStudentAccommodation, IStudentClearanceEdit, IStudentStudyLevel, … … 52 52 from waeup.sirp.students.vocabularies import StudyLevelSource 53 53 from waeup.sirp.students.utils import ( 54 getPaymentDetails, getAccommodationDetails, selectBed, renderPDF) 54 getPaymentDetails, getAccommodationDetails, selectBed, 55 renderPDF, validatePassword) 55 56 from waeup.sirp.browser.resources import toggleall 56 57 from waeup.sirp.authentication import get_principal_role_manager … … 1496 1497 form_fields = grok.AutoFields(IStudentBase).select( 1497 1498 'email', 'phone') 1498 #grok.template('basemanagepage')1499 1499 label = 'Edit base data' 1500 1500 title = 'Base Data' … … 1506 1506 return 1507 1507 1508 class StudentPasswordSetting(grok.Adapter): 1509 """Adapt IStudent to data needed for password settings. 1510 1511 We provide password getters/setters for the attached context (an 1512 IStudent object) that cooperate seamless with the usual 1513 formlib/form techniques. 1514 """ 1515 grok.context(IStudent) 1516 grok.provides(IStudentPasswordSetting) 1517 1518 def __init__(self, context): 1519 self.name = context.fullname 1520 self.password_repeat = context.password 1521 self.context = context 1522 return 1523 1524 def getPassword(self): 1525 return self.context.password 1526 1527 def setPassword(self, password): 1528 IUserAccount(self.context).setPassword(password) 1529 return 1530 1531 password = property(getPassword, setPassword) 1532 1533 class StudentPasswordFormPage(WAeUPEditFormPage): 1534 """ View to edit the password by student 1508 class StudentChangePasswordPage(WAeUPEditFormPage): 1509 """ View to manage student base data 1535 1510 """ 1536 1511 grok.context(IStudent) 1537 1512 grok.name('change_password') 1538 1513 grok.require('waeup.handleStudent') 1539 form_fields = grok.AutoFields(IStudentPasswordSetting) 1540 grok.template('baseeditpage') 1514 grok.template('change_password') 1541 1515 label = 'Change password' 1542 1516 title = 'Base Data' 1543 1517 pnav = 4 1544 1518 1545 def update(self): 1546 super(StudentPasswordFormPage, self).update() 1547 return 1548 1549 def onFailure(self, action, data, errors): 1550 new_status = [] 1551 other_errors = False 1552 for error in errors: 1553 msg = getattr(error, 'message', '') 1554 if isinstance(msg, basestring) and msg != '': 1555 # invariant error 1556 new_status.append(msg) 1519 @grok.action('Save') 1520 def save(self, **data): 1521 form = self.request.form 1522 password = form.get('change_password', None) 1523 password_ctl = form.get('change_password_repeat', None) 1524 if password: 1525 if (password != password_ctl): 1526 self.flash('Passwords do not match.') 1557 1527 else: 1558 # field error 1559 new_status.append('see below for details') 1560 continue 1561 self.status = u'Error: %s' % ', '.join(new_status) 1562 return 1563 1564 @grok.action('Save', failure=onFailure) 1565 def save(self, **data): 1566 if not isinstance(data.get('password', None), basestring): 1567 self.flash('Password unchanged.') 1568 return 1569 self.applyData(self.context, **data) 1570 self.flash('Password has been set.') 1528 error = validatePassword(password) 1529 if not error: 1530 IUserAccount(self.context).setPassword(password) 1531 write_log_message(self, 'password changed') 1532 self.flash('Password changed.') 1533 else: 1534 self.flash(error) 1571 1535 return 1572 1536
Note: See TracChangeset for help on using the changeset viewer.