source: main/waeup.kofa/trunk/src/waeup/kofa/students/studylevel.py @ 8335

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

When using catalogs existing objects must not necessarily be in the same container.

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