def post(self, id): ar = model.ModelData() form = self.form() # 删除字段 if self.get_argument("id", False) and self.get_argument("isDel", False): ar.remove(self.get_argument("id")) return self.write({"success": True}) # 绑定错误回调 form.on("validateError", self.onFormValidateError) # 验证 if form.validate(self.request.arguments): # 验证通过 post = form.values() if post.get("id", False): ret = ar.edit(post["id"], post) # print ret return self.write(ret) else: del post["id"] post["model_id"] = id ret = ar.add(post) return self.write(ret)
def post(self): import time time.sleep(1.5) form = self.form() # 验证 if form.validate(self.request.arguments): # 验证通过 post = form.values() ar = model.User().find("email = ?", post["email"]).where("password = ?", util.md5(post["password"])) user = ar.get() if user != None: # 为用户登陆 self.set_current_user( { "userId": user["id"], "userName": user["name"], "email": user["email"], "roles": user.getRoleCodes(), } ) return self.write({"success": True, "url": "/admin"}) return self.write({"success": False, "msg": "邮箱或密码错误"})
def post(self, id): category = model.Category().get(id) if category: form = self.form(category["model_id"]) data = util.json.decode(self.get_argument("list", "[]"), []) # 创建关联 cid = model.CategoryHasArticle().find().add({"category_id": id}) for post in data: # print post # 验证 if form.validate(post): ar = model.Category().getModel(id) # 验证通过 post = form.values() del post["id"] post["category_has_article_id"] = cid post["user_id"] = self.user["userId"] post["time"] = util.time.time() post["change_time"] = 0 post["ip"] = self.request.remote_ip ar.add(post) return self.write({"success": True}) return self.write({"success": False, "msg": "数据异常"})
def post(self, id, aid, cid): category = model.Category().get(id) if category: form = self.form(category["model_id"]) data = util.json.decode(self.get_argument("list", "[]"), []) for post in data: # print post # 验证 if form.validate(post): ar = model.Category().getModel(id) # 验证通过 post = form.values() if util.validators.isNumber(post["id"]): post["category_has_article_id"] = cid post["user_id"] = self.user["userId"] post["change_time"] = util.time.time() post["ip"] = self.request.remote_ip ar.where("id = ?", post["id"]).save(post) else: del post["id"] post["category_has_article_id"] = cid post["user_id"] = self.user["userId"] post["time"] = util.time.time() post["change_time"] = 0 post["ip"] = self.request.remote_ip ar.add(post) return self.write({"success": True}) return self.write({"success": False, "msg": "数据异常"})
def post(self): form = self.form() role = model.Role() if self.get_argument("id", False) and self.get_argument("isDel", False): role.remove(self.get_argument("id")) return self.write({"success": True}) # 验证 if form.validate(self.request.arguments): # 验证通过 post = form.values() if post.get("id", False): role.find().where("id = ?", post["id"]).save(post) return self.redirect(self.request.uri) else: del post["id"] role.find().add(post) return self.redirect(self.request.uri)
def post(self): ar = model.Category() form = self.form() # 删除 if self.get_argument("id", False) and self.get_argument("isDel", False): ar.remove(self.get_argument("id")) return self.write({"success": True}) # 验证 if form.validate(self.request.arguments): # 验证通过 post = form.values() if post.get("id", False): ret = ar.edit(post["id"], post) return self.write(ret) else: del post["id"] ret = ar.add(post) return self.redirect(self.request.uri)
def post(self): form = self.form() ar = model.Model() if self.get_argument("id", False) and self.get_argument("isDel", False): if int(self.get_argument("id")) == 1: return self.write({"success": False, "msg": "文章模型属于系统模型,不允许删除!"}) ar.remove(self.get_argument("id")) return self.write({"success": True}) # 验证 if form.validate(self.request.arguments): # 验证通过 post = form.values() if post.get("id", False): ar.edit(post["id"], post) return self.redirect(self.request.uri) else: del post["id"] ar.add(post) return self.redirect(self.request.uri)