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

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

Exception errors must be a tuple.

  • Property svn:keywords set to Id
File size: 4.2 KB
Line 
1## $Id: studylevel.py 13071 2015-06-17 05:10:20Z 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
23import pytz
24from datetime import datetime
25from zope.component.interfaces import IFactory
26from zope.component import createObject
27from zope.interface import implementedBy
28from waeup.kofa.utils.helpers import attrs_to_fields
29from waeup.kofa.interfaces import CREATED
30from waeup.kofa.students.studylevel import (
31    StudentStudyLevel, CourseTicket,
32    CourseTicketFactory, StudentStudyLevelFactory)
33from waeup.kofa.students.interfaces import IStudentNavigation
34from waeup.aaue.students.interfaces import (
35    ICustomStudentStudyLevel, ICustomCourseTicket)
36
37
38class CustomStudentStudyLevel(StudentStudyLevel):
39    """This is a container for course tickets.
40    """
41    grok.implements(ICustomStudentStudyLevel, IStudentNavigation)
42    grok.provides(ICustomStudentStudyLevel)
43
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
60    @property
61    def gpa_params_rectified(self):
62        return self.gpa_params
63
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        if not deadline or deadline > datetime.now(pytz.utc):
74            return True
75        payment_made = False
76        if len(self.student['payments']):
77            for ticket in self.student['payments'].values():
78                if ticket.p_category == 'late_registration' and \
79                    ticket.p_session == self.level_session and \
80                    ticket.p_state == 'paid':
81                        payment_made = True
82        if payment_made:
83            return True
84        return False
85
86CustomStudentStudyLevel = attrs_to_fields(
87    CustomStudentStudyLevel, omit=[
88    'total_credits', 'total_credits_s1', 'total_credits_s2', 'gpa'])
89
90class CustomStudentStudyLevelFactory(StudentStudyLevelFactory):
91    """A factory for student study levels.
92    """
93
94    def __call__(self, *args, **kw):
95        return CustomStudentStudyLevel()
96
97    def getInterfaces(self):
98        return implementedBy(CustomStudentStudyLevel)
99
100class CustomCourseTicket(CourseTicket):
101    """This is a course ticket which allows the
102    student to attend the course. Lecturers will enter scores and more at
103    the end of the term.
104
105    A course ticket contains a copy of the original course and
106    course referrer data. If the courses and/or their referrers are removed, the
107    corresponding tickets remain unchanged. So we do not need any event
108    triggered actions on course tickets.
109    """
110    grok.implements(ICustomCourseTicket, IStudentNavigation)
111    grok.provides(ICustomCourseTicket)
112
113CustomCourseTicket = attrs_to_fields(CustomCourseTicket)
114
115class CustomCourseTicketFactory(CourseTicketFactory):
116    """A factory for student study levels.
117    """
118
119    def __call__(self, *args, **kw):
120        return CustomCourseTicket()
121
122    def getInterfaces(self):
123        return implementedBy(CustomCourseTicket)
Note: See TracBrowser for help on using the repository browser.