Web2py有条件可读字段

时间:2017-01-20 16:42:02

标签: field web2py

为web2py完成新手...我想让表单底部的复选框仅在用户是管理员用户时有条件地出现。如何解决该字段的名称,以便我可以在非管理员用户看不到的情况下进行更改?

我使用for循环来引用循环变量,不确定我是否需要它...

## create all tables needed by Technical Request Form
db.define_table('technical_request',
Field('uuid', 'string', default=uuid.uuid4(), readable=False, writable=False),
Field('firstname', requires=IS_NOT_EMPTY(error_message='All Fields are Required!'), label="First Name"),
Field('lastname', requires=IS_NOT_EMPTY(error_message='All Fields are Required!'), label="Last Name"),
Field('phone', requires=IS_NOT_EMPTY(error_message='All Fields are Required!'), label="Phone Number"),
Field('email', requires=IS_NOT_EMPTY(error_message='All Fields are Required!'), label="Email"),    
Field('issue_name', requires=IS_NOT_EMPTY(error_message='All Fields are Required!'),label="Subject"),
Field('about_issue', 'text', requires=IS_NOT_EMPTY(error_message='All Fields are Required!'), label="Description of issue "),
Field('issue', 'upload', label="Attach Files "),
Field('request_processed', 'boolean', default=False, readable = False),
auth.signature)

for field in db.technical_request:
  if field.name == 'request_processed' and auth.has_group_membership("systemadmin"):
    field.readable = True

enter image description here

这是我要隐藏的复选框....

  • 跟进问题 *

有没有办法可以有条件地添加Field?

1 个答案:

答案 0 :(得分:1)

无需循环 - 您只需通过其名称直接访问该字段:

<Component>

或者在定义字段时这样做:

db.technical_request.request_processed.readable = auth.has_group_membership("systemadmin")