source: main/waeup.sirp/branches/ulif-schoolgrades/src/waeup/sirp/schoolgrades.py @ 7791

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

Move interface into interfaces module.

File size: 2.4 KB
Line 
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"""
20import grok
21from zope.formlib.interfaces import IInputWidget, IDisplayWidget
22from zope.publisher.interfaces.browser import IBrowserRequest
23from zope.schema.fieldproperty import FieldProperty
24from zope.schema.interfaces import IObject
25from zope.schema import Object
26from waeup.sirp.interfaces import IResultEntry, IResultEntryField
27from waeup.sirp.widgets.objectwidget import (
28    SIRPObjectWidget, SIRPObjectDisplayWidget
29    )
30
31class ResultEntry(grok.Model):
32    """A result entry contains a subject and a grade.
33    """
34    grok.implements(IResultEntry)
35    subject = FieldProperty(IResultEntry['subject'])
36    grade = FieldProperty(IResultEntry['grade'])
37
38class ResultEntryField(Object):
39    """A zope.schema-like field for usage in interfaces.
40
41    If you want to define an interface containing result entries, you
42    can do so like this::
43
44      class IMyInterface(Interface):
45          my_result_entry = ResultEntryField()
46
47    Default widgets are registered to render result entry fields.
48    """
49    grok.implements(IResultEntryField)
50
51    def __init__(self, **kw):
52        super(ResultEntryField, self).__init__(IResultEntry, **kw)
53        return
54
55# register SIRPObjectWidgets as default widgets for IResultEntryFields
56@grok.adapter(IResultEntryField, IBrowserRequest)
57@grok.implementer(IInputWidget)
58def result_entry_input_widget(obj, req):
59    return SIRPObjectWidget(obj, req, ResultEntry)
60
61# register a display widget for IResultEntryFields
62@grok.adapter(IResultEntryField, IBrowserRequest)
63@grok.implementer(IDisplayWidget)
64def result_entry_display_widget(obj, req):
65    return SIRPObjectDisplayWidget(obj, req, ResultEntry)
Note: See TracBrowser for help on using the repository browser.