Ignore:
Timestamp:
6 Aug 2013, 20:32:53 (11 years ago)
Author:
Henrik Bettermann
Message:

Add pages and buttons for transcript request processing. Work in progress, tests will follow!

File:
1 edited

Legend:

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

    r10440 r10458  
    2020import sys
    2121import grok
     22import pytz
    2223from urllib import urlencode
    2324from datetime import datetime
     
    6465from waeup.kofa.university.vocabularies import course_levels
    6566from waeup.kofa.utils.batching import VirtualExportJobContainer
    66 from waeup.kofa.utils.helpers import get_current_principal, to_timezone
     67from waeup.kofa.utils.helpers import get_current_principal, to_timezone, now
    6768from waeup.kofa.widgets.restwidget import ReSTDisplayWidget
    6869from waeup.kofa.students.interfaces import (
     
    7475    ICourseTicket, ICourseTicketAdd, IStudentPaymentsContainer,
    7576    IStudentOnlinePayment, IStudentPreviousPayment, IStudentBalancePayment,
    76     IBedTicket, IStudentsUtils, IStudentRequestPW
     77    IBedTicket, IStudentsUtils, IStudentRequestPW, IStudentTranscript
    7778    )
    7879from waeup.kofa.students.catalog import search, StudentQueryResultItem
     
    8283from waeup.kofa.students.workflow import (CREATED, ADMITTED, PAID,
    8384    CLEARANCE, REQUESTED, RETURNING, CLEARED, REGISTERED, VALIDATED,
    84     FORBIDDEN_POSTGRAD_TRANS)
     85    GRADUATED, TRANSCRIPT, FORBIDDEN_POSTGRAD_TRANS)
    8586
    8687
     
    10611062                self,'removed: %s' % ', '.join(deleted))
    10621063        self.redirect(self.url(self.context, u'@@manage')+'?tab2')
     1064        return
     1065
     1066class StudentRequestTranscriptPage(KofaPage):
     1067    """ Page to transcript by student
     1068    """
     1069    grok.context(IStudent)
     1070    grok.name('request_transcript')
     1071    grok.require('waeup.handleStudent')
     1072    grok.template('requesttranscript')
     1073    label = _('Request transcript')
     1074    ac_prefix = 'TSC'
     1075    notice = ''
     1076    pnav = 4
     1077    buttonname = _('Request transcript now')
     1078    with_ac = True
     1079
     1080    def update(self, SUBMIT=None):
     1081        if not self.context.state == GRADUATED:
     1082            self.flash(_("Wrong state"))
     1083            self.redirect(self.url(self.context))
     1084            return
     1085        if self.with_ac:
     1086            self.ac_series = self.request.form.get('ac_series', None)
     1087            self.ac_number = self.request.form.get('ac_number', None)
     1088        if self.context.transcript_comment is not None:
     1089            self.correspondence = self.context.transcript_comment.replace(
     1090                '\n', '<br>')
     1091        else:
     1092            self.correspondence = ''
     1093        if SUBMIT is None:
     1094            return
     1095        if self.with_ac:
     1096            pin = '%s-%s-%s' % (self.ac_prefix, self.ac_series, self.ac_number)
     1097            code = get_access_code(pin)
     1098            if not code:
     1099                self.flash(_('Activation code is invalid.'))
     1100                return
     1101            if code.state == USED:
     1102                self.flash(_('Activation code has already been used.'))
     1103                return
     1104            # Mark pin as used (this also fires a pin related transition)
     1105            # and fire transition start_clearance
     1106            comment = _(u"invalidated")
     1107            # Here we know that the ac is in state initialized so we do not
     1108            # expect an exception, but the owner might be different
     1109            if not invalidate_accesscode(pin, comment, self.context.student_id):
     1110                self.flash(_('You are not the owner of this access code.'))
     1111                return
     1112            self.context.clr_code = pin
     1113        IWorkflowInfo(self.context).fireTransition('request_transcript')
     1114        comment = self.request.form.get('comment', '').replace('\r', '')
     1115        address = self.request.form.get('address', '').replace('\r', '')
     1116        tz = getattr(queryUtility(IKofaUtils), 'tzinfo', pytz.utc)
     1117        today = now(tz).strftime('%d/%m/%Y %H:%M:%S %Z')
     1118        old_transcript_comment = self.context.transcript_comment
     1119        if old_transcript_comment == None:
     1120            old_transcript_comment = ''
     1121        self.context.transcript_comment = '''On %s %s wrote:
     1122
     1123%s
     1124
     1125Dispatch Address:
     1126%s
     1127
     1128%s''' % (today, self.request.principal.id, comment, address,
     1129         old_transcript_comment)
     1130        self.context.writeLogMessage(
     1131            self, 'comment: %s' % comment.replace('\n', '<br>'))
     1132        self.flash(_('Transcript processing has been started.'))
     1133        self.redirect(self.url(self.context))
     1134        return
     1135
     1136class StudentRequestTranscriptManageFormPage(KofaEditFormPage):
     1137    """ Page to edit personal data by student
     1138    """
     1139    grok.context(IStudent)
     1140    grok.name('manage_transcript_request')
     1141    grok.require('waeup.manageStudent')
     1142    form_fields = grok.AutoFields(IStudentTranscript)
     1143    label = _('Manage transcript request')
     1144    pnav = 4
     1145
     1146    def update(self):
     1147        super(StudentRequestTranscriptManageFormPage, self).update()
     1148        if self.context.state != TRANSCRIPT:
     1149            self.flash(_("Wrong state"))
     1150            self.redirect(self.url(self.context))
     1151        return
     1152
     1153    #@action(_('Save'), style='primary')
     1154    #def save(self, **data):
     1155    #    msave(self, **data)
     1156    #    return
     1157
     1158    @action(_('Save comment and mark as processed'), style='primary')
     1159    def process(self, **data):
     1160        if self.context.state == TRANSCRIPT:
     1161            IWorkflowInfo(self.context).fireTransition('process_transcript')
     1162            message = _('Transcript request processed.')
     1163            self.flash(message)
     1164        else:
     1165            self.flash(_('Student is in wrong state.'))
     1166            self.redirect(self.url(self.context))
     1167            return
     1168        self.applyData(self.context, **data)
     1169        comment = data['transcript_comment']
     1170        if comment:
     1171            self.context.writeLogMessage(
     1172                self, 'comment: %s' %
     1173                comment.replace('\r\n', '<br>'))
     1174            args = {'subject':message, 'body':comment}
     1175        else:
     1176            args = {'subject':message,}
     1177        self.redirect(self.url(self.context) +
     1178            '/contactstudent?%s' % urlencode(args))
    10631179        return
    10641180
Note: See TracChangeset for help on using the changeset viewer.