如何检查我的用户的个人资料在 web2py 中是否完整?

How to check if my user's profile is complete in web2py?

我创建了一个 'user_details' table,我将其 'user_id' 字段引用为默认值 'auth_user' table。现在注册后,我向用户展示他的个人资料并要求他完成。但是,问题是在用户提交更新后的配置文件后,我如何检查配置文件是否完整。

这是我的 'user_details' table ,

db.define_table('user_details',
    Field('user_id'),
    Field('gender',requires=IS_IN_SET(['Male','Female','Other'])),
    Field('phone_number',requires=IS_MATCH('\d{10}')),
    Field('preferred_mess'),
    Field('preferred_caterer'),
    Field('state_name','string'),
    Field('account_initial_balance'),
    Field('account_curr_balance'),
    Field('your_booking_preference',requires=IS_IN_SET(['''Don't Book Food Automatically''','Book Food Automatically'])))

您可以添加 onvalidation 功能来检查用户是否填写了所有字段。

阅读 - onvalidation

def form_validation():
    if not form.vars.gender:
        form.errors.gender = "Value not allowed"
    if not form.vars.phone_number:
        form.errors.phone_number = "Value not allowed"
    if not form.vars.preferred_mess:
        form.errors.preferred_mess = "Value not allowed"
    if not form.vars.preferred_caterer:
        form.errors.preferred_caterer = "Value not allowed"
    if not form.vars.state_name:
        form.errors.state_name = "Value not allowed"
    if not form.vars.account_initial_balance:
        form.errors.account_initial_balance = "Value not allowed"
    if not form.vars.account_curr_balance:
        form.errors.account_curr_balance = "Value not allowed"
    if not form.vars.your_booking_preference:
        form.errors.your_booking_preference = "Value not allowed"

或创建字段required=True

db.define_table('user_details',
    Field('user_id', required=True),
    Field('gender',requires=IS_IN_SET(['Male','Female','Other']), required=True),
    Field('phone_number',requires=IS_MATCH('\d{10}'), required=True),
    Field('preferred_mess', required=True),
    Field('preferred_caterer', required=True),
    Field('state_name','string', required=True),
    Field('account_initial_balance', required=True),
    Field('account_curr_balance', required=True),
    Field('your_booking_preference',requires=IS_IN_SET(['''Don't Book Food Automatically''','Book Food Automatically']), required=True))

您也可以使用 javascript。