Hi Tim, Tim Cook wrote: > 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.
Seems like you mess schema and widget. Think about schema in terms of the structure of your data only, but not in terms of forms and widgets for browser views. Then, after modelling of your data is done, think of form elements (widgets). So after you modelled your schema (as you did) the question would rather be: How do I get a textline-widget for the attribute of my class implementing my schema? Let me guess: You want to have your DvText as part of an other data modell, like class ISomeEnclosing(zope.interface.Interface): ... text = zope.schema.Object( title = u"Text", schema = IDvText(...), ) To get a textline-like widget for the 'text'-attribute you would have a subform. For the new z3c.form framework have a look at subforms.txt. http://svn.zope.org/z3c.form/trunk/src/z3c/form/subform.txt?rev=91127&view=markup Have a look at z3c.formdemo, too. For the older framework (formlib, widgets from zope.app.form) think of an object widget with a textline widget as subwidget. http://svn.zope.org/zope.app.form/trunk/src/zope/app/form/browser/objectwidget.txt?rev=80211&view=markup But before, you should think about your schema again. It looks very complicated to me. I would try to make as little use of zope.schema.Object as possible. As an alternative you could inherit from your IDvText. class ISomeEnclosing(IDvText): ... At least, try to reduce zope.schema.Object in IDvText! > > ****************************************************** > from zope.schema import TextLine,Text,List,Dict,URI,Object > from zope.i18nmessageid.message import MessageFactory > from zope.interface import Interface > > from interfaces.codephrase import ICodePhrase > from oship.openehr.rm.support.identification.interfaces.objectref import > IObjectRef > > _ = MessageFactory('oship') > > 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."""), > ) > > mappings=List( > value_type=Object(schema=IObjectRef), > title = _(u"Mappings"), > description = _(u"""A list of MappingTerm,terms from other > terminologies most closely matching this term, typically used where the > originator (e.g. pathology lab) of information uses a local > terminology but also supplies one or more equivalents from wellknown > terminologies (e.g. LOINC). The list contents should be of the type > TermMapping"""), > required = False, > ) > > formatting = Text( > title = _(u"Formatting"), > description = _(u"""A format string of the form "name:value; > name:value...", e.g. "font-weight : bold; font-family : Arial; > font-size : 12pt;". Values taken from W3C CSS2 properties lists > "background" and "font"."""), > required = False > ) Huh, that mixes content and layout/formatting. Suggestion 1) Think of a vocabulary of text types where types are defined by usage or some other non-layout but content-specific feature and then write HTML-renderers for each type. formatting = Choice( title = u"Text-Type", vocabulary = 'dvtext-types', required = True, default = 'plain', ) Suggestion 2) Subclass for each type from DvTextBase. Then write html-renderers for each type. > > hyperlink = URI( > title = _(u"Hyperlink"), > description = _(u"""Optional link sitting behind a section of > plain text or coded term item as type DvUri."""), > required = False > ) > > language = Object( > schema = ICodePhrase, > title = _(u"Language"), > description = _(u"""Optional indicator of the localised language > in which the value is written. Coded from openEHR Code Set "languages". > Only used when either the text object is in a different language from > the enclosing ENTRY, or else the text object is being used outside of an > ENTRY or other enclosing structure which indicates the language."""), > required = False > ) Think of a vocabulary! language = zope.schema.Choice( title = u"Language", vocubulary = 'openEHR-languages', required = False, ) Have a look at z3c.i18n for iso-languages. > > 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 > ) > The like! (encoding vocabulary) Better: use unicode only (how do you integrate other encodings in zope at all?) and leave this attribute away. Write converters for output with other encoding if needed. > > > ****************************************************** > 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! Write unittests instead of blahs. If you don't manage, improve your data modell! > """ > > 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 > ************************************************************** > > Regards, Christian _______________________________________________ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users