[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 | """ |
---|
| 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 |
---|
[6637] | 23 | from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState |
---|
| 24 | from waeup.sirp.interfaces import IObjectHistory |
---|
[6621] | 25 | from waeup.sirp.students.interfaces import IStudent |
---|
| 26 | from waeup.sirp.utils.helpers import attrs_to_fields |
---|
| 27 | |
---|
| 28 | class Student(grok.Container): |
---|
| 29 | """This is a student container for the various objects |
---|
| 30 | owned by students. |
---|
| 31 | """ |
---|
| 32 | grok.implements(IStudent) |
---|
| 33 | grok.provides(IStudent) |
---|
| 34 | |
---|
| 35 | def __init__(self): |
---|
| 36 | super(Student, self).__init__() |
---|
[6637] | 37 | IWorkflowInfo(self).fireTransition('create') |
---|
[6621] | 38 | return |
---|
| 39 | |
---|
[6637] | 40 | def loggerInfo(self, ob_class, comment=None): |
---|
| 41 | target = self.__name__ |
---|
| 42 | return grok.getSite()['students'].logger_info(ob_class,target,comment) |
---|
| 43 | |
---|
| 44 | @property |
---|
| 45 | def state(self): |
---|
| 46 | state = IWorkflowState(self).getState() |
---|
| 47 | return state |
---|
| 48 | |
---|
| 49 | @property |
---|
| 50 | def history(self): |
---|
| 51 | history = IObjectHistory(self) |
---|
| 52 | return history |
---|
| 53 | |
---|
[6621] | 54 | # Set all attributes of Student required in IStudent as field |
---|
| 55 | # properties. Doing this, we do not have to set initial attributes |
---|
| 56 | # ourselves and as a bonus we get free validation when an attribute is |
---|
| 57 | # set. |
---|
| 58 | Student = attrs_to_fields(Student) |
---|
| 59 | |
---|
| 60 | class StudentFactory(grok.GlobalUtility): |
---|
| 61 | """A factory for students. |
---|
| 62 | """ |
---|
| 63 | grok.implements(IFactory) |
---|
| 64 | grok.name(u'waeup.Student') |
---|
| 65 | title = u"Create a new student.", |
---|
| 66 | description = u"This factory instantiates new student instances." |
---|
| 67 | |
---|
| 68 | def __call__(self, *args, **kw): |
---|
| 69 | return Student() |
---|
| 70 | |
---|
| 71 | def getInterfaces(self): |
---|
| 72 | return implementedBy(Student) |
---|