def add02(request): name = request.POST['name'] email = request.POST['email'] de = request.POST['de'] bz = request.POST['bz'] u_id = int(request.GET['u_id']) if util.not_empty(name) and util.not_empty(email) and util.not_empty(de) and util.not_empty(bz): if u_id > 0: user = ReviewUser(id=u_id) else: user = ReviewUser() user.email = email user.name = name user.deparment = de user.password = util.md5(1) user.bz = bz user.type = 2 user.save() if u_id > 0: return HttpResponseRedirect('/user') else: return HttpResponseRedirect('/add') else: return util.result(request, False, '不得有空数据!', '')
def user_del(request): id = int(request.GET['id']) if id > 0 and util.not_empty(id): de = ReviewUser(id=id) de.delete() else: return util.result(request, False, '参数错误') return HttpResponseRedirect("/user")
def del_review(request): id = int(request.GET['id']) if id > 0 and util.not_empty(id): c = ReviewCount(id=id) c.delete() return HttpResponseRedirect('./review') else: return util.result(request, False, "参数错误!")
def add(request): if util.base(request) != False: return util.base(request) context = util.user(request) context['department'] = department() # 通过d_id和u_id确认分辨是否是新增还是修改 if "d_id" in request.GET: d_id = int(request.GET["d_id"]) # 通过页面传值处理相应数据的渲染 if d_id and util.not_empty(d_id): context['department_value'] = ReviewDeparment.objects.filter(id=d_id).first().name context['d_id'] = d_id if "u_id" in request.GET: u_id = int(request.GET['u_id']) if u_id and util.not_empty(u_id): context['user_value'] = ReviewUser.objects.filter(id=u_id).first() context['u_id'] = u_id print("test:", context['user_value']) return render(request, 'add.html', context)
def detail(request): if util.base(request) != False: return util.base(request) context = util.user(request) # 获取cid c_id = int(request.GET['c_id']) # 获取uid u_id = int(request.GET['u_id']) # 查询详情 if util.not_empty(c_id) and util.not_empty(u_id): score_detail = ReviewScore.objects.filter(uid=u_id, cid=c_id).all().values( "did", "score", "time") for d in score_detail: u = ReviewUser.objects.filter(id=d["did"]).values("name", "bz").first() d['name'] = u["name"] d["bz"] = u["bz"] context['score'] = score_detail return render(request, 'detail.html', context) else: return util.result(request, False, '参数错误')
def add01(request): department_name = request.POST['name'] d_id = int(request.GET['d_id']) if util.not_empty(department_name): print("d_id is :", d_id) if d_id > 0: d = ReviewDeparment(id=d_id) else: d = ReviewDeparment() d.name = department_name d.save() # print("保存结果:", d.save(), "上传结果:", department_name) # 如果是新增则跳转到添加页面,修改则跳到管理页面 if d_id > 0: return HttpResponseRedirect('/user') else: return HttpResponseRedirect('/add') else: return util.result(request, False, '部门名称不得为空', '')
def add_review(request): name = request.POST['name'] if util.not_empty(name): # 查询当天是否存在评选 in_px = ReviewCount.objects.filter( overtime__gte=time.time()).all().values('id') if in_px: return util.result(request, False, "当天已存在评选主题,请删除后再试") else: c = ReviewCount() c.name = name c.starttime = time.time() # 取得当天晚24点的时间戳,确保每一次评选只能到凌晨截止 c.overtime = time.mktime( time.strptime( time.strftime( '%Y-%m-%d 00:00:00', time.localtime(time.time() + float(24 * 3600))), '%Y-%m-%d %H:%M:%S')) c.save() return HttpResponseRedirect('./review') else: return util.result(request, False, "暂无评选主题")