source: main/waeup.sirp/trunk/src/waeup/sirp/students/student.py @ 6837

Last change on this file since 6837 was 6836, checked in by Henrik Bettermann, 14 years ago

Move removedStudentHandler to right place.

  • Property svn:keywords set to Id
File size: 3.4 KB
RevLine 
[6621]1## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann
2## This program is free software; you can redistribute it and/or modify
3## it under the terms of the GNU General Public License as published by
4## the Free Software Foundation; either version 2 of the License, or
5## (at your option) any later version.
6##
7## This program is distributed in the hope that it will be useful,
8## but WITHOUT ANY WARRANTY; without even the implied warranty of
9## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10## GNU General Public License for more details.
11##
12## You should have received a copy of the GNU General Public License
13## along with this program; if not, write to the Free Software
14## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15##
16"""
17Container for the various objects owned by students.
18"""
19import grok
20from grok import index
[6749]21from zope.component.interfaces import IFactory
[6621]22from zope.interface import implementedBy
[6830]23from hurry.workflow.interfaces import IWorkflowState
[6637]24from waeup.sirp.interfaces import IObjectHistory
[6694]25from waeup.sirp.students.interfaces import (
[6764]26    IStudent, IStudentNavigation, IStudentClearanceEdit,
[6695]27    IStudentPersonalEdit)
[6836]28from waeup.sirp.utils.helpers import attrs_to_fields, get_current_principal
[6651]29from waeup.sirp.students.utils import generate_student_id
[6621]30
31class Student(grok.Container):
32    """This is a student container for the various objects
33    owned by students.
34    """
[6694]35    grok.implements(IStudent, IStudentNavigation,
[6767]36        IStudentPersonalEdit, IStudentClearanceEdit)
[6621]37    grok.provides(IStudent)
38
39    def __init__(self):
40        super(Student, self).__init__()
[6749]41        # The site doesn't exist in unit tests
[6652]42        try:
[6749]43            students = grok.getSite()['students']
44            self.student_id = generate_student_id(students,'?')
45        except TypeError:
[6666]46            self.student_id = u'Z654321'
[6699]47        self.password = None
[6830]48       
[6621]49        return
50
[6637]51    def loggerInfo(self, ob_class, comment=None):
52        target = self.__name__
53        return grok.getSite()['students'].logger_info(ob_class,target,comment)
54
55    @property
56    def state(self):
57        state = IWorkflowState(self).getState()
58        return state
59
60    @property
61    def history(self):
62        history = IObjectHistory(self)
63        return history
64
[6642]65    def getStudent(self):
66        return self
67
[6814]68    @property
69    def certificate(self):
70        cert = getattr(self.get('studycourse', None), 'certificate', None)
71        return cert
72
[6621]73# Set all attributes of Student required in IStudent as field
74# properties. Doing this, we do not have to set initial attributes
75# ourselves and as a bonus we get free validation when an attribute is
76# set.
77Student = attrs_to_fields(Student)
78
79class StudentFactory(grok.GlobalUtility):
80    """A factory for students.
81    """
82    grok.implements(IFactory)
83    grok.name(u'waeup.Student')
84    title = u"Create a new student.",
85    description = u"This factory instantiates new student instances."
86
87    def __call__(self, *args, **kw):
88        return Student()
89
90    def getInterfaces(self):
91        return implementedBy(Student)
[6836]92
93@grok.subscribe(IStudent, grok.IObjectRemovedEvent)
94def removedStudentHandler(student, event):
95    """If a student is removed a message is logged.
96    """
97    comment = 'Student record removed'
98    user = get_current_principal().id
99    target = student.student_id
100    grok.getSite()['students'].logger.info('%s - %s - %s' % (
101        user, target, comment))
Note: See TracBrowser for help on using the repository browser.