[Zope3-dev] Re: a plan for widgets?

Jeff Shell eucci.group at gmail.com
Thu Mar 16 22:06:11 EST 2006


On 3/16/06, Tres Seaver <tseaver at palladion.com> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Martijn Faassen wrote:
>
> <snip>
>
> > * sources and terms are nice, but we should at least provide some basic
> > sources and register some basic terms for them; that bit is completely
> > missing in Zope 3 right now. People should be able to at make a simple
> > drop-down widget happen without having to figure out how to tie all
> > these components together - they should just import and use the right
> > source, perhaps import, use, and register the right term, and there they
> > go.

Um. Straight up sources are pretty easy, especially when you use terms
directly. We have a few Choice (and our own 'RelaxedChoice') fields in
one application that get their values, at present, from tuples in a
``values.py`` file. ``values=values.area_codes``. Works fine for
straight and simple sources.

The problem I have with vocabularies is, ahem, the vocabulary. "they
should just import and use the right source, perhaps import, use, and
register the right term, and there they go"... what? As I mention
below, I've ultimately started to find Vocabularies very useful. But I
also found them incredibly daunting with a surprisingly high entry
barrier. Terms, Tokens, Titles, deferred vocabulary loading and
binding, direct vocabulary-field binding, the vocabulary registry
(versus the Utility registry), the different vocabulary registry set
up in zope.app, ... It's been hard to control and understand. And
especially (strangely) hard to learn by interaction in the Python
interpreter.

> <zcml:ktupema_necro_halogo>
>
> Hmm, another case where high-level ZCML support would be useful:
> defining simple terms for a vocabulary.  Why should somebody who wants
> to tweak a vocabulary have to edit software?  E.g.:
>
>  <vocabulary name="philosophers">
>   <term id="plato">Plato</term>
>   <term id="aristotle">Aristotle</term>
>   <term id="kant">Immanuel Kant</term>
>  </vocabulary>
>
> Of course, we could also keep the vocabularies in another data file, and
> merely have the high-level directive "source" it:
>
>  <zope:vocabulary
>     name="philosophers"
>     file="philosophers.csv"
>     />
>
> </zcml:ktupema_necro_halogo>


If - and only if - and really really really really really only if -
you mean to do this, fix the HELL up the vocabulary registration
stuff. That's where most of my time got lost when I had that debugging
session the other week that pissed me off to no end about ZCML. I have
no idea how I fixed my situation either.

By the way, isn't it pretty easy to provide straight up values anyways
for those quick drop-down situations?

    trip_type = zope.schema.Choice(
        title=_(u"Trip Type"),
        description=_(u"Trip Type"),
        default=u"Business",
        required=True,
        values=(u"Business", u"Personal"),
        )

replacementOptions = SimpleVocabulary((
    SimpleTerm(value='none', title='No - keep all current articles'),
    SimpleTerm(value='matching', title='Only replace matching IDs'),
    SimpleTerm(value='all', title='Yes - replace all existing articles'),
    ))
class ImportSchema(Interface):
    importfile = zope.schema.Bytes(
        title=u"Import Zip File",
        description=u"Zipe file of items to import.",
        required=True,
        )

    replace = zope.schema.Choice(
        title=u"Replace existing articles?",
        vocabulary=replacementOptions,
        default='none',
        )

class ImportArticlesForm(form.Form):
    ...
    @form.action(u"Import Articles", failure='handleFailure')
    def importArticles(self, action, data):
        replace = data['replace']
        zipped = self.openZip(data['importfile'])
        if replace == 'all':
            self.clearExistingArticles()
        ...

Maybe someday I'll force us at Bottlerocket to make the time for me to
at least put up a version of my knowledge base app so I can publish
recipes I put up on the mailing list. I think that a lot of the easy /
relatively easy aspects get obscured or lost. A recipe or tip for "how
do I make a simple drop down?" would be nice.


More information about the Zope3-dev mailing list