def post(self): tag_name = request.form.get('tag_name') operate_id = request.form.get('operate_id') article_id = request.form.get('article_id') article = Article.query.filter_by(id=article_id).first() if operate_id == '1': tag = Tag.query.filter_by(tag_name=tag_name).first() if not tag: return restful.params_error(message='没有这个标签') if tag in article.tags: return restful.params_error(message='文章已经有这个标签') if tag not in article.tags: article.tags.append(tag) db.session.commit() return restful.success() if operate_id == '0': tag = Tag.query.filter_by(tag_name=tag_name).first() if not tag: return restful.params_error(message='没有这个标签') if tag not in article.tags: return restful.params_error(message='文章没有这个标签') if tag in article.tags: article.tags.remove(tag) db.session.commit() return restful.success()
def ddata(): data_id = request.form.get('data_id') # print (user_id) data = Exponent.query.get(data_id) db.session.delete(data) db.session.commit() return restful.success()
def post(self): form = RegisterForm(request.form) if form.validate(): username = form.username.data email = form.email.data password = form.password.data member = form.member.data school = form.school.data district = form.district.data print(district) if not User.query.filter_by(email=email).first(): user = User(username=username, email=email, password=password, role_id=member, parent_id=g.user.id, school_name=school, district_name=district) db.session.add(user) db.session.commit() return restful.success() else: return restful.params_error("该邮箱已被注册!请更换邮箱!") else: return restful.params_error(form.get_error())
def duser(): user_id = request.form.get('user_id') # print (user_id) user = User.query.get(user_id) db.session.delete(user) db.session.commit() return restful.success()
def post(self): form = ResetEmailForm(request.form) if form.validate(): email = form.email.data g.cms_user.email = email db.session.commit() return restful.success() else: return restful.params_error(form.get_error())
def del_article(): article_id = request.form.get('article_id') article = Article.query.get(article_id) if article: db.session.delete(article) db.session.commit() return restful.success() else: return restful.params_error(message='没有这篇文章')
def deltag(): tag_id = request.form.get('tag_id') tag = Tag.query.get(tag_id) if tag: db.session.delete(tag) db.session.commit() return restful.success() else: return restful.params_error(message='出现错误')
def manage(): """ HR项目管理页面 :return: """ if request.method == 'GET': projects = Project.query.all() return render_template('project_manage.html', projects=projects) else: project_id = request.form.get('project') user_id = request.form.get('user_id') user = HrUser.query.get(int(user_id)) if project_id: project = Project.query.get(int(project_id)) project.hr_user = user db.session.commit() return restful.success() else: user.project_id = None db.session.commit() return restful.success()
def addtags(): tag_name = request.form.get('tag_name') tag = Tag.query.filter_by(tag_name=tag_name).first() if not tag: newtag = Tag(tag_name=tag_name) db.session.add(newtag) db.session.commit() return restful.success() else: print(tag_name) return restful.params_error(message='存在重复标签')
def post(self): article_title = request.form.get('title') article_summary = request.form.get('summary') article_context = request.form.get('context') if not article_title or not article_summary or not article_context: return restful.params_error('参数错误') article = Article(title=article_title, summary=article_summary, context=article_context) db.session.add(article) db.session.commit() return restful.success()
def post(self): form = ResetpwdForm(request.form) if form.validate(): oldpwd = request.form.get('oldpwd') newpwd = request.form.get('newpwd') user = g.cms_user if user and user.check_password(oldpwd): user.password = newpwd db.session.commit() return restful.success() else: return restful.params_error(message='参数错误') else: return restful.params_error(message='验证失败')
def post(self): form = ResetpwdForm(request.form) if form.validate(): oldpwd = form.oldpwd.data newpwd = form.newpwd.data user = g.user if (user.password == oldpwd): user.password = newpwd db.session.commit() return restful.success() else: return restful.params_error("旧密码错误!") else: return restful.params_error(form.get_error())
def email_captcha(): # /email_captcha/[email protected] email = request.args.get('email') if not email: return restful.params_error('请传递邮箱参数!') source = list(string.ascii_letters) source.extend(map(lambda x: str(x), range(0, 10))) # source.extend(["0","1","2","3","4","5","6","7","8","9"]) captcha = "".join(random.sample(source, 6)) # 给这个邮箱发送邮件 message = Message('邮箱验证码', recipients=[email], body='您的验证码是:%s' % captcha) try: mail.send(message) except: return restful.server_error() cache.set(email, captcha) return restful.success()
def settings(): """ HR个人信息设置页面 :return: """ if request.method == 'GET': return render_template('settings.html') else: form = SettingsForm(request.form) if form.validate(): username = form.username.data email = form.email.data user = HrUser.query.get(g.user.id) user.username = username user.email = email db.session.commit() return restful.success() else: return restful.params_error(message=form.get_error())
def add_employee(): """ 添加应聘信息 :return: """ projects = Project.query.all() if request.method == 'GET': return render_template('add_employee.html', projects=projects) else: form = AddEmployeeForm(request.form) if form.validate(): name = form.name.data age = form.age.data sex = form.sex.data hometown = form.hometown.data working_age = form.working_age.data education = form.education.data certificate = form.certificate.data resume_score = form.resume_score.data interview_score = form.interview_score.data project_id = form.project.data hr_id = g.user.id employee = Employee(name=name, age=age, sex=sex, hometown=hometown, working_age=working_age, education=education, certificate=certificate, resume_score=resume_score, interview_score=interview_score, project_id=project_id, total_score=resume_score + interview_score, hr_id=hr_id) db.session.add(employee) db.session.commit() return restful.success() else: return restful.params_error(form.get_error())
def login(): """ 登录页面 :return: """ if request.method == 'GET': return render_template('login.html') else: form = LoginForm(request.form) if form.validate(): email = form.email.data password = form.password.data remember = form.remember.data user = HrUser.query.filter_by(email=email).first() if user and user.check_password(password): session[config.HR_USER_ID] = user.id if remember: # 默认过期时间31天 session.permanent = True return restful.success() else: return restful.params_error(message='邮箱或密码错误') else: return restful.params_error(message=form.get_error())
def edit_employee(): """ 编辑应聘信息接口 :return: """ form = EditEmployeeForm(request.form) if form.validate(): employee_id = form.employee_id.data name = form.name.data age = form.age.data sex = form.sex.data hometown = form.hometown.data working_age = form.working_age.data education = form.education.data certificate = form.certificate.data resume_score = form.resume_score.data interview_score = form.interview_score.data total_score = form.total_score.data employee = Employee.query.get(employee_id) if employee: employee.name = name employee.age = age employee.sex = sex employee.hometown = hometown employee.working_age = working_age employee.education = education employee.certificate = certificate employee.resume_score = resume_score employee.interview_score = interview_score employee.total_score = total_score db.session.commit() return restful.success() else: return restful.params_error(message='没有这个应聘者') else: return restful.params_error(message=form.get_error())
def post(self): form = DataAddForm(request.form) if form.validate(): schoolName = form.schoolName.data year = form.year.data province = form.province.data city = form.city.data county = form.county.data sumStu = form.sumStu.data schoolPut = form.schoolPut.data studentAvg = form.studentAvg.data computerSum = form.computerSum.data multiClass = form.multiClass.data classSum = form.classSum.data broadband = form.broadband.data effectPrepare = form.effectPrepare.data pertinencePrepare = form.pertinencePrepare.data optimizeTeach = form.optimizeTeach.data turnoverTeach = form.turnoverTeach.data manageCourse = form.manageCourse.data communicateCourse = form.communicateCourse.data # 投入指数 if (schoolPut / sumStu) / studentAvg > 1: I = 1 else: I = round((schoolPut / sumStu) / studentAvg, 2) C1 = round(computerSum / sumStu, 2) C2 = round(multiClass / classSum, 2) if broadband >= 1000: C3 = 1.0 elif broadband >= 100: C3 = 0.5 elif broadband > 0: C3 = 0.2 else: broadband = 0 # 配置指数 C = round((C1 * C2 * C3)**(1. / 3), 2) E1 = round(0.67 * effectPrepare + 0.33 * pertinencePrepare, 2) E2 = round(0.33 * optimizeTeach + 0.67 * turnoverTeach, 2) E3 = round(0.67 * manageCourse + 0.33 * communicateCourse, 2) # 效果指数 E = round((E1 * E2 * E3)**(1. / 3), 2) # 总指数 final_index = round((I**0.25) * (C**0.25) * (E**0.5), 2) # print(final_index) add_user_id = g.user.id exponent = Exponent(schoolName=schoolName, year=year, schoolProvince=province, schoolCity=city, schoolCounty=county, schoolStu=sumStu, schoolPut=schoolPut, studentAvg=studentAvg, computerSum=computerSum, multiClass=multiClass, classSum=classSum, broadband=broadband, effectPrepare=effectPrepare, pertinencePrepare=pertinencePrepare, optimizeTeach=optimizeTeach, turnoverTeach=turnoverTeach, manageCourse=manageCourse, communicateCourse=communicateCourse, I=I, C1=C1, C2=C2, C3=C3, C=C, E1=E1, E2=E2, E3=E3, E=E, final_index=final_index, add_user_id=add_user_id) db.session.add(exponent) db.session.commit() print(restful.success()) return restful.success() else: return restful.params_error(form.get_error())