def feedback(): if request.method == "POST": fd = request.form.get("feedback") data = json.loads(fd) user = None project = None if data["mail"]: if data["mail"].find("@") < 0: # auto compelet email data["mail"] = data["mail"] + "@corp.netease.com" user = interface_db.add_user(None, data["mail"]) if data["project"]: project, created = interface_db.add_project(data["project"]) # add message to item table newItem = interface_db.add_item(data["cat"], user.u_id, project.p_id, 0, data["note"], None, data["img"]) # 将image保存在本地 pic = data["img"] pic = pic.split(",")[1] imgData = base64.b64decode(pic) imgName = "static/pictures/item" + str(newItem.it_id) + ".png" local_img = open(imgName, "wb") local_img.write(imgData) local_img.close() # send popo message to sender popo_item_sender = data["mail"].split("@")[0] msg = u"已收到您的反馈,谢谢您的建议!" sendmsg(popo_item_sender, msg.encode("gbk")) # send popo message to project admins admins = interface_db.get_admins_of_project(project.p_id) for admin in admins: if admin: popo_admin_sender = admin["email"].split("@")[0] msg = ( u"您管理的项目‘" + data["project"] + u"’ 收到了用户‘" + data["mail"] + u"’的反馈信息,请点击 http://feedback.nie.netease.com" + u"/show 查看。" ) sendmsg(popo_admin_sender, msg.encode("gbk")) return "ok" else: return render_template("example.html")
def inner(*args, **kwargs): if g.user is None: return redirect("/login?next=" + urllib.quote(request.url)) ###################获取用户管理的项目################################# user = interface_db.add_user(session["user_name"], session["user_email"]) # return the project which user manages if user.admin_pro and user.admin_pro.startswith("all"): # 超级管理员,可查看所有项目 ps = Project.select() projects = [] for p in ps: projects.append({"p_id": str(p.p_id), "p_name": p.p_name}) else: projects = interface_db.get_user_admin(session["user_email"]) g.projects = projects return f(*args, **kwargs)
def project_config(): ##添加删除项目 if request.method == 'POST': postType = request.form.get('type') if postType == 'createProject': projectName = request.form.get('projectName') p_id, created = interface_db.add_project(projectName) if not created: return 'same project!' user = interface_db.add_user(session['user_name'],session['user_email']) admin_pro = user.admin_pro pids = [] if admin_pro and admin_pro.startswith('all'): pass elif not admin_pro: admin_pro = str(p_id) else: pids = admin_pro.split(',') if str(p_id) in pids: pass else: admin_pro += ',' + str(p_id) User.update(admin_pro = admin_pro).where(User.u_id == user.u_id).execute() data = {} data['name'] = projectName data['p_id'] = p_id return jsonify(data) elif postType == 'removeProject': try: p_id = request.form['p_id'] project = Project.get(Project.p_id == int(p_id)) # 根据项目名对数据库做删除操作 interface_db.del_project(project.p_name) return p_id except: return 'error'