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