source: main/waeup.kofa/branches/uli-zc-async/src/waeup/kofa/university/course.py @ 10687

Last change on this file since 10687 was 9211, checked in by uli, 12 years ago

Rollback r9209. Looks like multiple merges from trunk confuse svn when merging back into trunk.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.7 KB
Line 
1## $Id: course.py 9211 2012-09-21 08:19:35Z uli $
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.kofa.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.