source: main/waeup.kofa/trunk/src/waeup/sirp/university/course.py @ 7807

Last change on this file since 7807 was 7333, checked in by Henrik Bettermann, 13 years ago

Rename certificatecontainer, coursecontainer and facultycontainer. Now we have e.g. a container for faculties. Synonyms are 'facultiescontainer', 'faculties', 'academics' or 'Academic Section'. The faculty container is the faculty itself which contains the departments.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.7 KB
Line 
1## $Id: course.py 7333 2011-12-12 07:01:54Z henrik $
2##
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"""Courses.
19"""
20import grok
21from zope.catalog.interfaces import ICatalog
22from zope.interface import implementedBy
23from zope.component import getUtility
24from zope.component.interfaces import IFactory, ComponentLookupError
25from waeup.sirp.university.interfaces import ICourse, ICourseAdd
26
27class Course(grok.Model):
28    """A university course.
29    """
30    grok.implements(ICourse, ICourseAdd)
31
32    def __init__(self,
33                 title=u'Unnamed Course',
34                 code=u'NA',
35                 credits=0,
36                 passmark=40,
37                 semester=1, **kw):
38        super(Course, self).__init__(**kw)
39        self.title = title
40        self.code = code
41        self.credits = credits
42        self.passmark = passmark
43        self.semester = semester
44
45    def longtitle(self):
46        return "%s (%s)" % (self.title,self.code)
47
48class CourseFactory(grok.GlobalUtility):
49    """A factory for courses.
50    """
51    grok.implements(IFactory)
52    grok.name(u'waeup.Course')
53    title = u"Create a new course.",
54    description = u"This factory instantiates new course instances."
55
56    def __call__(self, *args, **kw):
57        return Course(*args, **kw)
58
59    def getInterfaces(self):
60        return implementedBy(Course)
61
62@grok.subscribe(ICourse, grok.IObjectRemovedEvent)
63def handle_course_removed(course, event):
64    """If a course is deleted, we make sure that also referrers in a
65       certificatescontainer are removed.
66    """
67    code = course.code
68
69    # Find all certificatecourses that refer to given course...
70    try:
71        cat = getUtility(ICatalog, name='certcourses_catalog')
72    except ComponentLookupError:
73        # catalog not available. This might happen during tests.
74        return
75
76    results = cat.searchResults(course_code=(code, code))
77    for certcourse in results:
78        # Remove that referrer...
79        cert = certcourse.__parent__
80        cert.delCourseRef(code)
81        cert._p_changed = True
82    return
Note: See TracBrowser for help on using the repository browser.