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

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

Rollback r9209. Looks like multiple merges from trunk confuse svn when merging back into trunk.

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