- Timestamp:
- 21 Sep 2012, 08:19:35 (12 years ago)
- Location:
- main/waeup.kofa/branches/uli-zc-async
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/branches/uli-zc-async
- Property svn:mergeinfo changed
/main/waeup.kofa/branches/uli-async-update removed /main/waeup.kofa/branches/uli-autoinclude-less removed /main/waeup.kofa/trunk removed
- Property svn:mergeinfo changed
-
main/waeup.kofa/branches/uli-zc-async/src/waeup/kofa/students/browser.py
r9209 r9211 43 43 from waeup.kofa.interfaces import ( 44 44 IKofaObject, IUserAccount, IExtFileStore, IPasswordValidator, IContactForm, 45 IKofaUtils, IUniversity , IObjectHistory)45 IKofaUtils, IUniversity) 46 46 from waeup.kofa.interfaces import MessageFactory as _ 47 47 from waeup.kofa.widgets.datewidget import ( … … 53 53 IUGStudentClearance,IPGStudentClearance, 54 54 IStudentPersonal, IStudentBase, IStudentStudyCourse, 55 IStudentStudyCourseTransfer,56 55 IStudentAccommodation, IStudentStudyLevel, 57 56 ICourseTicket, ICourseTicketAdd, IStudentPaymentsContainer, 58 IStudentOnlinePayment, IStudentPreviousPayment, 59 IBedTicket, IStudentsUtils, IStudentRequestPW 57 IStudentOnlinePayment, IBedTicket, IStudentsUtils, IStudentRequestPW 60 58 ) 61 59 from waeup.kofa.students.catalog import search 62 60 from waeup.kofa.students.workflow import (CREATED, ADMITTED, PAID, 63 CLEARANCE, REQUESTED, RETURNING, CLEARED, REGISTERED, VALIDATED, 64 FORBIDDEN_POSTGRAD_TRANS) 61 CLEARANCE, REQUESTED, RETURNING, CLEARED, REGISTERED, VALIDATED) 65 62 from waeup.kofa.students.studylevel import StudentStudyLevel, CourseTicket 66 63 from waeup.kofa.students.vocabularies import StudyLevelSource … … 68 65 from waeup.kofa.hostels.hostel import NOT_OCCUPIED 69 66 from waeup.kofa.utils.helpers import get_current_principal, to_timezone 70 from waeup.kofa.mandates.mandate import PasswordMandate71 67 72 68 grok.context(IKofaObject) # Make IKofaObject the default context … … 95 91 return 96 92 97 def translated_values(view):98 lang = view.request.cookies.get('kofa.language')99 for value in view.context.values():100 value_dict = dict([i for i in value.__dict__.items()])101 value_dict['mandatory_bool'] = value.mandatory102 value_dict['mandatory'] = translate(str(value.mandatory), 'zope',103 target_language=lang)104 value_dict['carry_over'] = translate(str(value.carry_over), 'zope',105 target_language=lang)106 value_dict['automatic'] = translate(str(value.automatic), 'zope',107 target_language=lang)108 yield value_dict109 110 93 class StudentsBreadcrumb(Breadcrumb): 111 94 """A breadcrumb for the students container. … … 133 116 """ 134 117 grok.context(IStudentStudyCourse) 135 136 def title(self): 137 if self.context.is_current: 138 return _('Study Course') 139 else: 140 return _('Previous Study Course') 118 title = _('Study Course') 141 119 142 120 class PaymentsBreadcrumb(Breadcrumb): … … 301 279 grok.require('waeup.viewStudent') 302 280 grok.template('basepage') 303 form_fields = grok.AutoFields(IStudentBase).omit('password' , 'suspended')281 form_fields = grok.AutoFields(IStudentBase).omit('password') 304 282 pnav = 4 305 283 306 284 @property 307 285 def label(self): 308 if self.context.suspended: 309 return _('${a}: Base Data (account deactivated)', 310 mapping = {'a':self.context.display_fullname}) 311 return _('${a}: Base Data', 286 return _('${a}: Base Data', 312 287 mapping = {'a':self.context.display_fullname}) 313 288 … … 317 292 return _('set') 318 293 return _('unset') 319 320 class StudentBasePDFFormPage(KofaDisplayFormPage):321 """ Page to display student base data in pdf files.322 """323 form_fields = grok.AutoFields(IStudentBase).omit(324 'password', 'suspended', 'phone', 'adm_code', 'sex')325 294 326 295 class ContactStudentForm(ContactAdminForm): … … 361 330 return 362 331 363 class ExportPDFAdmissionSlipPage(UtilityView, grok.View):364 """Deliver a PDF Admission slip.365 """366 grok.context(IStudent)367 grok.name('admission_slip.pdf')368 grok.require('waeup.viewStudent')369 prefix = 'form'370 371 form_fields = grok.AutoFields(IStudentBase).select('student_id', 'reg_number')372 373 @property374 def label(self):375 portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE376 return translate(_('Admission Letter of'),377 'waeup.kofa', target_language=portal_language) \378 + ' %s' % self.context.display_fullname379 380 def render(self):381 students_utils = getUtility(IStudentsUtils)382 return students_utils.renderPDFAdmissionLetter(self,383 self.context.student)384 385 332 class StudentBaseManageFormPage(KofaEditFormPage): 386 333 """ View to manage student base data … … 389 336 grok.name('manage_base') 390 337 grok.require('waeup.manageStudent') 391 form_fields = grok.AutoFields(IStudentBase).omit( 392 'student_id', 'adm_code', 'suspended') 338 form_fields = grok.AutoFields(IStudentBase).omit('student_id') 393 339 grok.template('basemanagepage') 394 340 label = _('Manage base data') … … 416 362 allowed_transitions = [t for t in self.wf_info.getManualTransitions() 417 363 if not t[0].startswith('pay')] 418 if self.context.is_postgrad:419 allowed_transitions = [t for t in allowed_transitions420 if not t[0] in FORBIDDEN_POSTGRAD_TRANS]421 364 return [dict(name='', title=_('No transition'))] +[ 422 365 dict(name=x, title=y) for x, y in allowed_transitions] … … 453 396 return 454 397 455 class StudentActivatePage(UtilityView, grok.View):456 """ Activate student account457 """458 grok.context(IStudent)459 grok.name('activate')460 grok.require('waeup.manageStudent')461 462 def update(self):463 self.context.suspended = False464 self.context.writeLogMessage(self, 'account activated')465 history = IObjectHistory(self.context)466 history.addMessage('Student account activated')467 self.flash(_('Student account has been activated.'))468 self.redirect(self.url(self.context))469 return470 471 def render(self):472 return473 474 class StudentDeactivatePage(UtilityView, grok.View):475 """ Deactivate student account476 """477 grok.context(IStudent)478 grok.name('deactivate')479 grok.require('waeup.manageStudent')480 481 def update(self):482 self.context.suspended = True483 self.context.writeLogMessage(self, 'account deactivated')484 history = IObjectHistory(self.context)485 history.addMessage('Student account deactivated')486 self.flash(_('Student account has been deactivated.'))487 self.redirect(self.url(self.context))488 return489 490 def render(self):491 return492 493 398 class StudentClearanceDisplayFormPage(KofaDisplayFormPage): 494 399 """ Page to display student clearance data … … 506 411 def form_fields(self): 507 412 if self.context.is_postgrad: 508 form_fields = grok.AutoFields( 509 IPGStudentClearance).omit('clearance_locked') 510 else: 511 form_fields = grok.AutoFields( 512 IUGStudentClearance).omit('clearance_locked') 413 form_fields = grok.AutoFields(IPGStudentClearance).omit('clearance_locked') 414 else: 415 form_fields = grok.AutoFields(IUGStudentClearance).omit('clearance_locked') 513 416 return form_fields 514 417 … … 529 432 def form_fields(self): 530 433 if self.context.is_postgrad: 531 form_fields = grok.AutoFields( 532 IPGStudentClearance).omit('clearance_locked') 533 else: 534 form_fields = grok.AutoFields( 535 IUGStudentClearance).omit('clearance_locked') 434 form_fields = grok.AutoFields(IPGStudentClearance).omit('clearance_locked') 435 else: 436 form_fields = grok.AutoFields(IUGStudentClearance).omit('clearance_locked') 536 437 return form_fields 537 438 … … 545 446 def label(self): 546 447 portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE 547 return translate(_('Clearance Slip of '),448 return translate(_('Clearance Slip of '), 548 449 'waeup.kofa', target_language=portal_language) \ 549 450 + ' %s' % self.context.display_fullname 550 451 551 def _signatures(self):552 if self.context.state == CLEARED:553 return (_('Student Signature'), _('Clearance Officer Signature'))554 return555 556 452 def render(self): 557 studentview = StudentBase PDFFormPage(self.context.student,453 studentview = StudentBaseDisplayFormPage(self.context.student, 558 454 self.request) 559 455 students_utils = getUtility(IStudentsUtils) 560 456 return students_utils.renderPDF( 561 457 self, 'clearance.pdf', 562 self.context.student, studentview , signatures=self._signatures())458 self.context.student, studentview) 563 459 564 460 class StudentClearanceManageFormPage(KofaEditFormPage): … … 579 475 def form_fields(self): 580 476 if self.context.is_postgrad: 581 form_fields = grok.AutoFields(IPGStudentClearance) .omit('clr_code')582 else: 583 form_fields = grok.AutoFields(IUGStudentClearance) .omit('clr_code')477 form_fields = grok.AutoFields(IPGStudentClearance) 478 else: 479 form_fields = grok.AutoFields(IUGStudentClearance) 584 480 return form_fields 585 481 … … 661 557 mapping = {'a':self.context.display_fullname}) 662 558 663 class StudentPersonal ManageFormPage(KofaEditFormPage):664 """ Page to managepersonal data559 class StudentPersonalEditFormPage(KofaEditFormPage): 560 """ Page to edit personal data 665 561 """ 666 562 grok.context(IStudent) 667 grok.name(' manage_personal')668 grok.require('waeup. manageStudent')563 grok.name('edit_personal') 564 grok.require('waeup.handleStudent') 669 565 form_fields = grok.AutoFields(IStudentPersonal) 670 label = _(' Managepersonal data')566 label = _('Edit personal data') 671 567 pnav = 4 672 568 … … 676 572 return 677 573 678 class StudentPersonalEditFormPage(StudentPersonalManageFormPage):679 """ Page to edit personal data680 """681 grok.name('edit_personal')682 grok.require('waeup.handleStudent')683 label = _('Edit personal data')684 pnav = 4685 686 574 class StudyCourseDisplayFormPage(KofaDisplayFormPage): 687 575 """ Page to display the student study course data … … 690 578 grok.name('index') 691 579 grok.require('waeup.viewStudent') 580 form_fields = grok.AutoFields(IStudentStudyCourse) 692 581 grok.template('studycoursepage') 693 582 pnav = 4 694 583 695 584 @property 696 def form_fields(self):697 if self.context.is_postgrad:698 form_fields = grok.AutoFields(IStudentStudyCourse).omit(699 'current_verdict', 'previous_verdict')700 else:701 form_fields = grok.AutoFields(IStudentStudyCourse)702 return form_fields703 704 @property705 585 def label(self): 706 if self.context.is_current: 707 return _('${a}: Study Course', 708 mapping = {'a':self.context.__parent__.display_fullname}) 709 else: 710 return _('${a}: Previous Study Course', 711 mapping = {'a':self.context.__parent__.display_fullname}) 586 return _('${a}: Study Course', 587 mapping = {'a':self.context.__parent__.display_fullname}) 712 588 713 589 @property … … 730 606 return 731 607 732 @property733 def prev_studycourses(self):734 if self.context.is_current:735 if self.context.__parent__.get('studycourse_2', None) is not None:736 return (737 {'href':self.url(self.context.student) + '/studycourse_1',738 'title':_('First Study Course, ')},739 {'href':self.url(self.context.student) + '/studycourse_2',740 'title':_('Second Study Course')}741 )742 if self.context.__parent__.get('studycourse_1', None) is not None:743 return (744 {'href':self.url(self.context.student) + '/studycourse_1',745 'title':_('First Study Course')},746 )747 return748 749 608 class StudyCourseManageFormPage(KofaEditFormPage): 750 609 """ Page to edit the student study course data … … 754 613 grok.require('waeup.manageStudent') 755 614 grok.template('studycoursemanagepage') 615 form_fields = grok.AutoFields(IStudentStudyCourse) 756 616 label = _('Manage study course') 757 617 pnav = 4 … … 760 620 tabthreeactions = [_('Add study level')] 761 621 762 @property763 def form_fields(self):764 if self.context.is_postgrad:765 form_fields = grok.AutoFields(IStudentStudyCourse).omit(766 'current_verdict', 'previous_verdict')767 else:768 form_fields = grok.AutoFields(IStudentStudyCourse)769 return form_fields770 771 622 def update(self): 772 if not self.context.is_current:773 emit_lock_message(self)774 return775 623 super(StudyCourseManageFormPage, self).update() 776 624 tabs.need() … … 837 685 return 838 686 839 class StudentTransferFormPage(KofaAddFormPage):840 """Page to transfer the student.841 """842 grok.context(IStudent)843 grok.name('transfer')844 grok.require('waeup.manageStudent')845 label = _('Transfer student')846 form_fields = grok.AutoFields(IStudentStudyCourseTransfer).omit(847 'entry_mode', 'entry_session')848 pnav = 4849 850 def update(self):851 super(StudentTransferFormPage, self).update()852 warning.need()853 return854 855 @jsaction(_('Transfer'))856 def transferStudent(self, **data):857 error = self.context.transfer(**data)858 if error == -1:859 self.flash(_('Current level does not match certificate levels.'))860 elif error == -2:861 self.flash(_('Former study course record incomplete.'))862 elif error == -3:863 self.flash(_('Maximum number of transfers exceeded.'))864 else:865 self.flash(_('Successfully transferred.'))866 return867 868 687 class StudyLevelDisplayFormPage(KofaDisplayFormPage): 869 688 """ Page to display student study levels … … 873 692 grok.require('waeup.viewStudent') 874 693 form_fields = grok.AutoFields(IStudentStudyLevel) 875 form_fields[876 'validation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')877 694 grok.template('studylevelpage') 878 695 pnav = 4 … … 885 702 @property 886 703 def translated_values(self): 887 return translated_values(self) 704 lang = self.request.cookies.get('kofa.language') 705 for value in self.context.values(): 706 value_dict = dict([i for i in value.__dict__.items()]) 707 value_dict['mandatory'] = translate(str(value.mandatory), 'zope', 708 target_language=lang) 709 value_dict['carry_over'] = translate(str(value.carry_over), 'zope', 710 target_language=lang) 711 value_dict['automatic'] = translate(str(value.automatic), 'zope', 712 target_language=lang) 713 yield value_dict 888 714 889 715 @property … … 945 771 Mand = translate(_('Mand.'), 'waeup.kofa', target_language=portal_language) 946 772 Score = translate(_('Score'), 'waeup.kofa', target_language=portal_language) 947 studentview = StudentBase PDFFormPage(self.context.student,773 studentview = StudentBaseDisplayFormPage(self.context.student, 948 774 self.request) 949 775 students_utils = getUtility(IStudentsUtils) … … 970 796 grok.require('waeup.manageStudent') 971 797 grok.template('studylevelmanagepage') 972 form_fields = grok.AutoFields(IStudentStudyLevel).omit( 973 'validation_date', 'validated_by') 798 form_fields = grok.AutoFields(IStudentStudyLevel) 974 799 pnav = 4 975 800 taboneactions = [_('Save'),_('Cancel')] … … 978 803 979 804 def update(self): 980 if not self.context.__parent__.is_current:981 emit_lock_message(self)982 return983 805 super(StudyLevelManageFormPage, self).update() 984 806 tabs.need() … … 991 813 datatable.need() 992 814 return 993 994 @property995 def translated_values(self):996 return translated_values(self)997 815 998 816 @property … … 1043 861 1044 862 def update(self): 1045 if not self.context.__parent__.is_current:1046 emit_lock_message(self)1047 return1048 863 if str(self.context.__parent__.current_level) != self.context.__name__: 1049 864 self.flash(_('This level does not correspond current level.')) … … 1068 883 1069 884 def update(self): 1070 if not self.context.__parent__.is_current:1071 emit_lock_message(self)1072 return1073 885 if str(self.context.__parent__.current_level) != self.context.__name__: 1074 886 self.flash(_('This level does not correspond current level.')) … … 1106 918 pnav = 4 1107 919 1108 def update(self):1109 if not self.context.__parent__.is_current:1110 emit_lock_message(self)1111 return1112 super(CourseTicketAddFormPage, self).update()1113 return1114 1115 920 @action(_('Add course ticket')) 1116 921 def addCourseTicket(self, **data): … … 1119 924 ticket.automatic = False 1120 925 ticket.carry_over = False 926 ticket.code = course.code 927 ticket.title = course.title 928 ticket.fcode = course.__parent__.__parent__.__parent__.code 929 ticket.dcode = course.__parent__.__parent__.code 930 ticket.credits = course.credits 931 ticket.passmark = course.passmark 932 ticket.semester = course.semester 1121 933 try: 1122 self.context.addCourseTicket(ticket , course)934 self.context.addCourseTicket(ticket) 1123 935 except KeyError: 1124 936 self.flash(_('The ticket exists.')) … … 1218 1030 mapping = {'a': ', '.join(deleted)})) 1219 1031 self.context.writeLogMessage( 1220 self,'removed: % s' % ', '.join(deleted))1032 self,'removed: % s' % ', '.join(deleted)) 1221 1033 self.redirect(self.url(self.context)) 1222 1034 return … … 1240 1052 def createTicket(self, **data): 1241 1053 p_category = data['p_category'] 1242 previous_session = data.get('p_session', None)1243 previous_level = data.get('p_level', None)1244 1054 student = self.context.__parent__ 1245 1055 if p_category == 'bed_allocation' and student[ … … 1252 1062 return 1253 1063 students_utils = getUtility(IStudentsUtils) 1254 error, payment = students_utils.setPaymentDetails( 1255 p_category, student, previous_session, previous_level) 1064 error, payment = students_utils.setPaymentDetails(p_category, student) 1256 1065 if error is not None: 1257 1066 self.flash(error) 1258 if 'previous session' in error:1259 self.redirect(self.url(self.context) + '/@@addpp')1260 return1261 1067 self.redirect(self.url(self.context)) 1262 1068 return … … 1265 1071 self.redirect(self.url(self.context)) 1266 1072 return 1267 1268 class PreviousPaymentAddFormPage(OnlinePaymentAddFormPage):1269 """ Page to add an online payment ticket for previous sessions1270 """1271 grok.context(IStudentPaymentsContainer)1272 grok.name('addpp')1273 grok.require('waeup.payStudent')1274 form_fields = grok.AutoFields(IStudentPreviousPayment).select(1275 'p_category', 'p_session', 'p_level')1276 label = _('Add previous session online payment')1277 pnav = 41278 1073 1279 1074 class OnlinePaymentDisplayFormPage(KofaDisplayFormPage): … … 1354 1149 # self.redirect(self.url(self.context)) 1355 1150 # return 1356 studentview = StudentBase PDFFormPage(self.context.student,1151 studentview = StudentBaseDisplayFormPage(self.context.student, 1357 1152 self.request) 1358 1153 students_utils = getUtility(IStudentsUtils) … … 1431 1226 buttonname = _('Create bed ticket') 1432 1227 notice = '' 1433 with_ac = True1434 1228 1435 1229 def update(self, SUBMIT=None): … … 1472 1266 self.redirect(self.url(self.context)) 1473 1267 return 1474 if self.with_ac: 1475 self.ac_series = self.request.form.get('ac_series', None) 1476 self.ac_number = self.request.form.get('ac_number', None) 1268 self.ac_series = self.request.form.get('ac_series', None) 1269 self.ac_number = self.request.form.get('ac_number', None) 1477 1270 if SUBMIT is None: 1478 1271 return 1479 if self.with_ac: 1480 pin = '%s-%s-%s' % (self.ac_prefix, self.ac_series, self.ac_number) 1481 code = get_access_code(pin) 1482 if not code: 1483 self.flash(_('Activation code is invalid.')) 1484 return 1272 pin = '%s-%s-%s' % (self.ac_prefix, self.ac_series, self.ac_number) 1273 code = get_access_code(pin) 1274 if not code: 1275 self.flash(_('Activation code is invalid.')) 1276 return 1485 1277 # Search and book bed 1486 1278 cat = queryUtility(ICatalog, name='beds_catalog', default=None) … … 1488 1280 owner=(student.student_id,student.student_id)) 1489 1281 if len(entries): 1490 # If bed space has bee nmanually allocated use this bed1282 # If bed space has bee manually allocated use this bed 1491 1283 bed = [entry for entry in entries][0] 1492 1284 else: … … 1504 1296 mapping = {'a':acc_details['bt']})) 1505 1297 return 1506 if self.with_ac: 1507 # Mark pin as used (this also fires a pin related transition) 1508 if code.state == USED: 1509 self.flash(_('Activation code has already been used.')) 1298 # Mark pin as used (this also fires a pin related transition) 1299 if code.state == USED: 1300 self.flash(_('Activation code has already been used.')) 1301 return 1302 else: 1303 comment = _(u'invalidated') 1304 # Here we know that the ac is in state initialized so we do not 1305 # expect an exception, but the owner might be different 1306 if not invalidate_accesscode( 1307 pin,comment,self.context.student.student_id): 1308 self.flash(_('You are not the owner of this access code.')) 1510 1309 return 1511 else:1512 comment = _(u'invalidated')1513 # Here we know that the ac is in state initialized so we do not1514 # expect an exception, but the owner might be different1515 if not invalidate_accesscode(1516 pin,comment,self.context.student.student_id):1517 self.flash(_('You are not the owner of this access code.'))1518 return1519 1310 # Create bed ticket 1520 1311 bedticket = createObject(u'waeup.BedTicket') 1521 if self.with_ac: 1522 bedticket.booking_code = pin 1312 bedticket.booking_code = pin 1523 1313 bedticket.booking_session = acc_details['booking_session'] 1524 1314 bedticket.bed_type = acc_details['bt'] 1525 1315 bedticket.bed = bed 1526 1316 hall_title = bed.__parent__.hostel_name 1527 coordinates = bed. coordinates[1:]1317 coordinates = bed.getBedCoordinates()[1:] 1528 1318 block, room_nr, bed_nr = coordinates 1529 1319 bc = _('${a}, Block ${b}, Room ${c}, Bed ${d} (${e})', mapping = { … … 1548 1338 grok.require('waeup.handleAccommodation') 1549 1339 form_fields = grok.AutoFields(IBedTicket) 1550 form_fields['booking_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')1551 1340 pnav = 4 1552 1341 … … 1575 1364 def label(self): 1576 1365 portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE 1577 #return translate(_('Bed Allocation: '), 1578 # 'waeup.kofa', target_language=portal_language) \ 1579 # + ' %s' % self.context.bed_coordinates 1580 return translate(_('Bed Allocation Slip'), 1366 return translate(_('Bed Allocation: '), 1581 1367 'waeup.kofa', target_language=portal_language) \ 1582 + ' %s' % self.context. getSessionString()1368 + ' %s' % self.context.bed_coordinates 1583 1369 1584 1370 def render(self): 1585 studentview = StudentBase PDFFormPage(self.context.student,1371 studentview = StudentBaseDisplayFormPage(self.context.student, 1586 1372 self.request) 1587 1373 students_utils = getUtility(IStudentsUtils) … … 1645 1431 self.context.bed = new_bed 1646 1432 hall_title = new_bed.__parent__.hostel_name 1647 coordinates = new_bed. coordinates[1:]1433 coordinates = new_bed.getBedCoordinates()[1:] 1648 1434 block, room_nr, bed_nr = coordinates 1649 1435 bc = _('${a}, Block ${b}, Room ${c}, Bed ${d} (${e})', mapping = { … … 1783 1569 self.flash(_('Activation code is invalid.')) 1784 1570 return 1571 # Mark pin as used (this also fires a pin related transition) 1572 # and fire transition start_clearance 1785 1573 if code.state == USED: 1786 1574 self.flash(_('Activation code has already been used.')) 1787 1575 return 1788 # Mark pin as used (this also fires a pin related transition) 1789 # and fire transition start_clearance 1790 comment = _(u"invalidated") 1791 # Here we know that the ac is in state initialized so we do not 1792 # expect an exception, but the owner might be different 1793 if not invalidate_accesscode(pin, comment, self.context.student_id): 1794 self.flash(_('You are not the owner of this access code.')) 1795 return 1796 self.context.clr_code = pin 1576 else: 1577 comment = _(u"invalidated") 1578 # Here we know that the ac is in state initialized so we do not 1579 # expect an exception, but the owner might be different 1580 if not invalidate_accesscode(pin,comment,self.context.student_id): 1581 self.flash(_('You are not the owner of this access code.')) 1582 return 1583 self.context.clr_code = pin 1797 1584 IWorkflowInfo(self.context).fireTransition('start_clearance') 1798 1585 self.flash(_('Clearance process has been started.')) … … 1811 1598 def form_fields(self): 1812 1599 if self.context.is_postgrad: 1813 form_fields = grok.AutoFields(IPGStudentClearance).omit( 1814 'clearance_locked', 'clr_code') 1815 else: 1816 form_fields = grok.AutoFields(IUGStudentClearance).omit( 1817 'clearance_locked', 'clr_code') 1600 form_fields = grok.AutoFields(IPGStudentClearance).omit('clearance_locked') 1601 else: 1602 form_fields = grok.AutoFields(IUGStudentClearance).omit('clearance_locked') 1818 1603 return form_fields 1819 1604 … … 1842 1627 return 1843 1628 self.flash(_('Clearance form has been saved.')) 1844 if self.context.clr_code: 1845 self.redirect(self.url(self.context, 'request_clearance')) 1846 else: 1847 # We bypass the request_clearance page if student 1848 # has been imported in state 'clearance started' and 1849 # no clr_code was entered before. 1850 state = IWorkflowState(self.context).getState() 1851 if state != CLEARANCE: 1852 # This shouldn't happen, but the application officer 1853 # might have forgotten to lock the form after changing the state 1854 self.flash(_('This form cannot be submitted. Wrong state!')) 1855 return 1856 IWorkflowInfo(self.context).fireTransition('request_clearance') 1857 self.flash(_('Clearance has been requested.')) 1858 self.redirect(self.url(self.context)) 1629 self.redirect(self.url(self.context,'request_clearance')) 1859 1630 return 1860 1631 … … 1876 1647 return 1877 1648 pin = '%s-%s-%s' % (self.ac_prefix, self.ac_series, self.ac_number) 1878 if self.context.clr_code and self.context.clr_code!= pin:1649 if self.context.clr_code != pin: 1879 1650 self.flash(_("This isn't your CLR access code.")) 1880 1651 return 1881 1652 state = IWorkflowState(self.context).getState() 1653 # This shouldn't happen, but the application officer 1654 # might have forgotten to lock the form after changing the state 1882 1655 if state != CLEARANCE: 1883 # This shouldn't happen, but the application officer1884 # might have forgotten to lock the form after changing the state1885 1656 self.flash(_('This form cannot be submitted. Wrong state!')) 1886 1657 return … … 1902 1673 1903 1674 def update(self, SUBMIT=None): 1904 if not self.context.is_current:1905 emit_lock_message(self)1906 return1907 super(StartSessionPage, self).update()1908 1675 if not self.context.next_session_allowed: 1909 1676 self.flash(_("You are not entitled to start session.")) … … 1963 1730 1964 1731 def update(self): 1965 if not self.context.is_current:1966 emit_lock_message(self)1967 return1968 1732 if self.context.student.state != PAID: 1969 1733 emit_lock_message(self) … … 1998 1762 1999 1763 def update(self): 2000 if not self.context.__parent__.is_current:2001 emit_lock_message(self)2002 return2003 1764 if self.context.student.state != PAID: 2004 1765 emit_lock_message(self) … … 2015 1776 level_title = translate(self.context.level_title, 'waeup.kofa', 2016 1777 target_language=lang) 2017 return _(' Edit course list of${a}',1778 return _('Add and remove course tickets of study level ${a}', 2018 1779 mapping = {'a':level_title}) 2019 1780 … … 2024 1785 total_credits += val.credits 2025 1786 return total_credits 2026 2027 @property2028 def translated_values(self):2029 return translated_values(self)2030 1787 2031 1788 @action(_('Add course ticket')) … … 2090 1847 ticket = createObject(u'waeup.CourseTicket') 2091 1848 course = data['course'] 1849 for name in ['code', 'title', 'credits', 'passmark', 'semester']: 1850 setattr(ticket, name, getattr(course, name)) 2092 1851 ticket.automatic = False 2093 ticket.carry_over = False2094 1852 try: 2095 self.context.addCourseTicket(ticket , course)1853 self.context.addCourseTicket(ticket) 2096 1854 except KeyError: 2097 1855 self.flash(_('The ticket exists.')) … … 2169 1927 grok.template('requestpw') 2170 1928 form_fields = grok.AutoFields(IStudentRequestPW).select( 2171 'firstname',' number','email')1929 'firstname','reg_number','email') 2172 1930 label = _('Request password for first-time login') 2173 1931 … … 2190 1948 return True 2191 1949 2192 @action(_(' Send login credentials to email address'), style='primary')1950 @action(_('Get login credentials'), style='primary') 2193 1951 def get_credentials(self, **data): 2194 1952 if not self.captcha_result.is_valid: … … 2196 1954 # No need to flash something. 2197 1955 return 2198 number = data.get('number','')1956 reg_number = data.get('reg_number','') 2199 1957 firstname = data.get('firstname','') 2200 1958 cat = getUtility(ICatalog, name='students_catalog') 2201 1959 results = list( 2202 cat.searchResults(reg_number=(number, number))) 2203 if not results: 2204 results = list( 2205 cat.searchResults(matric_number=(number, number))) 1960 cat.searchResults(reg_number=(reg_number, reg_number))) 2206 1961 if results: 2207 1962 student = results[0] … … 2229 1984 kofa_utils = getUtility(IKofaUtils) 2230 1985 password = kofa_utils.genPassword() 2231 mandate = PasswordMandate() 2232 mandate.params['password'] = password 2233 mandate.params['user'] = student 2234 site = grok.getSite() 2235 site['mandates'].addMandate(mandate) 1986 IUserAccount(student).setPassword(password) 2236 1987 # Send email with credentials 2237 args = {'mandate_id':mandate.mandate_id} 2238 mandate_url = self.url(site) + '/mandate?%s' % urlencode(args) 2239 url_info = u'Confirmation link: %s' % mandate_url 1988 login_url = self.url(grok.getSite(), 'login') 2240 1989 msg = _('You have successfully requested a password for the') 2241 1990 if kofa_utils.sendCredentials(IUserAccount(student), 2242 password, url_info, msg):1991 password, login_url, msg): 2243 1992 email_sent = student.email 2244 1993 else: … … 2246 1995 self._redirect(email=email_sent, password=password, 2247 1996 student_id=student.student_id) 2248 ob_class = self.__implemented__.__name__.replace('waeup.kofa.','')2249 self.context.logger.info(2250 '%s - %s (%s) - %s' % (ob_class, number, student.student_id, email_sent))2251 1997 return 2252 1998
Note: See TracChangeset for help on using the changeset viewer.