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