[7191] | 1 | ## $Id: studycourse.py 8337 2012-05-04 09:07:18Z uli $ |
---|
| 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 zope.component.interfaces import IFactory |
---|
[8325] | 24 | from zope.component import createObject |
---|
[7256] | 25 | from zope.interface import implementedBy |
---|
[7811] | 26 | from waeup.kofa.students.interfaces import ( |
---|
[6774] | 27 | IStudentStudyCourse, IStudentNavigation, IStudentStudyLevel) |
---|
[7811] | 28 | from waeup.kofa.students.studylevel import CourseTicket |
---|
| 29 | from waeup.kofa.utils.helpers import attrs_to_fields |
---|
[6633] | 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 | |
---|
[8323] | 44 | @property |
---|
| 45 | def may_register(self): |
---|
| 46 | return True |
---|
| 47 | |
---|
[6782] | 48 | def addStudentStudyLevel(self, cert, studylevel): |
---|
[6774] | 49 | """Add a study level object. |
---|
| 50 | """ |
---|
| 51 | if not IStudentStudyLevel.providedBy(studylevel): |
---|
| 52 | raise TypeError( |
---|
| 53 | 'StudentStudyCourses contain only IStudentStudyLevel instances') |
---|
[6775] | 54 | self[str(studylevel.level)] = studylevel |
---|
[6782] | 55 | |
---|
| 56 | #Create course tickets automatically |
---|
[7533] | 57 | if cert is not None: |
---|
| 58 | for key, val in cert.items(): |
---|
| 59 | if val.level != studylevel.level: |
---|
| 60 | continue |
---|
[8325] | 61 | ticket = createObject(u'waeup.CourseTicket') |
---|
[7533] | 62 | ticket.code = val.getCourseCode() |
---|
| 63 | ticket.automatic = True |
---|
[7665] | 64 | ticket.mandatory = val.mandatory |
---|
[7533] | 65 | ticket.title = val.course.title |
---|
| 66 | ticket.fcode = val.course.__parent__.__parent__.__parent__.code |
---|
| 67 | ticket.dcode = val.course.__parent__.__parent__.code |
---|
| 68 | ticket.credits = val.course.credits |
---|
| 69 | ticket.passmark = val.course.passmark |
---|
| 70 | ticket.semester = val.course.semester |
---|
[8141] | 71 | ticket.carry_over = False |
---|
[7661] | 72 | self[str(studylevel.level)][ticket.code] = ticket |
---|
| 73 | # Collect carry-over courses in base levels (not in repeating levels) |
---|
[7664] | 74 | try: |
---|
| 75 | co_enabled = grok.getSite()['configuration'].carry_over |
---|
| 76 | except TypeError: |
---|
| 77 | # In tests we might not have a site object |
---|
| 78 | co_enabled = True |
---|
[8337] | 79 | if not co_enabled or studylevel.level % 100 != 0: |
---|
| 80 | return |
---|
| 81 | levels = sorted(self.keys()) |
---|
| 82 | index = levels.index(str(studylevel.level)) |
---|
| 83 | if index <= 0: |
---|
| 84 | return |
---|
| 85 | previous_level = self[levels[index-1]] |
---|
| 86 | for key, val in previous_level.items(): |
---|
| 87 | if val.score >= val.passmark: |
---|
| 88 | continue |
---|
| 89 | if key in self[str(studylevel.level)]: |
---|
| 90 | # Carry-over ticket exists |
---|
| 91 | continue |
---|
| 92 | co_ticket = createObject(u'waeup.CourseTicket') |
---|
| 93 | for name in ['code', 'title', 'credits', 'passmark', |
---|
| 94 | 'semester', 'mandatory', 'fcode', 'dcode']: |
---|
| 95 | setattr(co_ticket, name, getattr(val, name)) |
---|
| 96 | co_ticket.automatic = True |
---|
| 97 | co_ticket.carry_over = True |
---|
| 98 | self[str(studylevel.level)][co_ticket.code] = co_ticket |
---|
[6774] | 99 | return |
---|
| 100 | |
---|
[6815] | 101 | StudentStudyCourse = attrs_to_fields(StudentStudyCourse) |
---|
| 102 | |
---|
[6822] | 103 | class StudentStudyCourseFactory(grok.GlobalUtility): |
---|
[7536] | 104 | """A factory for student study courses. |
---|
[6822] | 105 | """ |
---|
| 106 | grok.implements(IFactory) |
---|
| 107 | grok.name(u'waeup.StudentStudyCourse') |
---|
| 108 | title = u"Create a new student study course.", |
---|
| 109 | description = u"This factory instantiates new student study course instances." |
---|
| 110 | |
---|
| 111 | def __call__(self, *args, **kw): |
---|
| 112 | return StudentStudyCourse() |
---|
| 113 | |
---|
| 114 | def getInterfaces(self): |
---|
[7811] | 115 | return implementedBy(StudentStudyCourse) |
---|