Re: [Zope3-Users] Reusing Widgets

2009-02-05 Thread Tim Cook
Hi Christian,

Thanks for the tips.

On Thu, 2009-02-05 at 08:30 -0600, Christian Lück wrote:

> But before, you should think about your schema again. It looks very 
> complicated to me. 

Many here and on the Grok list have suggested that I simplify the
schema.  However,  the class and attribute names MUST comply with these
specs: http://www.openehr.org/releases/1.0.2/roadmap.html 

I'm sure that the Dv ... classes will be turned into subclasses of Field
at some point soon. 



> 
> 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.

The actual data that is assigned to these attributes come from one of
thousands of sources.  This is a reference model, not the actual data
definition.

> > class DvText(TextLine):
> > """
> >blah blah!
> 
> Write unittests instead of blahs. If you don't manage, improve your data 
> modell!

The blah blah was just because I deleted A LOT of stuff because it
wasn't germane to the email. :-)

Thanks again,
Tim




signature.asc
Description: This is a digitally signed message part
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Reusing Widgets

2009-02-05 Thread Carsten Senger
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

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Reusing Widgets

2009-02-05 Thread Christian Lück
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"),
>  

[Zope3-Users] Reusing Widgets

2009-02-04 Thread Tim Cook
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.

**
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
)

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
)

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
** 



<>

signature.asc
Description: This is a digitally signed message part
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users