[Grok-dev] summary templating/skinning discussion

Darryl Cousins darryl at darrylcousins.net.nz
Sat Jun 16 05:25:23 EDT 2007


Hi,

On Tue, 2007-05-22 at 08:16 -0700, Kevin Smith wrote:
> > Kevin, what do you think needs to be done for a)? I'm quite interested 
> > in starting that integration work, as I have the impression we're 
> > quite far along in this.
> >
>  From the doctests of the ksmith_mcweekly-layers branch, here is the 
> implementation as is. All tests pass, if there is consensus on the 
> naming, it's ready for merge.

+1 for merge to trunk.

I've come to need layers (use case described below) and the branch
answers my needs.

Use case: I have an application which manages multiple sites. The python
code in each site package looks like this and is script generated:

import os
import grok

from tfws.content.site import IImportableSite
from tfws.content.site.app import Site

from solacafe import datapath

class solacafe(Site):
    _importname = u'solacafe'


class solacafe_Factory(object):
    __name__ = u'solacafe'
    _datapath = os.path.join(datapath, 'data')

    def __call__(self, *args):
        return solacafe(*args)

grok.global_utility(solacafe_Factory, IImportableSite, u'solacafe')

Importers take care of the data.

Til now I've just used a single master template:

from zc import resourcelibrary

class Master(grok.View):
    grok.context(Interface)

    def __init__(self, context, request):
        super(Master, self).__init__(context, request)
        resourcelibrary.need('tfws.javascript.core')

With the third site that I have migrated I find I require a
site-specific master macro so I dived into Kevin's branch. It does all I
need.  Here is the python code for a site with a local master macro::

class yachtproLayer(grok.ILayer):
    pass

class yachtproSkin(grok.Skin):
    grok.layer(yachtproLayer)

class yachtpro(Site):
    _importname = u'yachtpro'

    grok.local_utility(PortletManager, IPortletManager, name='site.extracolumn',
                                                        name_in_container='site.extracolumn')
    grok.local_utility(ImagePortletAssignment, IPortletType, name='portlet.imageportlet',
                                                  name_in_container='portlet.imageportlet')

class yachtproFactory(object):
    __name__ = u'yachtpro'
    _datapath = os.path.join(datapath, 'data')

    def __call__(self, *args):
        return yachtpro(*args)

grok.global_utility(yachtproFactory, IImportableSite, u'yachtpro')

class Master(grok.View):
    grok.context(Interface)
    grok.layer(yachtproLayer)

    def __init__(self, context, request):
        super(Master, self).__init__(context, request)
        resourcelibrary.need('tfws.javascript.core')

Bingo.

Theming is done with Deliverance. With the layer (local master macro) I
can now register additional content providers specific to the site
alone.

Regards,
Darryl

> 
> grok.layer(IBasicSkin)
> 
> class MySkinLayer(grok.ILayer): # inherits from IDefaultBrowserLayer
>     pass 
> 
> class MySkin(grok.Skin):
>     grok.layer(MySkinLayer)
>     grok.name('myskin') # this is actually the default
> 
> class Mammoth(grok.Model):
>     pass
> 
> class CaveDrawings(grok.View):
>     pass # uses module-level grok.layer(IBasicSkin)
> 
> 
> cavedrawings = grok.PageTemplate("""\
> <html>
> <body>
> <h1>Hello, world!</h1>
> </body>
> </html>
> """)
> 
> class MoreDrawings(grok.View):
>     grok.layer(rotterdam) # overrides grok.layer(IBasicSkin)
> 
>     def render(self):
>         return "Pretty"
> 
> class EvenMoreDrawings(grok.View):
>     grok.layer(MySkin)
> 
>     def render(self):
>         return "Awesome"
> 
> 
> _______________________________________________
> Grok-dev mailing list
> Grok-dev at zope.org
> http://mail.zope.org/mailman/listinfo/grok-dev



More information about the Grok-dev mailing list