def user(request): if util.base(request) != False: return util.base(request) context = util.user(request) context['de'] = all_de() context['user'] = home.user() return render(request, 'user.html', context)
def home(request): if util.base(request) != False: return util.base(request) context = util.user(request) user_data = [] # 查询是否有评选会议 if in_px(): context['in_name'] = in_px().name context['in_id'] = in_px().id # 查询所有用户打分详情 for u in user(): rs = ReviewScore.objects.filter( uid=u['id'], cid=in_px().id, did=util.get_user(request, 'id')).values('score', 'count').first() if rs is not None: if rs['score'] is not None: u['score'] = rs['score'] if rs['count'] is not None: u['count'] = rs['count'] user_data.append(u) else: context['in_name'] = False context['user'] = user_data return render(request, 'home.html', context)
def result(request): if util.base(request) != False: return util.base(request) context = util.user(request) # 获取cid c_id = int(request.GET['c_id']) # 获取评选名称 p_name = request.GET['name'] context["p_name"] = p_name context['c_id'] = c_id # 获取所有用户信息并进行遍历,查询具体得分详情 user = home.user() for u in user: # 通过用户uid 查询打分表,查出该用户打的所有分 score = ReviewScore.objects.filter(uid=u['id'], cid=c_id).all().values( "score", 'did') # 分辨统计各级别的人数以及总分 bz_all = 0 bz_count = 0 zc_all = 0 zc_count = 0 pt_all = 0 pt_count = 0 # 遍历所有分数,按照规则取最终分 for s in score: # 查询该用户的级别 u_jb = ReviewUser.objects.filter(id=s['did']).values("bz").first() u_jb = int(u_jb["bz"]) in_score = float(s["score"]) if u_jb == 1: bz_all = bz_all + in_score bz_count += 1 elif u_jb == 2: zc_all = zc_all + in_score zc_count += 1 else: pt_all = pt_all + in_score pt_count += 1 # 对不同级别求出平均值并累加,将结果赋予字典中 if bz_count == 0: bz_all_avg = 0 else: bz_all_avg = (bz_all / bz_count) * 0.4 if zc_count == 0: zc_all_avg = 0 else: zc_all_avg = (zc_all / zc_count) * 0.3 if pt_count == 0: pt_all_avg = 0 else: pt_all_avg = (pt_all / pt_count) * 0.3 u['result'] = bz_all_avg + zc_all_avg + pt_all_avg context['user'] = user return render(request, 'score_result.html', context)
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 review(request): if util.base(request) != False: return util.base(request) context = util.user(request) context['review'] = all_review() return render(request, 'review.html', context)