source: main/waeup.sirp/trunk/src/waeup/sirp/students/studylevel.py @ 8062

Last change on this file since 8062 was 7633, checked in by Henrik Bettermann, 13 years ago

Add catalogs (indexes) for payments and course tickets.

  • Property svn:keywords set to Id
File size: 4.2 KB
Line 
1## $Id: studylevel.py 7633 2012-02-11 23:02:24Z henrik $
2##
3## Copyright (C) 2011 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
23from zope.component.interfaces import IFactory
24from waeup.sirp.students.interfaces import (
25    IStudentStudyLevel, IStudentNavigation, ICourseTicket)
26from waeup.sirp.utils.helpers import attrs_to_fields
27from waeup.sirp.students.vocabularies import StudyLevelSource
28
29class StudentStudyLevel(grok.Container):
30    """This is a container for course tickets.
31    """
32    grok.implements(IStudentStudyLevel, IStudentNavigation)
33    grok.provides(IStudentStudyLevel)
34
35    def __init__(self):
36        super(StudentStudyLevel, self).__init__()
37        self.level = None
38        self.validation_date = None
39        self.validated_by = None
40        return
41
42    def getStudent(self):
43        return self.__parent__.__parent__
44
45    @property
46    def level_title(self):
47        studylevelsource = StudyLevelSource()
48        return studylevelsource.factory.getTitle(self.__parent__, self.level)
49
50    def addCourseTicket(self, courseticket):
51        """Add a course ticket object.
52        """
53        if not ICourseTicket.providedBy(courseticket):
54            raise TypeError(
55                'StudentStudyLeves contain only ICourseTicket instances')
56        self[courseticket.code] = courseticket
57        return
58
59StudentStudyLevel = attrs_to_fields(StudentStudyLevel)
60
61class StudentStudyLevelFactory(grok.GlobalUtility):
62    """A factory for student study levels.
63    """
64    grok.implements(IFactory)
65    grok.name(u'waeup.StudentStudyLevel')
66    title = u"Create a new student study level.",
67    description = u"This factory instantiates new student study level instances."
68
69    def __call__(self, *args, **kw):
70        return StudentStudyLevel()
71
72    def getInterfaces(self):
73        return implementedBy(StudentStudyLevel)
74
75class CourseTicket(grok.Model):
76    """This is a course ticket which allows the
77    student to attend the course. Lecturers will enter scores and more at
78    the end of the term.
79
80    A course ticket contains a copy of the original course and
81    course referrer data. If the courses and/or their referrers are removed, the
82    corresponding tickets remain unchanged. So we do not need any event
83    triggered actions on course tickets.
84    """
85    grok.implements(ICourseTicket, IStudentNavigation)
86    grok.provides(ICourseTicket)
87
88    def __init__(self):
89        super(CourseTicket, self).__init__()
90        self.code = None
91        self.title = None
92        self.fcode = None
93        self.dcode = None
94        self.credits = None
95        self.passmark = None
96        self.semester = None
97        return
98
99    def getStudent(self):
100        return self.__parent__.__parent__.__parent__
101
102    def getLevel(self):
103        """Returns the id of the level the ticket has been added to.
104        """
105        return self.__parent__.level
106
107    def getLevelSession(self):
108        """Returns the session of the level the ticket has been added to.
109        """
110        return self.__parent__.level_session
111
112
113CourseTicket = attrs_to_fields(CourseTicket)
114
115class CourseTicketFactory(grok.GlobalUtility):
116    """A factory for student study levels.
117    """
118    grok.implements(IFactory)
119    grok.name(u'waeup.CourseTicket')
120    title = u"Create a new course ticket.",
121    description = u"This factory instantiates new course ticket instances."
122
123    def __call__(self, *args, **kw):
124        return CourseTicket()
125
126    def getInterfaces(self):
127        return implementedBy(CourseTicket)
Note: See TracBrowser for help on using the repository browser.