[Zope3-Users] Reusing Widgets

Carsten Senger senger at rehfisch.de
Thu Feb 5 08:15:17 EST 2009


Hi Tim,

Tim Cook schrieb:
> If I have an interface (IDvText) and a class DvText (shown below).  and
> I want it to act exactly as a zope.schema Textline (with some additional
> attributes) then is this correct and how do I (where do I find how to)
> register/add to the TextLine widget?  Apologies for the line wraps.

[...]

> class IDvText(Interface):
>     """
>     blah blah!
>     """
>     
>     value = TextLine(
>         title = _(u"Value"),
>         description = _(u"""Displayable rendition of the item,
> regardless of its underlying structure. For DV_CODED_TEXT, this is the
> rubric of the complete term as provided by the terminology service. No
> carriage returns, line feeds, or other non-printing characters
> permitted."""),
>     )

[...]

>     encoding = Object(
>         schema = ICodePhrase,
>         title = _(u"Encoding"),
>         description = _(u"""Name of character encoding scheme in which
> this value is encoded. Coded from openEHR Code Set "character sets".
> Unicode is the default assumption in openEHR, with UTF-8 being the
> assumed encoding. This attribute allows for variations from these
> assumptions."""),
>         required = False
>         )         
> 
> 
> 
> ******************************************************
> from zope.interface import implements
> from zope.i18nmessageid.message import MessageFactory
> from zope.schema import TextLine
> 
> from interfaces.dvtext import IDvText
> 
> _ = MessageFactory('oship')
> 
> 
> class DvText(TextLine):
>     """
>    blah blah!
>     """
> 
>     implements(IDvText)
>     
>     def __init__(self, value, mappings=None, formatting=None,
> hyperlink=None, language=None, encoding=None):
>         self.value = value
>         self.mappings = mappings
>         self.formatting = formatting
>         self.hyperlink = hyperlink
>         self.language = language
>         self.encoding = encoding

This does not look like you want to write a field. A schema field itself 
is not persistent on an object. The field is constructed at runtime and 
has a 'get' and a 'set' method to handle the value that should to be 
persistent on an object.
As you have a bunch of informations you store in a DvText it looks like 
it should itself be persistent, and not a field! It seems you just want 
to show specific informations about it somewhere. Can you describe what 
you want to do?

If you want to write a schema filed, it has to comply with (beside 
others) the zope.schema.interfaces.IField interface that needs some 
attributes like title, description and required that are used in a 
schema description. Then you should read the implementation of 
zope.schema._bootstrapfields.Field, .Text and .TextLine.

The registration of widgets happens in 
zope/app/form/browser/configure.zcml. Also your field should be a field, 
and it is working, the right TextLine widget should be picked up cause 
DvText say's it implements ITextLine (cause it inherits from TextLine), 
and the widget is registered for ITextLine.

..Carsten



More information about the Zope3-users mailing list