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