source: main/waeup.aaue/trunk/src/waeup/aaue/students/studylevel.py @ 13043

Last change on this file since 13043 was 13036, checked in by Henrik Bettermann, 10 years ago

Activate and customize late course registration payment. Fresh students can register without restriction.

  • Property svn:keywords set to Id
File size: 4.1 KB
RevLine 
[8326]1## $Id: studylevel.py 13036 2015-06-05 14:35:19Z henrik $
2##
3## Copyright (C) 2012 Uli Fouquet & Henrik Bettermann
4## This program is free software; you can redistribute it and/or modify
5## it under the terms of the GNU General Public License as published by
6## the Free Software Foundation; either version 2 of the License, or
7## (at your option) any later version.
8##
9## This program is distributed in the hope that it will be useful,
10## but WITHOUT ANY WARRANTY; without even the implied warranty of
11## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12## GNU General Public License for more details.
13##
14## You should have received a copy of the GNU General Public License
15## along with this program; if not, write to the Free Software
16## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17##
18"""
19Container which holds the data of a student study level
20and contains the course tickets.
21"""
22import grok
[13036]23import pytz
24from datetime import datetime
[8326]25from zope.component.interfaces import IFactory
[9502]26from zope.component import createObject
[8326]27from zope.interface import implementedBy
28from waeup.kofa.utils.helpers import attrs_to_fields
[13036]29from waeup.kofa.interfaces import CREATED
[8326]30from waeup.kofa.students.studylevel import (
31    StudentStudyLevel, CourseTicket,
32    CourseTicketFactory, StudentStudyLevelFactory)
[8867]33from waeup.kofa.students.interfaces import IStudentNavigation
[8444]34from waeup.aaue.students.interfaces import (
[8867]35    ICustomStudentStudyLevel, ICustomCourseTicket)
[8326]36
37
38class CustomStudentStudyLevel(StudentStudyLevel):
39    """This is a container for course tickets.
40    """
41    grok.implements(ICustomStudentStudyLevel, IStudentNavigation)
42    grok.provides(ICustomStudentStudyLevel)
43
[9914]44    @property
45    def total_credits_s1(self):
46        total = 0
47        for ticket in self.values():
48            if ticket.semester == 1:
49                total += ticket.credits
50        return total
51
52    @property
53    def total_credits_s2(self):
54        total = 0
55        for ticket in self.values():
56            if ticket.semester == 2:
57                total += ticket.credits
58        return total
59
[10443]60    @property
[10480]61    def gpa_params_rectified(self):
62        return self.gpa_params
[10443]63
[13036]64    @property
65    def course_registration_allowed(self):
66        if self.student.is_fresh:
67            return True
68        try:
69            deadline = grok.getSite()['configuration'][
70                    str(self.level_session)].coursereg_deadline
71        except TypeError, KeyError:
72            return True
73        payment_made = False
74        if len(self.student['payments']):
75            for ticket in self.student['payments'].values():
76                if ticket.p_category == 'late_registration' and \
77                    ticket.p_session == self.level_session and \
78                    ticket.p_state == 'paid':
79                        payment_made = True
80        if deadline and deadline < datetime.now(pytz.utc) and not payment_made:
81            return False
82        return True
83
[9692]84CustomStudentStudyLevel = attrs_to_fields(
[9914]85    CustomStudentStudyLevel, omit=[
[10480]86    'total_credits', 'total_credits_s1', 'total_credits_s2', 'gpa'])
[8326]87
88class CustomStudentStudyLevelFactory(StudentStudyLevelFactory):
89    """A factory for student study levels.
90    """
91
92    def __call__(self, *args, **kw):
93        return CustomStudentStudyLevel()
94
95    def getInterfaces(self):
96        return implementedBy(CustomStudentStudyLevel)
97
98class CustomCourseTicket(CourseTicket):
99    """This is a course ticket which allows the
100    student to attend the course. Lecturers will enter scores and more at
101    the end of the term.
102
103    A course ticket contains a copy of the original course and
104    course referrer data. If the courses and/or their referrers are removed, the
105    corresponding tickets remain unchanged. So we do not need any event
106    triggered actions on course tickets.
107    """
108    grok.implements(ICustomCourseTicket, IStudentNavigation)
109    grok.provides(ICustomCourseTicket)
110
111CustomCourseTicket = attrs_to_fields(CustomCourseTicket)
112
113class CustomCourseTicketFactory(CourseTicketFactory):
114    """A factory for student study levels.
115    """
116
117    def __call__(self, *args, **kw):
118        return CustomCourseTicket()
119
120    def getInterfaces(self):
121        return implementedBy(CustomCourseTicket)
Note: See TracBrowser for help on using the repository browser.