## $Id$ ## ## Copyright (C) 2012 Uli Fouquet & Henrik Bettermann ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ## """Components representing and aggregating school grades. """ import grok from zope.formlib.interfaces import IInputWidget, IDisplayWidget from zope.publisher.interfaces.browser import IBrowserRequest from zope.schema.fieldproperty import FieldProperty from zope.schema import Object from waeup.kofa.interfaces import IResultEntry, IResultEntryField from waeup.kofa.widgets.objectwidget import ( KofaObjectWidget, KofaObjectDisplayWidget ) class ResultEntry(grok.Model): """A result entry contains a subject and a grade. """ grok.implements(IResultEntry) subject = FieldProperty(IResultEntry['subject']) grade = FieldProperty(IResultEntry['grade']) class ResultEntryField(Object): """A zope.schema-like field for usage in interfaces. If you want to define an interface containing result entries, you can do so like this:: class IMyInterface(Interface): my_result_entry = ResultEntryField() Default widgets are registered to render result entry fields. """ grok.implements(IResultEntryField) def __init__(self, **kw): super(ResultEntryField, self).__init__(IResultEntry, **kw) return # register KofaObjectWidgets as default widgets for IResultEntryFields @grok.adapter(IResultEntryField, IBrowserRequest) @grok.implementer(IInputWidget) def result_entry_input_widget(obj, req): return KofaObjectWidget(obj, req, ResultEntry) # register a display widget for IResultEntryFields @grok.adapter(IResultEntryField, IBrowserRequest) @grok.implementer(IDisplayWidget) def result_entry_display_widget(obj, req): return KofaObjectDisplayWidget(obj, req, ResultEntry)