Hello all,
I'm creating a new question from a brief conversation I had going on in
this thread: https://groups.google.com/forum/#!topic/web2py/UYqS8nIkeQY.
So basically I have an app that uses nothing but web2py (no wsgi or apache)
and in this app I want to add 2 additional "auth" tables. One of these
tables will be linked to the auth_group table by the ID. The original way I
had accomplished this was in web2py version 1.99 and I had it as follows:
from gluon.tools import Auth
response.generic_patterns = ['*']
response.headers['Access-Control-Allow-Origin'] = '*'
auth = Auth(globals(), db)
auth.define_tables(username=True, fake_migrate=False, migrate=True)
auth.settings.allow_basic_login = True
auth.settings.create_user_groups = False
auth.settings.actions_disabled.extend(['change_password',
'request_reset_password', 'retrieve_username', 'register'])
db.define_table('auth_app',
Field('name','string',length=50,unique=True,notnull=True),
Field('description','string',length=255),
migrate='auth_app.table')
db.define_table('auth_app_group',
Field('app_id','integer',db.auth_app,notnull=True),
Field('group_id', 'integer',db.auth_group,notnull=True),
migrate='auth_app_group.table')
So I declared the tables after I did auth.define_tables so that the
auth_group table existed so I could link that auth_group.id field to my
custom table. This works just fine in my current production environment
with web2py 1.99 running. However I have a new dev environment set up with
a newer release of web2py (2.9.11) and it does not like this method I'm
using. It is giving the following error: <type 'exceptions.TypeError'>
can't pickle instancemethod objects.
So I turned to the documentation to see if there was a way I could get
around this. I found a section about creating your own auth tables before
auth.define_tables and having auth use those instead of defining it's own.
So I thought I could get around this by defining the auth_group table
myself before the define_tables function runs as well as my two custom
tables so I could link them together and still have it work. That looks
like so:
from gluon.tools import Auth
response.generic_patterns = ['*']
response.headers['Access-Control-Allow-Origin'] = '*'
auth = Auth(globals(), db)
db.define_table('auth_app',
Field('name','string',length=50,unique=True,notnull=True),
Field('description','string',length=255),
migrate='auth_app.table')
db.define_table(auth.settings.table_group_name,
Field('role','string',length=255,notnull=True),
Field('description','text'))
db.define_table('auth_app_group',
Field('app_id','integer',db.auth_app,notnull=True),
Field('group_id', 'integer',db.auth_group,notnull=True),
migrate='auth_app_group.table')
custom_auth_table = db[auth.settings.table_group_name]
custom_auth_table.role.requires = IS_NOT_EMPTY(error_message=auth.messages.
is_empty)
auth.settings.table_group = custom_auth_table
auth.define_tables(username=True, fake_migrate=False, migrate=True)
auth.settings.allow_basic_login = True
auth.settings.create_user_groups = False
auth.settings.actions_disabled.extend(['change_password',
'request_reset_password', 'retrieve_username', 'register'])
Unfortunately this produced the same "can't pickle instancemethod objects"
error. At this point I am out of ideas and so I am in need of some
assistance. Any suggestions on how I can accomplish this?
I hope this all makes sense. Please ask for any clarification if it does
not.
Thanks,
M
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.