[Grok-dev] Put the user-defined permissions in a separate .py file?

Jan-Wijbrand Kolman janwijbrand at gmail.com
Mon Jan 10 03:44:34 EST 2011


On 12/23/10 18:08 PM, Hector Blanco wrote:
  > If I create a "Permissions.py" file, I put this permission in it and
> then I import "permissions" in app.py, when I try to start the server,
> I get:

Putting the permissions in one module sounds to me like a good idea. We 
do it too in our apps.

The reason you get the error, is because app.py is "grokked" before 
"permission.py" and thus the permissions are not declared. It made me 
wonder why we, in our apps, do not have this error... And the answer is 
rather simple: we put our view code in a browser subpackage. The 
permission module live in the parent package, and thus is grokked before 
the views (that make use of the permissions) are grokked.

It is unfortunate that the grokking-order influences how code is 
organized in packages. The work around I see is to make sure the 
permission.py module is grokked before the rest of the package from the 
configure.zcml (untested, but it might work):

configure.zcml:

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

     <include package="MyApp.permission"/>
     <include package="MyApp" />

   </configure>


regards, jw



More information about the Grok-dev mailing list