[Grok-dev] change WidgetInputErrorView

Jens Adner j.adner at fh-sm.de
Tue Jul 31 10:21:18 UTC 2012


Hi to all,

I'm using grok for more then 4 years now and I'm very lucky with my app,
based on grok-1.0.

Now, I'm working on a new app based on the current grok.

All is fine and I have good results so far.

I need a little help from you, after searching the web for solutions.
And this ist my problem:

I want to use the great css-framework "yaml" in grok. yaml defines some
css-styles, an error class is one of them.

Without changing the yaml-css, I have to change the standard zope
snipped html-code (<span class="error">%s</span>'), showing as result of
an error in a input widget.
How can I change the class-attribute in the WidgetInputErrorView or
other parts?

And this is what I tried:

from zope.formlib.interfaces import IWidgetInputErrorView
from zope.interface import Invalid
from zope.i18n import translate
from cgi import escape

class MyWidgetErrorView(grok.Adapter):
    "change the class attribute"
    grok.context(Mytest)
    grok.implements(IWidgetInputErrorView) # the new interface provided

    def snippet(self):
        """Use a different class than the default zope input error view"""
        message = self.context.doc()
        translated = translate(message, context=self.request,
default=message)
        return u'<span class="form-error">%s</span>' % escape(translated)


The new class should be "form-error" or something else.
I thought that's all, but it's of course not working ;-)

Here I have not enough Knowledge of adapters oder interfaces and how
this work together. How can I this modified WidgetInputErrorview work in
my views? Is this the right way or am I completely wrong?

Kind regards from Germany
Jens


-- 
+++++ Jens Adner, Rechenzentrum der FH Schmalkalden  +++++
+++++ Fon: +49 3683688 9201  Fax: +49 3683688 989201 +++++


More information about the Grok-dev mailing list