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