New base class in Grok

View: New views
2 Messages — Rating Filter:   Alert me  

New base class in Grok

by Souheil CHELFOUH :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello Grokkers,

There's something I use a lot in zope in general : the namespace traverser.
Out of the box, Grok proposes traversers, but no namespace traversers.
What do you think, if we add it there ? I can do it, of course, just
asking to be sure people want it there.

Code would be :

class NamespaceTraverser(grok.MultiAdapter):
    grok.baseclass()
    grok.adapts(Interface, IHTTPRequest)
    grok.provides(ITraversable)

    def __init__(self, context, request):
        self.context = context
        self.request = request


    def traverse(self, name, stack):
        raise NotImplementedError('You have to implement your own method')


Actually, it would be much better to use a grok.layer and grok.context
directives, on that component.
It would make it much more pluggable.For that, we'd need to use a
grokker very similar to "TraverserGrokker" which is not reusable in
this case.
I don't know if you, guys, use a lot of Namespace Traversers, but,
it's a very convenient component and I'm definitly willing to see that
in Grok.

code with dedicated grokker, would be:

class NamespaceTraverser(grok.MultiAdapter):
    grok.baseclass()
    grok.context(Interface)
    grok.layer(IHTTPRequest)
    grok.provides(ITraversable)

    def __init__(self, context, request):
        self.context = context
        self.request = request

    def traverse(self, name, stack):
        raise NotImplementedError('You have to implement your own method')


Cheers
- Souheil
_______________________________________________
Grok-dev mailing list
Grok-dev@...
https://mail.zope.org/mailman/listinfo/grok-dev

Re: New base class in Grok

by Jan-Wijbrand Kolman-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Souheil,

Souheil CHELFOUH wrote:

> class NamespaceTraverser(grok.MultiAdapter):
>     grok.baseclass()
>     grok.adapts(Interface, IHTTPRequest)
>     grok.provides(ITraversable)
>
>     def __init__(self, context, request):
>         self.context = context
>         self.request = request
>
>
>     def traverse(self, name, stack):
>         raise NotImplementedError('You have to implement your own method')
>
>
> Actually, it would be much better to use a grok.layer and grok.context
> directives, on that component.
> It would make it much more pluggable.For that, we'd need to use a
> grokker very similar to "TraverserGrokker" which is not reusable in
> this case.
> I don't know if you, guys, use a lot of Namespace Traversers, but,
> it's a very convenient component and I'm definitly willing to see that
> in Grok.
>
> code with dedicated grokker, would be:
>
> class NamespaceTraverser(grok.MultiAdapter):
>     grok.baseclass()
>     grok.context(Interface)
>     grok.layer(IHTTPRequest)
>     grok.provides(ITraversable)
>
>     def __init__(self, context, request):
>         self.context = context
>         self.request = request
>
>     def traverse(self, name, stack):
>         raise NotImplementedError('You have to implement your own method')

Interesting idea: this namespace traverser component is intended to have
semantics similar to the ++skin++, ++language++, ++resource++ etc.
namespaces, right?

I guess we could have a close look at zope.traversing and see if we can
provided some sub types of the namespace traverse component: one that
does shiftNameToApplication() - like "skin" and "vh", and one that
doesn't and thus effectively can be used anywhere in the traverse path?

BTW, in your applications, are you generally using your "custom"
namespace traversal in URLs or rather in path traversal in for example
page templates?


If it wasn't clear, I'm +1 on putting this in Grok (to what extend does
a new package grokcore.traversing make any sense?)

Some more thoughts:

* Is there anything useful for us here:
http://pypi.python.org/pypi/z3c.traverser/0.2.5#additional-namespaces ?

* The namespaces in zope.traversing seem to not really differentiate on
context nor layer basis; is that accidentally or are there reasons to
think of why namespace traversers shouldn't really try to only work for
certain context types or request types?

HTH
regards,
jw


regards,
jw

_______________________________________________
Grok-dev mailing list
Grok-dev@...
https://mail.zope.org/mailman/listinfo/grok-dev