[Grok-dev] Re: A Django-like admin in Grok

Kevin Smith kevin at mcweekly.com
Thu Apr 24 18:57:17 EDT 2008


Martijn Faassen wrote:
> On a slightly unrelated topic:
>
> How hard is it to use Django templating outside of Django? Is it a
> seperate library? If so, it wouldn't be too hard to integrate this
> into a Grok extension, as we have a pluggable templating language
> system. We could throw in this adaptation bit too. :)
>   

Once upon a time I played with porting DJango templates to Zope3. It 
worked, but since DJango templates were not separated out from the rest 
of their packages, it didn't seem worth the time to maintain an 
independent branch. Especially since it's quite limited(crippled) in 
it's power and flexibility.

I recommend checking out Jinja
http://pypi.python.org/pypi/Jinja/1.2

 From their pypi page:

    Jinja is a sandboxed
    <http://en.wikipedia.org/wiki/Sandbox_%28computer_security%29>
    template engine written in pure Python. It provides a Django
    <http://www.djangoproject.com/> like non-XML syntax and compiles
    templates into executable python code. It's basically a combination
    of Django templates and python code.

Also, it seems many people are enamored with DJango Template filters and 
tags, which are very easy in to do in grok.


e.g.

from zope.traversing.interfaces import IPathAdapter
from zope.tales.interfaces import ITALESFunctionNamespace

class MyFilter(grok.Adapter):
    grok.context(interface.Interface)
    grok.implements(interface.Interface, ITALESFunctionNamespace, 
IPathAdapter)
    grok.provides(IPathAdapter)
    grok.name('myfilter') # name to access 'filter'

    def upper(self):
       return self.context.upper()

    def lower(self):
       return self.context.lower()

    def cap_words(self):
       return ' '.join([x.capitalize() for x in self.context.split()])

    def myadapter(self):
       return IMyAdapter(self.context).myattribute
     

used like:
<span tal:replace="context/title/myfilter:upper" />


> I think having this would be great, as I've heard people say good
> things about the Django templating language. Having this would also
> make it easier for people familiar with Django to learn Grok.
>   
Jinja shouldn't be a big leap, very similar syntax and usage, just a 
little more power and flexibilty, and alot more maintainability.

> Regards,
>
> Martijn
> _______________________________________________
> Grok-dev mailing list
> Grok-dev at zope.org
> http://mail.zope.org/mailman/listinfo/grok-dev
>
>
>   
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.zope.org/pipermail/grok-dev/attachments/20080424/e950a65e/attachment-0001.htm


More information about the Grok-dev mailing list