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

Hector Blanco white.lists at gmail.com
Thu Dec 23 12:08:02 EST 2010


Hello everyone!

I am starting to set up my grok server (version 1.2.1) and I have
created a (very basic) "server.ViewSite" permission. All the users
with a valid login/password will have that permission. The problem is
that if I don't put it in app.py, the server won't start...

This is my permission:

class ViewSite(grok.Permission):
    grok.name("server.ViewSite")
    grok.title("View the site")

So I can use it in my views:
---------- app.py ------------
class Test(grok.View):
    grok.context(Server)
    grok.require('server.ViewSite')
	
    def render(self):
        [ . . . ]

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:

zope.configuration.config.ConfigurationExecutionError: <class
'martian.error.GrokError'>: Undefined permission 'server.ViewSite' in
<class 'server.app.Test'>. Use grok.Permission first.

It also happens if (in app.py) instead of writing:
from backlib.user import Permissions

(which is what I'd like to be able to do) I write:
from backlib.user.Permissions import ViewSite

It's not big deal... is just that I'm planning to define more
permissions and it would be slightly clearer having them stored in a
file which is not app.py.

Thanks in advance


More information about the Grok-dev mailing list