@黄祥,
*Its still giving error: *Table has no attribute 'gender' and '*
*'custom_auth_table' not defined.
Db.py
# -*- coding: utf-8 -*-
from gluon.tools import Auth
db = DAL("sqlite://storage.sqlite")
auth = Auth(db)
auth.settings.create_user_groups=True
auth.define_tables(username=False, signature=True)
db.define_table('person',
Field('name', requires=IS_NOT_EMPTY()),
Field('married', 'boolean'),
Field('gender', requires=IS_IN_SET(['Male', 'Female', 'Other'])),
Field('phone', 'integer'))
auth.settings.extra_fields['auth_user']=[
Field('gender', 'list:string', notnull=True),
Field('address', 'text', notnull=True),
Field('zip', length=10, notnull=True),
Field('city', length=10, notnull=True),
Field('country', length=10, notnull=True),
Field('phone', length=10, notnull=True, unique=True),
Field('company', 'reference company', notnull=True)]
from gluon.contrib.populate import populate
if db(db.auth_user).isempty():
auth.add_group('Manager', 'Manager')
auth.add_group('Admin', 'Admin')
auth.add_membership('1', '1')
auth.add_membership('2', '1')
auth.add_membership('2', '2')
db.auth_user.bulk_insert([{'first_name' : 'Manager', 'last_name' :
'Manager',
'email' : '[email protected]',
'password' :
db.auth_user.password.validate('password')[0],
'gender' : 'Male', 'address' : 'Address',
'zip' : '11111',
'city' : 'Jakarta', 'country' : 'Indonesia',
'phone' : '1',
'company' : 1},
{'first_name' : 'Admin', 'last_name' :
'Admin',
'email' : '[email protected]',
'password' :
db.auth_user.password.validate('password')[0],
'gender' : 'Male', 'address' : 'Address',
'zip' : '11111',
'city' : 'Jakarta', 'country' : 'Indonesia',
'phone' : '2',
'company' : 1}])
custom_auth_table=db[auth.settings.table_user_name]
custom_auth_table.gender.requires=IS_IN_SET(['Male', 'Female'])
custom_auth_table.address.requires=IS_NOT_EMPTY()
custom_auth_table.zip.requires=IS_MATCH('^\d{5,5}$',
error_message='not a zip code')
custom_auth_table.city.requires=IS_NOT_EMPTY()
custom_auth_table.country.requires=IS_NOT_EMPTY()
custom_auth_table.phone.requires=IS_NOT_IN_DB(db, custom_auth_table.phone)
custom_auth_table.company.requires=IS_IN_DB(db, db.company.id,
'%(company_name)s')
auth.settings.table_user=custom_auth_table
--
---
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/groups/opt_out.