Ignore:
Timestamp:
24 May 2019, 09:11:40 (5 years ago)
Author:
Henrik Bettermann
Message:

Implement course result validation workflow for lecturers.

File:
1 edited

Legend:

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

    r15419 r15422  
    3333from zope.schema.interfaces import ConstraintNotSatisfied, RequiredMissing
    3434from zope.security import checkPermission
     35from zope.securitypolicy.interfaces import IPrincipalRoleManager
    3536from waeup.kofa.accesscodes import invalidate_accesscode, get_access_code
    3637from waeup.kofa.accesscodes.workflow import USED
     
    33793380        return
    33803381
    3381 
    33823382class EditScoresPage(KofaPage):
    33833383    """Page that allows to edit batches of scores.
     
    34643464        return True
    34653465
     3466    def _validate_results(self, form):
     3467        ob_class = self.__implemented__.__name__.replace('waeup.kofa.', '')
     3468        user = get_current_principal()
     3469        if user is None:
     3470            usertitle = 'system'
     3471        else:
     3472            usertitle = getattr(user, 'public_name', None)
     3473            if not usertitle:
     3474                usertitle = user.title
     3475        self.context.results_validated_by = usertitle
     3476        self.context.results_validation_date = datetime.utcnow()
     3477        self.context.results_validation_session = self.current_academic_session
     3478        return
     3479
     3480    def _results_editable(self, results_validation_session,
     3481                         current_academic_session):
     3482        user = get_current_principal()
     3483        prm = IPrincipalRoleManager(self.context)
     3484        roles = [x[0] for x in prm.getRolesForPrincipal(user.id)]
     3485        if 'waeup.local.LocalStudentsManager' in roles:
     3486            return True
     3487        if results_validation_session \
     3488            and results_validation_session >= current_academic_session:
     3489            return False
     3490        return True
     3491
    34663492    def update(self,  *args, **kw):
    34673493        form = self.request.form
     
    34763502            self.redirect(self.url(self.context))
    34773503            return
     3504        vs = self.context.results_validation_session
     3505        if not self._results_editable(vs, self.current_academic_session):
     3506            self.flash(
     3507                _('Course results have already been '
     3508                  'validated and can no longer be changed.'),
     3509                type="danger")
     3510            self.redirect(self.url(self.context))
     3511            return
    34783512        self.session_title = academic_sessions_vocab.getTerm(
    34793513            self.current_academic_session).title
     
    34853519        self.editable_tickets = [
    34863520            ticket for ticket in self.tickets if ticket.editable_by_lecturer]
    3487         if not 'UPDATE_TABLE' in form and not 'UPDATE_FILE' in form:
     3521        if not 'UPDATE_TABLE' in form and not 'UPDATE_FILE' in form\
     3522            and not 'VALIDATE_RESULTS' in form:
     3523            return
     3524        if 'VALIDATE_RESULTS' in form:
     3525            if vs and vs >= self.current_academic_session:
     3526                self.flash(
     3527                    _('Course results have already been validated.'),
     3528                    type="danger")
     3529                return
     3530            self._validate_results(form)
     3531            self.flash(_('You successfully validated the course results.'))
     3532            self.redirect(self.url(self.context))
    34883533            return
    34893534        if not self.editable_tickets:
     
    34943539        return
    34953540
    3496 
    34973541class DownloadScoresView(UtilityView, grok.View):
    34983542    """View that exports scores.
     
    35013545    grok.require('waeup.editScores')
    35023546    grok.name('download_scores')
     3547
     3548    def _results_editable(self, results_validation_session,
     3549                         current_academic_session):
     3550        user = get_current_principal()
     3551        prm = IPrincipalRoleManager(self.context)
     3552        roles = [x[0] for x in prm.getRolesForPrincipal(user.id)]
     3553        if 'waeup.local.LocalStudentsManager' in roles:
     3554            return True
     3555        if results_validation_session \
     3556            and results_validation_session >= current_academic_session:
     3557            return False
     3558        return True
    35033559
    35043560    def update(self):
     
    35113567        if not self.current_academic_session:
    35123568            self.flash(_('Current academic session not set.'), type="warning")
     3569            self.redirect(self.url(self.context))
     3570            return
     3571        vs = self.context.results_validation_session
     3572        if not self._results_editable(vs, self.current_academic_session):
     3573            self.flash(
     3574                _('Course results have already been '
     3575                  'validated and can no longer be changed.'),
     3576                type="danger")
    35133577            self.redirect(self.url(self.context))
    35143578            return
     
    35373601    grok.context(ICourse)
    35383602    grok.name('coursetickets.pdf')
    3539     grok.require('waeup.editScores')
     3603    grok.require('waeup.showStudents')
    35403604
    35413605    @property
Note: See TracChangeset for help on using the changeset viewer.