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