def applicationView(request, is_submited): re_id = request.GET.get("re_id") re_obj = Re_Project_Expert.objects.get(id = re_id) pid = re_obj.project.project_id score_table = getScoreTable(re_obj.project).objects.get(re_obj = re_obj) context = appManage(request, pid, is_submited) file_list = getSingleProjectURLList(re_obj.project)[:1] if request.method == "GET": score_form = getScoreForm(re_obj.project)(instance = score_table) context.update({ 'score_form': score_form, 're_obj': re_obj, 'file_list': file_list, 'user': '******', }) return render(request, "expert/application.html", context) else: score_form = getScoreForm(re_obj.project)(request.POST, instance = score_table) if score_form.is_valid(): score_form.save() return HttpResponseRedirect("/expert/redirect/?is_first_round=1") else: context.update({ 'score_form': score_form, 're_obj': re_obj, 'file_list': file_list, 'error': score_form.errors, "user": "******", }) return render(request, "expert/application.html", context)
def getScore(request, pid): message = "" project = ProjectSingle.objects.get(project_id=pid) is_first_round = True if project.project_status.status == PROJECT_STATUS_FINAL_EXPERT_SUBJECT: is_first_round = False if is_first_round: scoreTableType = getScoreTable(project) else: scoreTableType = getFinalScoreTable(project) comments_index = scoreTableType.has_comments() #scoreFormType = getScoreForm(project) if is_first_round: scoreFormType = getScoreForm(project) else: scoreFormType = getFinalScoreForm(project) scoreList = [] ave_score = {} tem = scoreTableType.objects.all() for re_obj in Re_Project_Expert.objects.filter( Q(project=project) & Q(is_first_round=is_first_round)): table = scoreTableType.objects.get_or_create(re_obj=re_obj)[0] score_row = scoreFormType(instance=table) if table.get_total_score() == 0: continue for i, field in enumerate(score_row): if i == comments_index: continue ave_score[i] = ave_score.get(i, 0) + int(field.value()) score_row.expert_name = re_obj.expert score_row.total_score = table.get_total_score() ave_score["total"] = ave_score.get("total", 0) + score_row.total_score score_row.comments = table.get_comments() scoreList.append(score_row) if len(scoreList): for item in ave_score.items(): ave_score[item[0]] = 1.0 * item[1] / len(scoreList) html = render_to_string( "widgets/concluding_data.html", { "scoreList": scoreList, "ave_score": ave_score.values(), "form": scoreFormType, "comments_index": comments_index, }) return simplejson.dumps({ "message": message, "html": html, })
def get_single_project_average_score(project): is_first_round = True if project.project_status.status == PROJECT_STATUS_FINAL_REVIEW_OVER: is_first_round = False scoreTableType = getScoreTable(project) scoreFormType = getScoreForm(project) ave_score = 0 item_count = 0 for re_obj in Re_Project_Expert.objects.filter(Q(project = project) & Q(is_first_round = is_first_round)): table = scoreTableType.objects.get(re_obj = re_obj) score_row = scoreFormType(instance = table) ave_score += sum(field.value() for field in score_row) item_count += 1 if item_count: ave_score /= 1.0 * item_count return ave_score
def getScore(request, pid): message = "" project = ProjectSingle.objects.get(project_id = pid) is_first_round = True if project.project_status.status == PROJECT_STATUS_FINAL_EXPERT_SUBJECT: is_first_round = False if is_first_round:scoreTableType = getScoreTable(project) else:scoreTableType = getFinalScoreTable(project) comments_index = scoreTableType.has_comments() #scoreFormType = getScoreForm(project) if is_first_round:scoreFormType=getScoreForm(project) else: scoreFormType=getFinalScoreForm(project) scoreList = [] ave_score = {} tem = scoreTableType.objects.all() for re_obj in Re_Project_Expert.objects.filter(Q(project = project) & Q(is_first_round = is_first_round)): table = scoreTableType.objects.get_or_create(re_obj = re_obj)[0] score_row = scoreFormType(instance = table) if table.get_total_score() == 0: continue for i, field in enumerate(score_row): if i == comments_index: continue ave_score[i] = ave_score.get(i, 0) + int(field.value()) score_row.expert_name = re_obj.expert score_row.total_score = table.get_total_score() ave_score["total"] = ave_score.get("total", 0) + score_row.total_score score_row.comments = table.get_comments() scoreList.append(score_row) if len(scoreList): for item in ave_score.items(): ave_score[item[0]] = 1.0 * item[1] / len(scoreList) html = render_to_string("widgets/concluding_data.html", {"scoreList": scoreList, "ave_score": ave_score.values(), "form": scoreFormType, "comments_index": comments_index, }) return simplejson.dumps({"message": message, "html": html,})