[Grok-dev] how to split an application into packages

DIVINE, PAUL (PAUL) paul.divine at alcatel-lucent.com
Tue Oct 12 05:22:13 EDT 2010


Hi, grokkers,

I have made an application with grok.
The home page is a list of functions. Then with a click on a function you
access to the page of the function. Each function has no link with the others,
but the display has the same header and footer.

For example the function can be the following one.
 - blob example
 - web service example
 - xml indentation service
Or the application can be a demo of several functions of grok.

My aim is to split the app.py file into packages:
one package for the home page, one package for each function.

The home page is divided (like in the application example of the book of
Carlos de la Guardia) headslot, head, main and footer with viewlet managers.
Each function just use the main viewlet manager.

The home_app call each function at the initialisation.

class Home_app(grok.Application, grok.Container):
    """ Home_app  """
        super(Home_app, self).__init__()
        self.funcs   = [Func0, Func1, Func2]
        for index, func in enumerate(func_list):
            self[func]


To make a package of each funcx (x is 0 1 ...) with (for example) the following classes,

class Funcx(grok.Container):
     .....

class FuncxDescription(grok.Viewlet):
    grok.viewletmanager(Main)
    grok.context(Funcx)
    grok.order(1)

class FuncxBoard(grok.View):
    grok.context(Funcx)
    grok.name('index')
    grok.template('master')

class FuncxBoardViewlet(grok.Viewlet):
    grok.viewletmanager(Main)
    grok.context(Funcx)
    grok.template('Funcx_viewlet')
    grok.view(FuncxBoard)
    grok.order(2)


class FuncxUploadForm(grok.AddForm):

  .....


1) In the directory home_app/src, I type the command

../bin/paster create -t basic_package func0

2) Inside the home_app/src/func0/func0 directory, I create a
configure.zcml file like the following one.


 <configure xmlns="http://namespaces.zope.org/zope"
           xmlns:grok="http://namespaces.zope.org/grok"
           xmlns:mail="http://namespaces.zope.org/mail" >
  <include package="grok" />
  <includeDependencies package="." />
  <grok:grok package="." />
</configure>

3) I create the directories (with mkdir command)
home_app/src/func0/func0/app_templates
home_app/src/func0/func0/static

4) in the home_app/src/func0/setup.py  I added the home_app line in the install_require

      install_requires=[
          # -*- Extra requirements: -*-
          'home_app'

5) in the home_app/buildout.cfg I added the line   func0

[app]
recipe = zc.recipe.egg
eggs = home_app
       func0


6) in the home_app/src/func0/func0/app.py I put the line

from home_app.app import HeadSlot, ...
and put all the func0 related classes

7) in the home_app/src/home_app/app.py
I put all the home_app related classes
What import to get the func0 class?
And Is this process OK?


Thanks in advance for you help.
Best regards
Paul



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.zope.org/pipermail/grok-dev/attachments/20101012/a73362e7/attachment.html 


More information about the Grok-dev mailing list