0

I am trying this form a while. I have a page which displays a form and whose databse definition looks like:

db.define_table('nskrelease',
            Field('sprid',length=128,requires=IS_IN_SET(['R3.2', 'R3.3', 'R3.4'],zero=T('choose one'),error_message='must be R3.2 or R3.3  or R3.4 '),label = T('SPR')),
            Field('releaseid',length=128, requires = IS_NOT_EMPTY(error_message='Release ID cant be empty'),label = T('Release')),
            Field('coordinator',requires=IS_EMAIL(error_message='invalid email!') ,label=T('Co-ordinator Email')),
            Field('startdate', 'datetime', default=request.now,requires = IS_NOT_EMPTY(error_message='Start date cant be empty'), label=T('Start date')),
            Field('enddate', 'datetime', default=request.now, requires = IS_NOT_EMPTY(error_message='End date cant be empty'), label=T('End Date')),format='%(%releaseid)s')

db.nskrelease.releaseid.requires = IS_NOT_IN_DB(db,'nskrelease.releaseid')
db.nskrelease.coordinator.requires = IS_IN_DB(db,'auth_user.email','%(email)s')

But the problem here is the Coordinator field displays all the user in present in db.auth_user. Instead i need that to be restricted only to the Logged in user. So I tried:

db.nskrelease.coordinator.requires = IS_IN_DB(db(db.nskrelease.coordinator == 'auth.user.email'))

But it gives me error:

TypeError: __init__() takes at least 3 arguments (2 given)

Please help. Thanks in advance.

1 Answer 1

2

If the only email address allowed in this field is that of the currently logged in user, then maybe just set that as the default value and don't make the field writable:

Field('coordinator', writable=False,
      default=auth.user.email if auth.user else None,
      update=auth.user.email if auth.user else None)

However, a better approach might be to make this a reference field, so you don't have to worry about updating this field whenever there is a profile update:

Field('coordinator', 'reference auth_user', writable=False,
      default=auth.user_id, represent=lambda v, r: v.email)
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.