[7191] | 1 | ## $Id: studycourse.py 7191 2011-11-25 07:13:22Z henrik $ |
---|
| 2 | ## |
---|
[6633] | 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 | """ |
---|
| 19 | Container which holds the data of the student study courses |
---|
| 20 | and contains the (student) study level objects. |
---|
| 21 | """ |
---|
| 22 | import grok |
---|
| 23 | from grok import index |
---|
| 24 | from zope.component.interfaces import IFactory |
---|
[6815] | 25 | from zope.securitypolicy.interfaces import IPrincipalRoleManager |
---|
[6642] | 26 | from waeup.sirp.students.interfaces import ( |
---|
[6774] | 27 | IStudentStudyCourse, IStudentNavigation, IStudentStudyLevel) |
---|
[6782] | 28 | from waeup.sirp.students.studylevel import CourseTicket |
---|
[6633] | 29 | from waeup.sirp.utils.helpers import attrs_to_fields |
---|
| 30 | |
---|
| 31 | class StudentStudyCourse(grok.Container): |
---|
| 32 | """This is a container for study levels. |
---|
| 33 | """ |
---|
[6642] | 34 | grok.implements(IStudentStudyCourse, IStudentNavigation) |
---|
[6633] | 35 | grok.provides(IStudentStudyCourse) |
---|
| 36 | |
---|
| 37 | def __init__(self): |
---|
| 38 | super(StudentStudyCourse, self).__init__() |
---|
| 39 | return |
---|
| 40 | |
---|
[6642] | 41 | def getStudent(self): |
---|
| 42 | return self.__parent__ |
---|
| 43 | |
---|
[6782] | 44 | def addStudentStudyLevel(self, cert, studylevel): |
---|
[6774] | 45 | """Add a study level object. |
---|
| 46 | """ |
---|
| 47 | if not IStudentStudyLevel.providedBy(studylevel): |
---|
| 48 | raise TypeError( |
---|
| 49 | 'StudentStudyCourses contain only IStudentStudyLevel instances') |
---|
[6775] | 50 | self[str(studylevel.level)] = studylevel |
---|
[6782] | 51 | |
---|
| 52 | #Create course tickets automatically |
---|
| 53 | for key, val in cert.items(): |
---|
[6791] | 54 | if val.level != studylevel.level: |
---|
| 55 | continue |
---|
[6795] | 56 | ticket = CourseTicket() |
---|
| 57 | ticket.code = val.getCourseCode() |
---|
[6802] | 58 | ticket.automatic = True |
---|
[6795] | 59 | ticket.core_or_elective = val.core_or_elective |
---|
| 60 | ticket.title = val.course.title |
---|
| 61 | ticket.faculty = val.course.__parent__.__parent__.__parent__.title |
---|
| 62 | ticket.department = val.course.__parent__.__parent__.title |
---|
| 63 | ticket.credits = val.course.credits |
---|
| 64 | ticket.passmark = val.course.passmark |
---|
| 65 | ticket.semester = val.course.semester |
---|
[6782] | 66 | self[str(studylevel.level)][val.getCourseCode()] = ticket |
---|
[6774] | 67 | return |
---|
| 68 | |
---|
[6815] | 69 | StudentStudyCourse = attrs_to_fields(StudentStudyCourse) |
---|
| 70 | |
---|
[6822] | 71 | class StudentStudyCourseFactory(grok.GlobalUtility): |
---|
| 72 | """A factory for students. |
---|
| 73 | """ |
---|
| 74 | grok.implements(IFactory) |
---|
| 75 | grok.name(u'waeup.StudentStudyCourse') |
---|
| 76 | title = u"Create a new student study course.", |
---|
| 77 | description = u"This factory instantiates new student study course instances." |
---|
| 78 | |
---|
| 79 | def __call__(self, *args, **kw): |
---|
| 80 | return StudentStudyCourse() |
---|
| 81 | |
---|
| 82 | def getInterfaces(self): |
---|
| 83 | return implementedBy(StudentStudyCourse) |
---|