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

Last change on this file since 6670 was 6666, checked in by uli, 13 years ago

Make fallback student_id unicode to please interfaces.

  • Property svn:keywords set to Id
File size: 2.8 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"""
17Container for the various objects owned by students.
18"""
19import grok
20from grok import index
21from zope.component.interfaces import IFactory, ComponentLookupError
22from zope.interface import implementedBy
23from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState
24from waeup.sirp.interfaces import IObjectHistory
25from waeup.sirp.students.interfaces import IStudent, IStudentNavigation
26from waeup.sirp.utils.helpers import attrs_to_fields
27from waeup.sirp.students.utils import generate_student_id
28
29class Student(grok.Container):
30    """This is a student container for the various objects
31    owned by students.
32    """
33    grok.implements(IStudent, IStudentNavigation)
34    grok.provides(IStudent)
35
36    def __init__(self):
37        super(Student, self).__init__()
38        IWorkflowInfo(self).fireTransition('create')
39        # The catalog doesn't exist in unit tests
40        try:
41            self.student_id = generate_student_id('?')
42        except ComponentLookupError:
43            self.student_id = u'Z654321'
44        return
45
46    def loggerInfo(self, ob_class, comment=None):
47        target = self.__name__
48        return grok.getSite()['students'].logger_info(ob_class,target,comment)
49
50    @property
51    def state(self):
52        state = IWorkflowState(self).getState()
53        return state
54
55    @property
56    def history(self):
57        history = IObjectHistory(self)
58        return history
59
60    def getStudent(self):
61        return self
62
63# Set all attributes of Student required in IStudent as field
64# properties. Doing this, we do not have to set initial attributes
65# ourselves and as a bonus we get free validation when an attribute is
66# set.
67Student = attrs_to_fields(Student)
68
69class StudentFactory(grok.GlobalUtility):
70    """A factory for students.
71    """
72    grok.implements(IFactory)
73    grok.name(u'waeup.Student')
74    title = u"Create a new student.",
75    description = u"This factory instantiates new student instances."
76
77    def __call__(self, *args, **kw):
78        return Student()
79
80    def getInterfaces(self):
81        return implementedBy(Student)
Note: See TracBrowser for help on using the repository browser.