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

Last change on this file since 9002 was 9002, checked in by Henrik Bettermann, 12 years ago

Add lecturer local role which has no dynamic role assignment yet.

Add test_import to CourseProcessorTests?.

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