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

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

Fire transition after student has been added. Otherwise we don't see the student id in the logfile.

  • Property svn:keywords set to Id
File size: 3.3 KB
Line 
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
22from zope.securitypolicy.interfaces import IPrincipalRoleManager
23from hurry.workflow.interfaces import IWorkflowInfo
24from waeup.sirp.interfaces import IUserAccount
25from waeup.sirp.students.interfaces import (
26    IStudentsContainer, IStudent, IStudentPayments, IStudentAccommodation)
27from waeup.sirp.students.studycourse import StudentStudyCourse
28from waeup.sirp.students.payments import StudentPayments
29from waeup.sirp.students.accommodation import StudentAccommodation
30from waeup.sirp.utils.helpers import get_current_principal
31from waeup.sirp.utils.logger import Logger
32
33class StudentsContainer(grok.Container, Logger):
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
46    def addStudent(self, student):
47        """Add a student with subcontainers.
48        """
49        if not IStudent.providedBy(student):
50            raise TypeError(
51                'StudentsContainers contain only IStudent instances')
52        student.clearance_locked = True
53        self[student.student_id] = student
54        studycourse = StudentStudyCourse()
55        self[student.student_id]['studycourse'] = studycourse
56        payments = StudentPayments()
57        self[student.student_id]['payments'] = payments
58        accommodation = StudentAccommodation()
59        self[student.student_id]['accommodation'] = accommodation
60        # Assign global student role for new student
61        account = IUserAccount(student)
62        account.roles = ['waeup.Student']
63        # Assign local StudentRecordOwner role
64        role_manager = IPrincipalRoleManager(self[student.student_id])
65        role_manager.assignRoleToPrincipal(
66            'waeup.local.StudentRecordOwner', student.student_id)
67        # Return student_id (only needed in tests)
68        IWorkflowInfo(self[student.student_id]).fireTransition('create')
69        return student.student_id
70
71    logger_name = 'waeup.sirp.${sitename}.students'
72    logger_filename = 'students.log'
73
74    def logger_info(self, ob_class, target, comment=None):
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' % (
83                user, ob_class, target, comment))
84        return
Note: See TracBrowser for help on using the repository browser.