source: main/waeup.sirp/trunk/src/waeup/sirp/students/studycourse.py @ 7301

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

pyflakes

  • Property svn:keywords set to Id
File size: 3.1 KB
Line 
1## $Id: studycourse.py 7256 2011-12-03 05:46:52Z 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 the student study courses
20and contains the (student) study level objects.
21"""
22import grok
23from zope.component.interfaces import IFactory
24from zope.interface import implementedBy
25from waeup.sirp.students.interfaces import (
26    IStudentStudyCourse, IStudentNavigation, IStudentStudyLevel)
27from waeup.sirp.students.studylevel import CourseTicket
28from waeup.sirp.utils.helpers import attrs_to_fields
29
30class StudentStudyCourse(grok.Container):
31    """This is a container for study levels.
32    """
33    grok.implements(IStudentStudyCourse, IStudentNavigation)
34    grok.provides(IStudentStudyCourse)
35
36    def __init__(self):
37        super(StudentStudyCourse, self).__init__()
38        return
39
40    def getStudent(self):
41        return self.__parent__
42
43    def addStudentStudyLevel(self, cert, studylevel):
44        """Add a study level object.
45        """
46        if not IStudentStudyLevel.providedBy(studylevel):
47            raise TypeError(
48                'StudentStudyCourses contain only IStudentStudyLevel instances')
49        self[str(studylevel.level)] = studylevel
50
51        #Create course tickets automatically
52        for key, val in cert.items():
53            if val.level != studylevel.level:
54                continue
55            ticket = CourseTicket()
56            ticket.code = val.getCourseCode()
57            ticket.automatic = True
58            ticket.core_or_elective = val.core_or_elective
59            ticket.title = val.course.title
60            ticket.faculty = val.course.__parent__.__parent__.__parent__.title
61            ticket.department = val.course.__parent__.__parent__.title
62            ticket.credits = val.course.credits
63            ticket.passmark = val.course.passmark
64            ticket.semester = val.course.semester
65            self[str(studylevel.level)][val.getCourseCode()] = ticket
66        return
67
68StudentStudyCourse = attrs_to_fields(StudentStudyCourse)
69
70class StudentStudyCourseFactory(grok.GlobalUtility):
71    """A factory for students.
72    """
73    grok.implements(IFactory)
74    grok.name(u'waeup.StudentStudyCourse')
75    title = u"Create a new student study course.",
76    description = u"This factory instantiates new student study course instances."
77
78    def __call__(self, *args, **kw):
79        return StudentStudyCourse()
80
81    def getInterfaces(self):
82        return implementedBy(StudentStudyCourse)
Note: See TracBrowser for help on using the repository browser.