[Grok-dev] five.grok (was: 0.14 todo list)
Sylvain Viollon
sylvain at infrae.com
Thu Jul 31 05:04:48 EDT 2008
On Thu, 31 Jul 2008 09:47:12 +0100
Martin Aspeli <optilude at gmx.net> wrote:
> Hi Sylvain,
>
Hello,
> >> Mmmm.... is there any documentation on how to use this in plain
> >> Zope 2 (or Plone)? I'm getting confused by Silva stuff. ;-)
> >>
> >
> > Not, really, but that's easy. In a meta.zcml somewhere, add an:
>
> Excellent!
>
> > <include package="five.grok" file="meta.zcml" />
> > <include package="five.grok" />
>
> What's the relationship between five.grok and grokcore.view? Is the
> latter a dependency on the former?
>
five.grok is a bunch of changes for Zope 2, and yes,
grokcore.{view,component} are dependencies of five.grok.
> > In the package where your view is, add to the configure.zcml:
> >
> > <grok:grok package=".wheremyviewis" />
> >
> > And your view will be something like:
> >
> > import five.grok
> >
> > class MyView(five.grok.View):
> >
> > five.grok.context(IMyContent)
> > five.grok.name(u"test.html")
>
> Would it work to use the context() and name() directives from
> grokcore.view instead of five.grok?
>
Yes, they are just imported in five.grok, if I remember correctly.
It's just that's better to have one import instead of two.
> > def render(self):
> > return u"Hello World"
> >
> >
> > That's it. After you have the same rules than in Grok for templates,
> > and so on.
>
> Are these documented anywhere?
>
I think in grok documentation. The rule is unless you used the
templatedir directive in module to configure a different template
directory, if a view don't define a render method, a template named
with the name of your view class in lower case is search in a directory
which have the same name than your python module (in lower case as well
I think).
So if your view is in wheremyviewis.py, the template
wheremyviewis/myview.pt is going to be used if you remove the render
method above.
> > Forms are more complex, since you need to build a mixin with Five:
> >
> > from grokcore.formlib.components import GrokForm
> > from grokcore.formlib import action
> >
> > class PageForm(GrokForm, formbase.PageForm, five.grok.View):
> >
> > five.grok.context(IMyContent)
> > five.grok.name(u"edit.html")
> >
> > @action(u"Test me")
> > def action_test(self, **data):
> > self.status = "Tested"
> >
> >
> > Don't forget to include in the configure.zcml grokcore.formlib.
>
> Cool! I'm more interested in a z3c.form version, though. Is anyone
> working on that? If not, I would be interested to figure out how to
> do that.
>
Yes, I am currently trying to do that. We need the support of
plone.z3cform (it will act like formbase of Five for formlib). I
discussed of that yesterday with Daniel, and he removed all CMF
specifics parts from plone.z3cform (I am building it for Silva, and I
don't want CMF).
Basically, we have to build a grokker which create the form_fields
attribute like for formlib, wrap actions ... We will have to register
the form to the ZCA as view wrapped with the form_wrapper provided in
plone.z3cform.
> > Security can be done with grokcore.security.require ...
>
> Cool! Does that take IPermission utility names? Or Zope 2 permission
> strings?
>
You can give either Grok permission object, or Zope 3 permission
title: 'zope.Public' for instance.
> Thanks again!
>
> Martin
>
Sylvain,
--
Sylvain Viollon -- Infrae
t +31 10 243 7051 -- http://infrae.com
Hoevestraat 10 3033GC Rotterdam -- The Netherlands
More information about the Grok-dev
mailing list