[7779] | 1 | ## $Id$ |
---|
| 2 | ## |
---|
| 3 | ## Copyright (C) 2012 Uli Fouquet & Henrik Bettermann |
---|
| 4 | ## This program is free software; you can redistribute it and/or modify |
---|
| 5 | ## it under the terms of the GNU General Public License as published by |
---|
| 6 | ## the Free Software Foundation; either version 2 of the License, or |
---|
| 7 | ## (at your option) any later version. |
---|
| 8 | ## |
---|
| 9 | ## This program is distributed in the hope that it will be useful, |
---|
| 10 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 11 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 12 | ## GNU General Public License for more details. |
---|
| 13 | ## |
---|
| 14 | ## You should have received a copy of the GNU General Public License |
---|
| 15 | ## along with this program; if not, write to the Free Software |
---|
| 16 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
| 17 | ## |
---|
| 18 | """Components representing and aggregating school grades. |
---|
| 19 | """ |
---|
| 20 | import grok |
---|
[7785] | 21 | from zope.formlib.interfaces import IInputWidget, IDisplayWidget |
---|
| 22 | from zope.publisher.interfaces.browser import IBrowserRequest |
---|
[7779] | 23 | from zope.schema.fieldproperty import FieldProperty |
---|
[7785] | 24 | from zope.schema import Object |
---|
[7791] | 25 | from waeup.sirp.interfaces import IResultEntry, IResultEntryField |
---|
[7785] | 26 | from waeup.sirp.widgets.objectwidget import ( |
---|
| 27 | SIRPObjectWidget, SIRPObjectDisplayWidget |
---|
| 28 | ) |
---|
[7779] | 29 | |
---|
| 30 | class ResultEntry(grok.Model): |
---|
[7785] | 31 | """A result entry contains a subject and a grade. |
---|
[7779] | 32 | """ |
---|
| 33 | grok.implements(IResultEntry) |
---|
| 34 | subject = FieldProperty(IResultEntry['subject']) |
---|
| 35 | grade = FieldProperty(IResultEntry['grade']) |
---|
[7785] | 36 | |
---|
| 37 | class ResultEntryField(Object): |
---|
| 38 | """A zope.schema-like field for usage in interfaces. |
---|
| 39 | |
---|
| 40 | If you want to define an interface containing result entries, you |
---|
| 41 | can do so like this:: |
---|
| 42 | |
---|
| 43 | class IMyInterface(Interface): |
---|
| 44 | my_result_entry = ResultEntryField() |
---|
| 45 | |
---|
| 46 | Default widgets are registered to render result entry fields. |
---|
| 47 | """ |
---|
| 48 | grok.implements(IResultEntryField) |
---|
| 49 | |
---|
| 50 | def __init__(self, **kw): |
---|
| 51 | super(ResultEntryField, self).__init__(IResultEntry, **kw) |
---|
| 52 | return |
---|
| 53 | |
---|
| 54 | # register SIRPObjectWidgets as default widgets for IResultEntryFields |
---|
| 55 | @grok.adapter(IResultEntryField, IBrowserRequest) |
---|
| 56 | @grok.implementer(IInputWidget) |
---|
| 57 | def result_entry_input_widget(obj, req): |
---|
| 58 | return SIRPObjectWidget(obj, req, ResultEntry) |
---|
| 59 | |
---|
| 60 | # register a display widget for IResultEntryFields |
---|
| 61 | @grok.adapter(IResultEntryField, IBrowserRequest) |
---|
| 62 | @grok.implementer(IDisplayWidget) |
---|
| 63 | def result_entry_display_widget(obj, req): |
---|
| 64 | return SIRPObjectDisplayWidget(obj, req, ResultEntry) |
---|