auth.signature and Format ....issue

41 views
Skip to first unread message

Steve

unread,
Jun 1, 2016, 9:00:50 AM6/1/16
to web2py-users
Hi,

I am trying to extend the Auth_user tabel with a dropdown field.

I have them working but if i try to add the "Auth.signature" in Db.py to the table "work_position"  i get an error message. 
error message: 

<type 'exceptions.KeyError'> 'Cannot resolve reference auth_user in work_position definition'



-----------------------------------------------------------------------------
from gluon.tools import Auth, Service, PluginManager

auth = Auth(db)
service = Service()
plugins = PluginManager()

## adding custom fields to Auth_user table
db.define_table('work_position',
                Field('Name',requires=IS_NOT_EMPTY(error_message='cannot be empty!'), label=T('Name')),
                auth.signature,
                format='%(Name)s')

auth.settings.extra_fields['auth_user']= [
                Field('work_position', db.work_position, label=T('Profession')),
                etc

Anyone an idea to solve this ?
Without the auth.signature it works fine.

steve

Niphlod

unread,
Jun 1, 2016, 10:06:10 AM6/1/16
to web2py-users
at a minimum you need to extend auth BEFORE referencing it. and where is your auth.define_tables() call ?

Steve

unread,
Jun 1, 2016, 2:54:57 PM6/1/16
to web2py-users
What do you mean by first extending auth ... Before referencing it... if i do so then i get an atrribute error.

See here a snippet of my code which works in this order but auth.signature ( because i reference to auth.signature before i define my auth tables?
 )

--------------------------------------------------
from gluon.tools import Auth, Service, PluginManager

auth = Auth(db)
service = Service()
plugins = PluginManager()

## adding custom fields to Auth_user table
db.define_table('work_position',
                Field('Name',requires=IS_NOT_EMPTY(error_message='cannot be empty!'), label=T('Name')),
                format='%(Name)s')

db.define_table('practice',
                Field('Name',requires=IS_NOT_EMPTY(error_message='cannot be empty!'), label=T('Name')),
                format='%(Name)s')

auth.settings.extra_fields['auth_user']= [
                Field('work_position', db.work_position, label=T('Profession')),
                Field('practice', db.practice, label=T('Practice')),
                Field('Reg_number',requires=IS_NOT_EMPTY(error_message='cannot be empty!'), label=T('Registration Number')),]

## create all tables needed by auth if not custom tables
auth.define_tables(username=False, signature=False)

## configure auth policy
auth.settings.registration_requires_verification = False
auth.settings.registration_requires_approval = False
auth.settings.reset_password_requires_verification = True
auth.settings.actions_disabled=['register']

Op woensdag 1 juni 2016 16:06:10 UTC+2 schreef Niphlod:

pbreit

unread,
Jun 1, 2016, 3:15:39 PM6/1/16
to web2py-users
You might try:

Field('work_position', 'reference work_position', label=T('Profession')),


Reply all
Reply to author
Forward
0 new messages