def form(self): # 模型列表 models = model.Model().find().order("id ASC").get(100) modelList = [] for v in models: modelList.append({"label": v["info"], "value": v["id"]}) # 栏目列表 ar = model.Category() treeList = ar.treeToSelect() treeList.insert(0, {"label": "无", "value": "0"}) form = YooYo.form.Form() form.add(YooYo.form.Hidden(name="id")).add( YooYo.form.Select(name="model_id", label="所属模型", data=modelList) ).add(YooYo.form.Select(name="parent", label="上级", data=treeList)) # 多语言名称 locales = model.Locale().find().get(100) for locale in locales: form.add( YooYo.form.Text( name="locale_" + str(locale["id"]), label=locale["name"] + "名称", validators=["notEmpty"], filter=["trim"], ) ) return form.add(YooYo.form.Submit(name="send", label="保存"))
def getForm(self,id): def jsonDecode(json,defalut=[]): if json == None or '' == json: return defalut return escape.json_decode(json) # ['id','model_id','locale_id','ip','category_id', # 'user_id','time','change_time','listorder'] fields = self.getFields(id) form = YooYo.form.Form() form.add(YooYo.form.Hidden( name = 'id' )).add(YooYo.form.Hidden( name = 'locale_id' , validators = 'notEmpty' )).add(YooYo.form.Hidden( name = 'model_id' , value = id , validators = 'notEmpty' )) for f in fields: if hasattr(YooYo.form,f['widget']) : form.add(getattr(YooYo.form,f['widget'])( name = f['name'] , label = f['label'] , validators = jsonDecode(f['validators']), filter = jsonDecode(f['filters']), data = jsonDecode(f['data']) )) return form
def form(self): form = YooYo.form.Form() form.add(YooYo.form.Hidden(name="id")).add( YooYo.form.Text(name="code", label="代码", validators=["notEmpty"], filter=["trim"]) ).add(YooYo.form.Text(name="name", label="名称", validators=["notEmpty"], filter=["trim"])).add( YooYo.form.Submit(name="send", label="保存") ) return form
def form(self): form = YooYo.form.Form() form.add(YooYo.form.Hidden(name="id")).add( YooYo.form.Text(name="title", label="表名", validators=["notEmpty"], filter=["trim"]) ).add(YooYo.form.Text(name="info", label="描述", validators=["notEmpty"], filter=["trim"])).add( YooYo.form.Submit(name="send", label="保存") ) return form
def form(self): roles = [] for r in model.Role().find().get(20): roles.append({"label": r["info"], "value": r["id"]}) form = YooYo.form.Form() form.add(YooYo.form.Hidden(name="id")).add( YooYo.form.Text(name="name", label="账号", validators=["notEmpty"], filter=["trim"]) ).add(YooYo.form.Password(name="password", label="密码", filter=["trim"], attr={"tip": "不修改请留空"})).add( YooYo.form.Text(name="email", label="邮箱", validators=["notEmpty", "isEmail"], filter=["trim"]) ).add( YooYo.form.Checkbox(name="roles", label="角色", data=roles) ).add( YooYo.form.Submit(name="send", label="保存") ) return form
def form(self): form = YooYo.form.Form() form.add(YooYo.form.Hidden(name="id")).add(YooYo.form.Hidden(name="model_id")).add( YooYo.form.Text(name="name", label="字段", validators=["notEmpty"], filter=["trim"]) ).add(YooYo.form.Text(name="label", label="标签", validators=["notEmpty"], filter=["trim"])).add( YooYo.form.Select( name="widget", label="组件", data=[ {"label": "单行文本框", "value": "Text"}, {"label": "多行文本框", "value": "Textarea"}, {"label": "编辑器", "value": "Editor"}, {"label": "图片上传", "value": "ImageUpload"}, {"label": "组图", "value": "Photos"}, {"label": "视频组", "value": "Videos"}, {"label": "下拉框", "value": "Select"}, {"label": "复选框", "value": "Checkbox"}, ], ) ).add( YooYo.form.Select( name="type", label="类型", data=[ {"label": "数字", "value": "INT"}, {"label": "字符", "value": "VARCHAR"}, {"label": "文本", "value": "TEXT"}, {"label": "浮点", "value": "FLOAT"}, ], ) ).add( YooYo.form.Text(name="info", label="描述", filter=["trim"]) ).add( YooYo.form.Textarea(name="data", label="可选数据", filter=["trim"], validators=["isJson"]) ).add( YooYo.form.Textarea(name="validators", label="验证规则", filter=["trim"], validators=["isJson"]) ).add( YooYo.form.Textarea(name="filters", label="过滤规则", filter=["trim"], validators=["isJson"]) ).add( YooYo.form.Text(name="max_len", label="最大长度", validators=["isNumber"], value="0") ).add( YooYo.form.Text(name="min_len", label="最小长度", validators=["isNumber"], value="0") ).add( YooYo.form.Submit(name="send", label="保存") ) return form
def form(self): form = YooYo.form.Form() form.add(YooYo.form.Text(name="email", label="邮箱", validators=["notEmpty", "isEmail"], filter=["trim"])).add( YooYo.form.Password(name="password", label="密码", filter=["trim"], validators=["notEmpty"]) ).add(YooYo.form.Submit(name="send", label="登陆")) return form
def form(self, id): form = model.Model().getForm(id) return form.add(YooYo.form.Submit(name="send", label="添加"))