Ignore:
Timestamp:
21 Sep 2012, 08:19:35 (12 years ago)
Author:
uli
Message:

Rollback r9209. Looks like multiple merges from trunk confuse svn when merging back into trunk.

Location:
main/waeup.kofa/branches/uli-zc-async
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/branches/uli-zc-async

  • main/waeup.kofa/branches/uli-zc-async/src/waeup/kofa/students/browser.py

    r9209 r9211  
    4343from waeup.kofa.interfaces import (
    4444    IKofaObject, IUserAccount, IExtFileStore, IPasswordValidator, IContactForm,
    45     IKofaUtils, IUniversity, IObjectHistory)
     45    IKofaUtils, IUniversity)
    4646from waeup.kofa.interfaces import MessageFactory as _
    4747from waeup.kofa.widgets.datewidget import (
     
    5353    IUGStudentClearance,IPGStudentClearance,
    5454    IStudentPersonal, IStudentBase, IStudentStudyCourse,
    55     IStudentStudyCourseTransfer,
    5655    IStudentAccommodation, IStudentStudyLevel,
    5756    ICourseTicket, ICourseTicketAdd, IStudentPaymentsContainer,
    58     IStudentOnlinePayment, IStudentPreviousPayment,
    59     IBedTicket, IStudentsUtils, IStudentRequestPW
     57    IStudentOnlinePayment, IBedTicket, IStudentsUtils, IStudentRequestPW
    6058    )
    6159from waeup.kofa.students.catalog import search
    6260from 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)
    6562from waeup.kofa.students.studylevel import StudentStudyLevel, CourseTicket
    6663from waeup.kofa.students.vocabularies import StudyLevelSource
     
    6865from waeup.kofa.hostels.hostel import NOT_OCCUPIED
    6966from waeup.kofa.utils.helpers import get_current_principal, to_timezone
    70 from waeup.kofa.mandates.mandate import PasswordMandate
    7167
    7268grok.context(IKofaObject) # Make IKofaObject the default context
     
    9591    return
    9692
    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.mandatory
    102         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_dict
    109 
    11093class StudentsBreadcrumb(Breadcrumb):
    11194    """A breadcrumb for the students container.
     
    133116    """
    134117    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')
    141119
    142120class PaymentsBreadcrumb(Breadcrumb):
     
    301279    grok.require('waeup.viewStudent')
    302280    grok.template('basepage')
    303     form_fields = grok.AutoFields(IStudentBase).omit('password', 'suspended')
     281    form_fields = grok.AutoFields(IStudentBase).omit('password')
    304282    pnav = 4
    305283
    306284    @property
    307285    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',
    312287            mapping = {'a':self.context.display_fullname})
    313288
     
    317292            return _('set')
    318293        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')
    325294
    326295class ContactStudentForm(ContactAdminForm):
     
    361330        return
    362331
    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     @property
    374     def label(self):
    375         portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
    376         return translate(_('Admission Letter of'),
    377             'waeup.kofa', target_language=portal_language) \
    378             + ' %s' % self.context.display_fullname
    379 
    380     def render(self):
    381         students_utils = getUtility(IStudentsUtils)
    382         return students_utils.renderPDFAdmissionLetter(self,
    383             self.context.student)
    384 
    385332class StudentBaseManageFormPage(KofaEditFormPage):
    386333    """ View to manage student base data
     
    389336    grok.name('manage_base')
    390337    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')
    393339    grok.template('basemanagepage')
    394340    label = _('Manage base data')
     
    416362        allowed_transitions = [t for t in self.wf_info.getManualTransitions()
    417363            if not t[0].startswith('pay')]
    418         if self.context.is_postgrad:
    419             allowed_transitions = [t for t in allowed_transitions
    420                 if not t[0] in FORBIDDEN_POSTGRAD_TRANS]
    421364        return [dict(name='', title=_('No transition'))] +[
    422365            dict(name=x, title=y) for x, y in allowed_transitions]
     
    453396        return
    454397
    455 class StudentActivatePage(UtilityView, grok.View):
    456     """ Activate student account
    457     """
    458     grok.context(IStudent)
    459     grok.name('activate')
    460     grok.require('waeup.manageStudent')
    461 
    462     def update(self):
    463         self.context.suspended = False
    464         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         return
    470 
    471     def render(self):
    472         return
    473 
    474 class StudentDeactivatePage(UtilityView, grok.View):
    475     """ Deactivate student account
    476     """
    477     grok.context(IStudent)
    478     grok.name('deactivate')
    479     grok.require('waeup.manageStudent')
    480 
    481     def update(self):
    482         self.context.suspended = True
    483         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         return
    489 
    490     def render(self):
    491         return
    492 
    493398class StudentClearanceDisplayFormPage(KofaDisplayFormPage):
    494399    """ Page to display student clearance data
     
    506411    def form_fields(self):
    507412        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')
    513416        return form_fields
    514417
     
    529432    def form_fields(self):
    530433        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')
    536437        return form_fields
    537438
     
    545446    def label(self):
    546447        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
    547         return translate(_('Clearance Slip of'),
     448        return translate(_('Clearance Slip of '),
    548449            'waeup.kofa', target_language=portal_language) \
    549450            + ' %s' % self.context.display_fullname
    550451
    551     def _signatures(self):
    552         if self.context.state == CLEARED:
    553             return (_('Student Signature'), _('Clearance Officer Signature'))
    554         return
    555 
    556452    def render(self):
    557         studentview = StudentBasePDFFormPage(self.context.student,
     453        studentview = StudentBaseDisplayFormPage(self.context.student,
    558454            self.request)
    559455        students_utils = getUtility(IStudentsUtils)
    560456        return students_utils.renderPDF(
    561457            self, 'clearance.pdf',
    562             self.context.student, studentview, signatures=self._signatures())
     458            self.context.student, studentview)
    563459
    564460class StudentClearanceManageFormPage(KofaEditFormPage):
     
    579475    def form_fields(self):
    580476        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)
    584480        return form_fields
    585481
     
    661557            mapping = {'a':self.context.display_fullname})
    662558
    663 class StudentPersonalManageFormPage(KofaEditFormPage):
    664     """ Page to manage personal data
     559class StudentPersonalEditFormPage(KofaEditFormPage):
     560    """ Page to edit personal data
    665561    """
    666562    grok.context(IStudent)
    667     grok.name('manage_personal')
    668     grok.require('waeup.manageStudent')
     563    grok.name('edit_personal')
     564    grok.require('waeup.handleStudent')
    669565    form_fields = grok.AutoFields(IStudentPersonal)
    670     label = _('Manage personal data')
     566    label = _('Edit personal data')
    671567    pnav = 4
    672568
     
    676572        return
    677573
    678 class StudentPersonalEditFormPage(StudentPersonalManageFormPage):
    679     """ Page to edit personal data
    680     """
    681     grok.name('edit_personal')
    682     grok.require('waeup.handleStudent')
    683     label = _('Edit personal data')
    684     pnav = 4
    685 
    686574class StudyCourseDisplayFormPage(KofaDisplayFormPage):
    687575    """ Page to display the student study course data
     
    690578    grok.name('index')
    691579    grok.require('waeup.viewStudent')
     580    form_fields = grok.AutoFields(IStudentStudyCourse)
    692581    grok.template('studycoursepage')
    693582    pnav = 4
    694583
    695584    @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_fields
    703 
    704     @property
    705585    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})
    712588
    713589    @property
     
    730606        return
    731607
    732     @property
    733     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         return
    748 
    749608class StudyCourseManageFormPage(KofaEditFormPage):
    750609    """ Page to edit the student study course data
     
    754613    grok.require('waeup.manageStudent')
    755614    grok.template('studycoursemanagepage')
     615    form_fields = grok.AutoFields(IStudentStudyCourse)
    756616    label = _('Manage study course')
    757617    pnav = 4
     
    760620    tabthreeactions = [_('Add study level')]
    761621
    762     @property
    763     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_fields
    770 
    771622    def update(self):
    772         if not self.context.is_current:
    773             emit_lock_message(self)
    774             return
    775623        super(StudyCourseManageFormPage, self).update()
    776624        tabs.need()
     
    837685        return
    838686
    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 = 4
    849 
    850     def update(self):
    851         super(StudentTransferFormPage, self).update()
    852         warning.need()
    853         return
    854 
    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         return
    867 
    868687class StudyLevelDisplayFormPage(KofaDisplayFormPage):
    869688    """ Page to display student study levels
     
    873692    grok.require('waeup.viewStudent')
    874693    form_fields = grok.AutoFields(IStudentStudyLevel)
    875     form_fields[
    876         'validation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
    877694    grok.template('studylevelpage')
    878695    pnav = 4
     
    885702    @property
    886703    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
    888714
    889715    @property
     
    945771        Mand = translate(_('Mand.'), 'waeup.kofa', target_language=portal_language)
    946772        Score = translate(_('Score'), 'waeup.kofa', target_language=portal_language)
    947         studentview = StudentBasePDFFormPage(self.context.student,
     773        studentview = StudentBaseDisplayFormPage(self.context.student,
    948774            self.request)
    949775        students_utils = getUtility(IStudentsUtils)
     
    970796    grok.require('waeup.manageStudent')
    971797    grok.template('studylevelmanagepage')
    972     form_fields = grok.AutoFields(IStudentStudyLevel).omit(
    973         'validation_date', 'validated_by')
     798    form_fields = grok.AutoFields(IStudentStudyLevel)
    974799    pnav = 4
    975800    taboneactions = [_('Save'),_('Cancel')]
     
    978803
    979804    def update(self):
    980         if not self.context.__parent__.is_current:
    981             emit_lock_message(self)
    982             return
    983805        super(StudyLevelManageFormPage, self).update()
    984806        tabs.need()
     
    991813        datatable.need()
    992814        return
    993 
    994     @property
    995     def translated_values(self):
    996         return translated_values(self)
    997815
    998816    @property
     
    1043861
    1044862    def update(self):
    1045         if not self.context.__parent__.is_current:
    1046             emit_lock_message(self)
    1047             return
    1048863        if str(self.context.__parent__.current_level) != self.context.__name__:
    1049864            self.flash(_('This level does not correspond current level.'))
     
    1068883
    1069884    def update(self):
    1070         if not self.context.__parent__.is_current:
    1071             emit_lock_message(self)
    1072             return
    1073885        if str(self.context.__parent__.current_level) != self.context.__name__:
    1074886            self.flash(_('This level does not correspond current level.'))
     
    1106918    pnav = 4
    1107919
    1108     def update(self):
    1109         if not self.context.__parent__.is_current:
    1110             emit_lock_message(self)
    1111             return
    1112         super(CourseTicketAddFormPage, self).update()
    1113         return
    1114 
    1115920    @action(_('Add course ticket'))
    1116921    def addCourseTicket(self, **data):
     
    1119924        ticket.automatic = False
    1120925        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
    1121933        try:
    1122             self.context.addCourseTicket(ticket, course)
     934            self.context.addCourseTicket(ticket)
    1123935        except KeyError:
    1124936            self.flash(_('The ticket exists.'))
     
    12181030                mapping = {'a': ', '.join(deleted)}))
    12191031            self.context.writeLogMessage(
    1220                 self,'removed: %s' % ', '.join(deleted))
     1032                self,'removed: % s' % ', '.join(deleted))
    12211033        self.redirect(self.url(self.context))
    12221034        return
     
    12401052    def createTicket(self, **data):
    12411053        p_category = data['p_category']
    1242         previous_session = data.get('p_session', None)
    1243         previous_level = data.get('p_level', None)
    12441054        student = self.context.__parent__
    12451055        if p_category == 'bed_allocation' and student[
     
    12521062                return
    12531063        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)
    12561065        if error is not None:
    12571066            self.flash(error)
    1258             if 'previous session' in error:
    1259                 self.redirect(self.url(self.context) + '/@@addpp')
    1260                 return
    12611067            self.redirect(self.url(self.context))
    12621068            return
     
    12651071        self.redirect(self.url(self.context))
    12661072        return
    1267 
    1268 class PreviousPaymentAddFormPage(OnlinePaymentAddFormPage):
    1269     """ Page to add an online payment ticket for previous sessions
    1270     """
    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 = 4
    12781073
    12791074class OnlinePaymentDisplayFormPage(KofaDisplayFormPage):
     
    13541149        #    self.redirect(self.url(self.context))
    13551150        #    return
    1356         studentview = StudentBasePDFFormPage(self.context.student,
     1151        studentview = StudentBaseDisplayFormPage(self.context.student,
    13571152            self.request)
    13581153        students_utils = getUtility(IStudentsUtils)
     
    14311226    buttonname = _('Create bed ticket')
    14321227    notice = ''
    1433     with_ac = True
    14341228
    14351229    def update(self, SUBMIT=None):
     
    14721266            self.redirect(self.url(self.context))
    14731267            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)
    14771270        if SUBMIT is None:
    14781271            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
    14851277        # Search and book bed
    14861278        cat = queryUtility(ICatalog, name='beds_catalog', default=None)
     
    14881280            owner=(student.student_id,student.student_id))
    14891281        if len(entries):
    1490             # If bed space has been manually allocated use this bed
     1282            # If bed space has bee manually allocated use this bed
    14911283            bed = [entry for entry in entries][0]
    14921284        else:
     
    15041296                    mapping = {'a':acc_details['bt']}))
    15051297                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.'))
    15101309                return
    1511             else:
    1512                 comment = _(u'invalidated')
    1513                 # Here we know that the ac is in state initialized so we do not
    1514                 # expect an exception, but the owner might be different
    1515                 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                     return
    15191310        # Create bed ticket
    15201311        bedticket = createObject(u'waeup.BedTicket')
    1521         if self.with_ac:
    1522             bedticket.booking_code = pin
     1312        bedticket.booking_code = pin
    15231313        bedticket.booking_session = acc_details['booking_session']
    15241314        bedticket.bed_type = acc_details['bt']
    15251315        bedticket.bed = bed
    15261316        hall_title = bed.__parent__.hostel_name
    1527         coordinates = bed.coordinates[1:]
     1317        coordinates = bed.getBedCoordinates()[1:]
    15281318        block, room_nr, bed_nr = coordinates
    15291319        bc = _('${a}, Block ${b}, Room ${c}, Bed ${d} (${e})', mapping = {
     
    15481338    grok.require('waeup.handleAccommodation')
    15491339    form_fields = grok.AutoFields(IBedTicket)
    1550     form_fields['booking_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
    15511340    pnav = 4
    15521341
     
    15751364    def label(self):
    15761365        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: '),
    15811367            'waeup.kofa', target_language=portal_language) \
    1582             + ' %s' % self.context.getSessionString()
     1368            + ' %s' % self.context.bed_coordinates
    15831369
    15841370    def render(self):
    1585         studentview = StudentBasePDFFormPage(self.context.student,
     1371        studentview = StudentBaseDisplayFormPage(self.context.student,
    15861372            self.request)
    15871373        students_utils = getUtility(IStudentsUtils)
     
    16451431        self.context.bed = new_bed
    16461432        hall_title = new_bed.__parent__.hostel_name
    1647         coordinates = new_bed.coordinates[1:]
     1433        coordinates = new_bed.getBedCoordinates()[1:]
    16481434        block, room_nr, bed_nr = coordinates
    16491435        bc = _('${a}, Block ${b}, Room ${c}, Bed ${d} (${e})', mapping = {
     
    17831569            self.flash(_('Activation code is invalid.'))
    17841570            return
     1571        # Mark pin as used (this also fires a pin related transition)
     1572        # and fire transition start_clearance
    17851573        if code.state == USED:
    17861574            self.flash(_('Activation code has already been used.'))
    17871575            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
    17971584        IWorkflowInfo(self.context).fireTransition('start_clearance')
    17981585        self.flash(_('Clearance process has been started.'))
     
    18111598    def form_fields(self):
    18121599        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')
    18181603        return form_fields
    18191604
     
    18421627            return
    18431628        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'))
    18591630        return
    18601631
     
    18761647            return
    18771648        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:
    18791650            self.flash(_("This isn't your CLR access code."))
    18801651            return
    18811652        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
    18821655        if state != CLEARANCE:
    1883             # This shouldn't happen, but the application officer
    1884             # might have forgotten to lock the form after changing the state
    18851656            self.flash(_('This form cannot be submitted. Wrong state!'))
    18861657            return
     
    19021673
    19031674    def update(self, SUBMIT=None):
    1904         if not self.context.is_current:
    1905             emit_lock_message(self)
    1906             return
    1907         super(StartSessionPage, self).update()
    19081675        if not self.context.next_session_allowed:
    19091676            self.flash(_("You are not entitled to start session."))
     
    19631730
    19641731    def update(self):
    1965         if not self.context.is_current:
    1966             emit_lock_message(self)
    1967             return
    19681732        if self.context.student.state != PAID:
    19691733            emit_lock_message(self)
     
    19981762
    19991763    def update(self):
    2000         if not self.context.__parent__.is_current:
    2001             emit_lock_message(self)
    2002             return
    20031764        if self.context.student.state != PAID:
    20041765            emit_lock_message(self)
     
    20151776        level_title = translate(self.context.level_title, 'waeup.kofa',
    20161777            target_language=lang)
    2017         return _('Edit course list of ${a}',
     1778        return _('Add and remove course tickets of study level ${a}',
    20181779            mapping = {'a':level_title})
    20191780
     
    20241785            total_credits += val.credits
    20251786        return total_credits
    2026 
    2027     @property
    2028     def translated_values(self):
    2029         return translated_values(self)
    20301787
    20311788    @action(_('Add course ticket'))
     
    20901847        ticket = createObject(u'waeup.CourseTicket')
    20911848        course = data['course']
     1849        for name in ['code', 'title', 'credits', 'passmark', 'semester']:
     1850            setattr(ticket, name, getattr(course, name))
    20921851        ticket.automatic = False
    2093         ticket.carry_over = False
    20941852        try:
    2095             self.context.addCourseTicket(ticket, course)
     1853            self.context.addCourseTicket(ticket)
    20961854        except KeyError:
    20971855            self.flash(_('The ticket exists.'))
     
    21691927    grok.template('requestpw')
    21701928    form_fields = grok.AutoFields(IStudentRequestPW).select(
    2171         'firstname','number','email')
     1929        'firstname','reg_number','email')
    21721930    label = _('Request password for first-time login')
    21731931
     
    21901948        return True
    21911949
    2192     @action(_('Send login credentials to email address'), style='primary')
     1950    @action(_('Get login credentials'), style='primary')
    21931951    def get_credentials(self, **data):
    21941952        if not self.captcha_result.is_valid:
     
    21961954            # No need to flash something.
    21971955            return
    2198         number = data.get('number','')
     1956        reg_number = data.get('reg_number','')
    21991957        firstname = data.get('firstname','')
    22001958        cat = getUtility(ICatalog, name='students_catalog')
    22011959        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)))
    22061961        if results:
    22071962            student = results[0]
     
    22291984        kofa_utils = getUtility(IKofaUtils)
    22301985        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)
    22361987        # 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')
    22401989        msg = _('You have successfully requested a password for the')
    22411990        if kofa_utils.sendCredentials(IUserAccount(student),
    2242             password, url_info, msg):
     1991            password, login_url, msg):
    22431992            email_sent = student.email
    22441993        else:
     
    22461995        self._redirect(email=email_sent, password=password,
    22471996            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))
    22511997        return
    22521998
Note: See TracChangeset for help on using the changeset viewer.