我已经建立了一个系统,允许用户申请代码审查并等待经理批准。
现在我想要实现以下目标:
1. 如果被批准,
那么所有字段都变为只读(这里我手动将项目名称设置为只读):
现在我想要实现以下目标:
1. 如果被批准,
![enter image description here](https://istack.dev59.com/aPYSl.webp)
![enter image description here](https://istack.dev59.com/PhaT4.webp)
If it's rejected,
then all the fields become editable. Of course, when creating a new project, all the fields should be editable.
The code of class
Project
andProjectView
are as below:from flask_sqlalchemy import SQLAlchemy from flask_admin.contrib import sqla from flask_security import current_user # Create Flask application app = Flask(__name__) app.config.from_pyfile('config.py') db = SQLAlchemy(app) class Project(db.Model): id = db.Column(db.Integer, primary_key=True) project_name = db.Column(db.Unicode(128)) version = db.Column(db.Unicode(128)) SVN = db.Column(db.UnicodeText) approve = db.Column(db.Boolean()) def __unicode__(self): return self.name class ProjectView(sqla.ModelView): def is_accessible(self): if not current_user.is_active or not current_user.is_authenticated: return False return False @property def _form_edit_rules(self): return rules.RuleSet(self, self.form_rules) @_form_edit_rules.setter def _form_edit_rules(self, value): pass @property def _form_create_rules(self): return rules.RuleSet(self, self.form_rules) @_form_create_rules.setter def _form_create_rules(self, value): pass @property def form_rules(self): form_rules = [ rules.Field('project_name'), rules.Field('version'), rules.Field('SVN'), ] if not has_app_context() or current_user.has_role('superuser'): form_rules.append('approve')
In my opinion, since approve is a boolean variable, there should be a condition judgement to tell if it is 0 or 1 and then the field become read-only or editable accordingly.
Thanks for any advise in advance.