source: main/waeup.kofa/branches/uli-async-update/src/waeup/kofa/students/studylevel.py @ 10009

Last change on this file since 10009 was 9169, checked in by uli, 12 years ago

Merge changes from trunk, r8786-HEAD

  • Property svn:keywords set to Id
File size: 5.2 KB
RevLine 
[7191]1## $Id: studylevel.py 9169 2012-09-10 11:05:07Z uli $
2##
[6775]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
[7536]23from zope.component.interfaces import IFactory
[8330]24from zope.interface import implementedBy
[7811]25from waeup.kofa.students.interfaces import (
[6781]26    IStudentStudyLevel, IStudentNavigation, ICourseTicket)
[7811]27from waeup.kofa.utils.helpers import attrs_to_fields
28from waeup.kofa.students.vocabularies import StudyLevelSource
[6775]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        return
40
[8736]41    @property
42    def student(self):
43        try:
44            return self.__parent__.__parent__
45        except AttributeError:
46            return None
[6775]47
[8735]48    def writeLogMessage(self, view, message):
49        return self.__parent__.__parent__.writeLogMessage(view, message)
50
[6775]51    @property
52    def level_title(self):
53        studylevelsource = StudyLevelSource()
54        return studylevelsource.factory.getTitle(self.__parent__, self.level)
55
[9169]56    def addCourseTicket(self, ticket, course):
[6781]57        """Add a course ticket object.
58        """
[9169]59        if not ICourseTicket.providedBy(ticket):
[6781]60            raise TypeError(
61                'StudentStudyLeves contain only ICourseTicket instances')
[9169]62        ticket.code = course.code
63        ticket.title = course.title
64        ticket.fcode = course.__parent__.__parent__.__parent__.code
65        ticket.dcode = course.__parent__.__parent__.code
66        ticket.credits = course.credits
67        ticket.passmark = course.passmark
68        ticket.semester = course.semester
69        self[ticket.code] = ticket
[6781]70        return
71
72StudentStudyLevel = attrs_to_fields(StudentStudyLevel)
73
[7536]74class StudentStudyLevelFactory(grok.GlobalUtility):
75    """A factory for student study levels.
76    """
77    grok.implements(IFactory)
78    grok.name(u'waeup.StudentStudyLevel')
79    title = u"Create a new student study level.",
80    description = u"This factory instantiates new student study level instances."
81
82    def __call__(self, *args, **kw):
83        return StudentStudyLevel()
84
85    def getInterfaces(self):
86        return implementedBy(StudentStudyLevel)
87
[6781]88class CourseTicket(grok.Model):
89    """This is a course ticket which allows the
90    student to attend the course. Lecturers will enter scores and more at
91    the end of the term.
[6783]92
93    A course ticket contains a copy of the original course and
[9169]94    certificate course data. If the courses and/or the referrin certificate
95    courses are removed, the corresponding tickets remain unchanged.
96    So we do not need any event
[6783]97    triggered actions on course tickets.
[6781]98    """
99    grok.implements(ICourseTicket, IStudentNavigation)
100    grok.provides(ICourseTicket)
101
[6795]102    def __init__(self):
[6781]103        super(CourseTicket, self).__init__()
[6795]104        self.code = None
105        self.title = None
[7304]106        self.fcode = None
107        self.dcode = None
[6795]108        self.credits = None
109        self.passmark = None
110        self.semester = None
[6781]111        return
112
[8736]113    @property
114    def student(self):
[8338]115        """Get the associated student object.
116        """
117        try:
118            return self.__parent__.__parent__.__parent__
119        except AttributeError:
120            return None
[6781]121
[8735]122    def writeLogMessage(self, view, message):
123        return self.__parent__.__parent__.__parent__.writeLogMessage(view, message)
124
[7633]125    def getLevel(self):
126        """Returns the id of the level the ticket has been added to.
127        """
[8338]128        # XXX: shouldn't that be an attribute?
129        try:
130            return self.__parent__.level
131        except AttributeError:
132            return None
[7633]133
134    def getLevelSession(self):
135        """Returns the session of the level the ticket has been added to.
136        """
[8338]137        # XXX: shouldn't that be an attribute?
138        try:
139            return self.__parent__.level_session
140        except AttributeError:
141            return None
[7633]142
143
[6782]144CourseTicket = attrs_to_fields(CourseTicket)
[7548]145
146class CourseTicketFactory(grok.GlobalUtility):
147    """A factory for student study levels.
148    """
149    grok.implements(IFactory)
150    grok.name(u'waeup.CourseTicket')
151    title = u"Create a new course ticket.",
152    description = u"This factory instantiates new course ticket instances."
153
154    def __call__(self, *args, **kw):
155        return CourseTicket()
156
157    def getInterfaces(self):
158        return implementedBy(CourseTicket)
Note: See TracBrowser for help on using the repository browser.