source: main/waeup.sirp/trunk/src/waeup/sirp/students/container.py @ 6835

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

Add removedStudentHandler which logs if a student has been removed.

  • Property svn:keywords set to Id
File size: 3.6 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"""
17Containers for students.
18"""
19import grok
20import os
21from zope.component.interfaces import IFactory
[6681]22from zope.securitypolicy.interfaces import IPrincipalRoleManager
[6830]23from hurry.workflow.interfaces import IWorkflowInfo
[6679]24from waeup.sirp.interfaces import IUserAccount
[6633]25from waeup.sirp.students.interfaces import (
[6635]26    IStudentsContainer, IStudent, IStudentPayments, IStudentAccommodation)
[6633]27from waeup.sirp.students.studycourse import StudentStudyCourse
[6635]28from waeup.sirp.students.payments import StudentPayments
29from waeup.sirp.students.accommodation import StudentAccommodation
[6637]30from waeup.sirp.utils.helpers import get_current_principal
31from waeup.sirp.utils.logger import Logger
[6621]32
[6637]33class StudentsContainer(grok.Container, Logger):
[6621]34    """
35    The node containing the student models
36    """
37
38    grok.implements(IStudentsContainer)
39
40    def archive(self, id=None):
41        raise NotImplementedError()
42
43    def clear(self, id=None, archive=True):
44        raise NotImplementedError()
45
[6633]46    def addStudent(self, student):
47        """Add a student with subcontainers.
48        """
49        if not IStudent.providedBy(student):
[6663]50            raise TypeError(
51                'StudentsContainers contain only IStudent instances')
[6695]52        student.clearance_locked = True
[6633]53        self[student.student_id] = student
54        studycourse = StudentStudyCourse()
55        self[student.student_id]['studycourse'] = studycourse
[6635]56        payments = StudentPayments()
57        self[student.student_id]['payments'] = payments
58        accommodation = StudentAccommodation()
59        self[student.student_id]['accommodation'] = accommodation
[6681]60        # Assign global student role for new student
[6679]61        account = IUserAccount(student)
[6684]62        account.roles = ['waeup.Student']
[6681]63        # Assign local StudentRecordOwner role
64        role_manager = IPrincipalRoleManager(self[student.student_id])
65        role_manager.assignRoleToPrincipal(
66            'waeup.local.StudentRecordOwner', student.student_id)
[6652]67        # Return student_id (only needed in tests)
[6830]68        IWorkflowInfo(self[student.student_id]).fireTransition('create')
[6652]69        return student.student_id
[6637]70
71    logger_name = 'waeup.sirp.${sitename}.students'
72    logger_filename = 'students.log'
73
[6644]74    def logger_info(self, ob_class, target, comment=None):
[6637]75        """Get the logger's info method.
76        """
77        user = get_current_principal()
78        if user is None:
79            user = 'system'
80        else:
81            user = user.id
82        self.logger.info('%s - %s - %s - %s' % (
[6644]83                user, ob_class, target, comment))
[6637]84        return
[6832]85
86@grok.subscribe(IStudent, grok.IObjectRemovedEvent)
87def removedStudentHandler(student, event):
88    """If a student is removed a message is logged.
89    """
90    comment = 'Student record removed'
91    user = get_current_principal().id
92    target = student.student_id
93    grok.getSite()['students'].logger.info('%s - %s - %s' % (
94        user, target, comment))
Note: See TracBrowser for help on using the repository browser.