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

时间:2015-10-22 18:44:19

标签: web2py

我已经制作了一个' user_details'表' user_id'字段我引用了默认' auth_user'表。注册后,我向用户显示他的个人资料并要求他完成。但问题是,在用户提交更新的配置文件后,如何检查配置文件是否完整。

这是我的' user_details'表,

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'])))

1 个答案:

答案 0 :(得分:0)

您可以添加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" 功能来检查用户是否填写了所有字段。

阅读 - onvalidation

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))

<TextView
    android:id="@+id/tv1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:text="Count"
    android:textColor="#F44336"
    android:textSize="30dp" />

<ImageSwitcher
    android:id="@+id/imageSwitcher"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/tv1"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="168dp" />

你也可以使用javascript。