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 myproject(): projectInfo = [] pageinfo = {} page_size = 10 pageinfo["total_page_number"] = 1 pageinfo["total_number"] = 0 pageinfo["current_page"] = 1 user = User.get(User.email == g.user["email"]) current_page = int(request.form.get("page", 1)) if user.admin_pro and user.admin_pro.startswith("all"): ps = Project.select() if ps != None: pageinfo["total_number"] = ps.count() pageinfo["total_page_number"] = int(math.ceil(pageinfo["total_number"] / float(page_size))) if current_page > pageinfo["total_page_number"]: current_page = pageinfo["total_page_number"] k = 0 limit_low = (current_page - 1) * page_size limit_high = ( limit_low + page_size if limit_low + page_size <= pageinfo["total_number"] else pageinfo["total_number"] ) for p in ps: k = k + 1 if k > limit_high: break if k > limit_low and k <= limit_high: info = {} info["name"] = "" info["id"] = "" info["admins"] = [] info["id"] = str(p.p_id) info["name"] = p.p_name admins = interface_db.get_admins_of_project(p.p_id) info["admins"] = admins projectInfo.append(info) else: admin_pro = user.admin_pro pids = [] if admin_pro: pids = admin_pro.split(",") pageinfo["total_number"] = len(pids) pageinfo["total_page_number"] = int(math.ceil(pageinfo["total_number"] / float(page_size))) if current_page > pageinfo["total_page_number"]: current_page = pageinfo["total_page_number"] k = 0 limit_low = (current_page - 1) * page_size limit_high = ( limit_low + page_size if limit_low + page_size <= pageinfo["total_number"] else pageinfo["total_number"] ) for pid in pids: k = k + 1 if k > limit_high: break if k > limit_low and k <= limit_high: info = {} info["name"] = "" info["id"] = "" info["admins"] = [] get_pro = Project.get(Project.p_id == int(pid)) info["id"] = str(get_pro.p_id) info["name"] = get_pro.p_name admins = interface_db.get_admins_of_project(get_pro.p_id) info["admins"] = admins projectInfo.append(info) pageinfo["current_page"] = current_page if request.args.get("p_id"): session["cur_project"] = request.args.get("p_id") return "select project" filters = {} filters["category"] = p_id = session.get("cur_project") or "-1" projectInfolen = len(projectInfo) return render_template( "myproject.html", projects=g.projects, projectInfo=projectInfo, filters=filters, pageinfo=pageinfo, projectInfolen=projectInfolen, )
def config(): if request.method == "POST": postType = request.form.get("type") ##选择项目 if postType == "selectProject": p_id = request.form.get("p_id") session["cur_project"] = p_id if p_id == "-1": return "no select project!" project = Project.get(Project.p_id == int(p_id)) # app.logger.debug(project.p_id) admins = interface_db.get_admins_of_project(project.p_id) data = {} names = [] emails = [] for admin in admins: names.append(admin["u_name"]) emails.append(admin["email"]) # app.logger.debug(jsonify(data)) data["name"] = names data["email"] = emails return jsonify(data) ##添加admin elif postType == "addAdmin": email = request.form.get("email") p_id = request.form.get("p_id") try: user = User.get(User.email == email) except: user = None if user == None: return "no such user!" else: u_id = user.u_id admin_pro = user.admin_pro data = {} if not admin_pro: admin_pro = str(p_id) data["type"] = "add" else: pids = admin_pro.split(",") if str(p_id) in pids: data["type"] = "same" else: data["type"] = "add" admin_pro += "," + str(p_id) query = User.update(admin_pro=admin_pro).where(User.u_id == u_id) query.execute() data["name"] = user.u_name data["email"] = user.email return jsonify(data) ##删除admin elif postType == "removeAdmin": email = request.form.get("email") p_id = request.form.get("p_id") user = User.get(User.email == email) u_id = user.u_id admin_pro = user.admin_pro if admin_pro == str(p_id): admin_pro = None else: pids = admin_pro.split(",") pids.remove(str(p_id)) splits = "," admin_pro = splits.join(pids) query = User.update(admin_pro=admin_pro).where(User.u_id == u_id) query.execute() return "remove admin success!" ##auto search elif postType == "autoSearch": str1 = request.form.get("letter") user = User.select() search_dict = {} search_list = [] if user: for user_iter in user: user_email = user_iter.email search_len = len(str1) if len(str1) < len(user_email) else len(user_email) if str1 == user_email[:search_len]: search_list.append(user_iter.u_name + " " + user_iter.email) search_dict["list"] = search_list return jsonify(search_dict) filters = {} filters["category"] = p_id = session.get("cur_project") or "-1" try: project = Project.get(Project.p_id == int(p_id)) admins = interface_db.get_admins_of_project(project.p_id) except: admins = [] session["cur_project"] = "-1" return render_template("config.html", projects=g.projects, filters=filters, admins=admins)