def deleteAll(request): logger.info(unicode(request).replace('\n', '\t')) try: Team.delAllTeam(); Contestant.delAllContestant(); return redirect('Register:view_teams') except Exception as e: logger.error('delete FAILED!') return redirect('Register:view_teams')
def addTeamMember(request, tid): logger.info(unicode(request).replace("\n", "\t")) tid = int(tid) try: team = Team.getSessionTeam(request.session) except Exception as e: request.session["team_id"] = None messages.add_message(request, messages.INFO, u"请先登录!") return redirect("Register:team_login") try: if team.pk != tid: raise Exception(u"您没有查看该队伍信息的权限!") target_team = Team.getById(tid) if request.method != "POST": return render( request, "newtpl/register/add_member.html", { "target_team": target_team, "gender_choices": Const.GENDER_CHOICES, "school_choices": Const.SCHOOL_CHOICES, "grade_choices": Const.GRADE_CHOICES, }, ) form = ContestantForm(request.POST) if form.is_valid(): name = form.cleaned_data["name"] gender = form.cleaned_data["gender"] email = form.cleaned_data["email"] grade = form.cleaned_data["grade"] mobile = form.cleaned_data["mobile"] student_id = form.cleaned_data["student_id"] class_id = form.cleaned_data["class_id"] school = form.cleaned_data["school"] Contestant.addContestant(name, gender, grade, email, mobile, student_id, class_id, school, target_team) else: raise Exception(u"输入的内容不合法!") # Success messages.add_message(request, messages.SUCCESS, u"添加队员%s成功!请等待管理员审核" % name) target_team.status = "等待审核" target_team.updateStatus("Pending") return redirect("Register:team_info", tid) except Exception as e: logger.error(unicode(e).replace("\n", "\t")) messages.add_message(request, messages.INFO, unicode(e)) return redirect("Register:team_info", team.pk)
def viewAllTeams(request): logger.info(unicode(request).replace("\n", "\t")) try: admin = request.session.get("admin", None) if not admin: messages.add_message(request, messages.INFO, unicode("Invalid Key")) return redirect("Register:admin_login") team_list = Team.getAllTeams() pending = team_list.filter(status="Pending").count() accepted = team_list.filter(status="Accepted").count() failed = team_list.filter(status="Failed").count() skipped = team_list.filter(status="Skipped").count() teams = [] for team in team_list: members = Contestant.getTeamContestant(team) teams.append({"info": team, "members": members}) return render( request, "newtpl/register/view_teams.html", {"teams": teams, "pending": pending, "accepted": accepted, "failed": failed, "skipped": skipped}, ) except Exception as e: logger.error(unicode(e).replace("\n", "\t")) messages.add_message(request, messages.INFO, unicode(e)) return redirect("Register:view_teams")
def judgeTeam(request, tid = 1): logger.info(unicode(request).replace('\n', '\t')) try: admin = request.session.get('admin', None) if not admin: messages.add_message(request, messages.INFO, u'Not admin!') return redirect('Register:admin_login') tid = int(tid) team = None while True: if tid > Team.getMaxId(): raise Exception('No Pending Teams!') try: team = Team.getById(tid) except: tid += 1 continue if team.status == 'Skipped' or team.status == 'Pending': break tid += 1 team_list = Team.getAllTeams() pending = team_list.filter(status = 'Pending').count() accepted = team_list.filter(status = 'Accepted').count() failed = team_list.filter(status = 'Failed').count() skipped = team_list.filter(status = 'Skipped').count() members = Contestant.getTeamContestant(team) return render(request, 'newtpl/register/judge_team.html', {'team': team, 'members': members, 'pending': pending, 'accepted': accepted, 'failed': failed, 'skipped': skipped, 'admin': True}) except Exception as e: logger.error(unicode(e).replace('\n', '\t')) messages.add_message(request, messages.INFO, unicode(e)) return redirect('Register:view_teams')
def judgeTeam(request, tid = 1): logger.info(unicode(request).replace('\n', '\t')) try: admin = request.session.get('admin', None) if not admin: messages.add_message(request, messages.INFO, u'Not admin!') return redirect('Register:admin_login') tid = int(tid) team = None while True: try: team = Team.getById(tid) except: raise Exception('No Pending Teams!') if team.status == 'Skipped' or team.status == 'Pending': break tid += 1 team_list = Team.getAllTeams() pending = team_list.filter(status = 'Pending').count() accepted = team_list.filter(status = 'Accepted').count() failed = team_list.filter(status = 'Failed').count() skipped = team_list.filter(status = 'Skipped').count() members = Contestant.getTeamContestant(team) return render(request, 'newtpl/register/judge_team.html', {'team': team, 'members': members, 'pending': pending, 'accepted': accepted, 'failed': failed, 'skipped': skipped, 'admin': True}) except Exception as e: logger.error(unicode(e).replace('\n', '\t')) messages.add_message(request, messages.INFO, unicode(e)) return redirect('Register:view_teams')
def addTeamMember(request, tid): logger.info(unicode(request).replace('\n', '\t')) tid = int(tid) try: team = Team.getSessionTeam(request.session) except Exception as e: request.session['team_id'] = None messages.add_message(request, messages.INFO, u'请先登录!') return redirect('Register:team_login') try: if team.pk != tid: raise Exception(u'您没有查看该队员信息的权限!') target_team = Team.getById(tid) if request.method != 'POST': return render(request, 'newtpl/register/add_member.html', {'target_team': target_team, 'gender_choices': Const.GENDER_CHOICES, 'school_choices': Const.SCHOOL_CHOICES, 'grade_choices': Const.GRADE_CHOICES}) form = ContestantForm(request.POST) if form.is_valid(): name = form.cleaned_data['name'] gender = form.cleaned_data['gender'] email = form.cleaned_data['email'] grade = form.cleaned_data['grade'] mobile = form.cleaned_data['mobile'] student_id = form.cleaned_data['student_id'] class_id = form.cleaned_data['class_id'] school = form.cleaned_data['school'] info = form.cleaned_data['info'] Contestant.addContestant(name, gender, grade, email, mobile, student_id, class_id, school, info, target_team) else: raise Exception(u'输入信息不合法!') # Success messages.add_message(request, messages.SUCCESS, u'完善信息成功!请等待管理员审核') target_team.status = '等待审核' target_team.updateStatus('Pending') return redirect('Register:team_info', tid) except Exception as e: logger.error(unicode(e).replace('\n', '\t')) messages.add_message(request, messages.INFO, unicode(e)) return redirect('Register:team_info', team.pk)
def addTeamMember(request, tid): logger.info(unicode(request).replace('\n', '\t')) tid = int(tid) try: team = Team.getSessionTeam(request.session) except Exception as e: request.session['team_id'] = None messages.add_message(request, messages.INFO, u'请先登录!') return redirect('Register:team_login') try: if team.pk != tid: raise Exception(u'您没有查看该队伍信息的权限!') target_team = Team.getById(tid) if request.method != 'POST': return render(request, 'newtpl/register/add_member.html', {'target_team': target_team, 'gender_choices': Const.GENDER_CHOICES, 'school_choices': Const.SCHOOL_CHOICES, 'grade_choices': Const.GRADE_CHOICES}) form = ContestantForm(request.POST) if form.is_valid(): name = form.cleaned_data['name'] gender = form.cleaned_data['gender'] email = form.cleaned_data['email'] grade = form.cleaned_data['grade'] mobile = form.cleaned_data['mobile'] student_id = form.cleaned_data['student_id'] class_id = form.cleaned_data['class_id'] school = form.cleaned_data['school'] Contestant.addContestant(name, gender, grade, email, mobile, student_id, class_id, school, target_team) else: raise Exception(u'输入的内容不合法!') # Success messages.add_message(request, messages.SUCCESS, u'添加队员%s成功!请等待管理员审核' % name) target_team.status = '等待审核' target_team.updateStatus('Pending') return redirect('Register:team_info', tid) except Exception as e: logger.error(unicode(e).replace('\n', '\t')) messages.add_message(request, messages.INFO, unicode(e)) return redirect('Register:team_info', team.pk)
def teamInfo(request, tid): logger.info(unicode(request).replace('\n', '\t')) tid = int(tid) try: team = Team.getSessionTeam(request.session) except Exception as e: messages.add_message(request, messages.INFO, u'请先登录!') return redirect('Register:team_login') try: if team.pk != tid: raise Exception(u'您没有查看该队伍信息的权限!') target_team = Team.getById(tid) members = Contestant.getTeamContestant(target_team) full = True if len(members) >= 3 else False return render(request, 'newtpl/register/team_info.html', {'target_team': target_team, 'members': members, 'full': full}) except Exception as e: logger.error(unicode(e).replace('\n', '\t')) messages.add_message(request, messages.INFO, unicode(e)) return redirect('Register:team_info', team.pk)
def teamInfo(request, tid): logger.info(unicode(request).replace('\n', '\t')) tid = int(tid) try: team = Team.getSessionTeam(request.session) except Exception as e: messages.add_message(request, messages.INFO, u'请先登录!') return redirect('Register:team_login') try: if team.pk != tid: raise Exception(u'您没有查看该队员信息的权限!') target_team = Team.getById(tid) members = Contestant.getTeamContestant(target_team) full = True if len(members) >= 3 else False return render(request, 'newtpl/register/team_info.html', {'target_team': target_team, 'members': members, 'full': full}) except Exception as e: logger.error(unicode(e).replace('\n', '\t')) messages.add_message(request, messages.INFO, unicode(e)) return redirect('Register:team_info', team.pk)
def judgeTeam(request, tid=1): logger.info(unicode(request).replace("\n", "\t")) try: admin = request.session.get("admin", None) if not admin: messages.add_message(request, messages.INFO, u"Not admin!") return redirect("Register:admin_login") tid = int(tid) team = None while True: try: team = Team.getById(tid) except: raise Exception("No Pending Teams!") if team.status == "Skipped" or team.status == "Pending": break tid += 1 team_list = Team.getAllTeams() pending = team_list.filter(status="Pending").count() accepted = team_list.filter(status="Accepted").count() failed = team_list.filter(status="Failed").count() skipped = team_list.filter(status="Skipped").count() members = Contestant.getTeamContestant(team) return render( request, "newtpl/register/judge_team.html", { "team": team, "members": members, "pending": pending, "accepted": accepted, "failed": failed, "skipped": skipped, "admin": True, }, ) except Exception as e: logger.error(unicode(e).replace("\n", "\t")) messages.add_message(request, messages.INFO, unicode(e)) return redirect("Register:view_teams")
def modifyTeamMember(request, cid): logger.info(unicode(request).replace('\n', '\t')) cid = int(cid) try: team = Team.getSessionTeam(request.session) except Exception as e: request.session['team_id'] = None messages.add_message(request, messages.INFO, u'请先登录!') return redirect('Register:team_login') try: contestant = Contestant.getById(cid) belong_team = contestant.team if team.pk != belong_team.pk: raise Exception(u'您没有查看该队员信息的权限!') if request.method != 'POST': return render(request, 'newtpl/register/modify_member.html', {'gender_choices': Const.GENDER_CHOICES, 'school_choices': Const.SCHOOL_CHOICES, 'grade_choices': Const.GRADE_CHOICES, 'contestant': contestant}) form = ContestantForm(request.POST) if form.is_valid(): name = form.cleaned_data['name'] gender = form.cleaned_data['gender'] email = form.cleaned_data['email'] grade = form.cleaned_data['grade'] mobile = form.cleaned_data['mobile'] student_id = form.cleaned_data['student_id'] class_id = form.cleaned_data['class_id'] school = form.cleaned_data['school'] info = form.cleaned_data['info'] contestant.modifyContestant(name, gender, grade, email, mobile, student_id, class_id, school, info, belong_team) else: raise Exception(u'输入的内容不合法!') # Success messages.add_message(request, messages.SUCCESS, u'修改队员信息%s成功!请等待管理员审核' % name) belong_team.updateStatus('Pending') return redirect('Register:team_info', belong_team.pk) except Exception as e: logger.error(unicode(e).replace('\n', '\t')) messages.add_message(request, messages.INFO, unicode(e)) return redirect('Register:modify_member', cid)
def modifyTeamMember(request, cid): logger.info(unicode(request).replace('\n', '\t')) cid = int(cid) try: team = Team.getSessionTeam(request.session) except Exception as e: request.session['team_id'] = None messages.add_message(request, messages.INFO, u'请先登录!') return redirect('Register:team_login') try: contestant = Contestant.getById(cid) belong_team = contestant.team if team.pk != belong_team.pk: raise Exception(u'您没有查看该队伍信息的权限!') if request.method != 'POST': return render(request, 'newtpl/fresh/modify_member.html', {'gender_choices': Const.GENDER_CHOICES, 'school_choices': Const.SCHOOL_CHOICES, 'grade_choices': Const.GRADE_CHOICES, 'contestant': contestant}) form = ContestantForm(request.POST) if form.is_valid(): name = form.cleaned_data['name'] gender = form.cleaned_data['gender'] email = form.cleaned_data['email'] grade = form.cleaned_data['grade'] mobile = form.cleaned_data['mobile'] student_id = form.cleaned_data['student_id'] class_id = form.cleaned_data['class_id'] school = form.cleaned_data['school'] contestant.modifyContestant(name, gender, grade, email, mobile, student_id, class_id, school, belong_team) else: raise Exception(u'输入的内容不合法!') # Success messages.add_message(request, messages.SUCCESS, u'修改队员%s成功!请等待管理员审核' % name) belong_team.updateStatus('Pending') return redirect('Register:team_info', belong_team.pk) except Exception as e: logger.error(unicode(e).replace('\n', '\t')) messages.add_message(request, messages.INFO, unicode(e)) return redirect('Register:modify_member', cid)
def teamInfo(request, tid): logger.info(unicode(request).replace("\n", "\t")) tid = int(tid) try: team = Team.getSessionTeam(request.session) except Exception as e: messages.add_message(request, messages.INFO, u"请先登录!") return redirect("Register:team_login") try: if team.pk != tid: raise Exception(u"您没有查看该队伍信息的权限!") target_team = Team.getById(tid) members = Contestant.getTeamContestant(target_team) full = True if len(members) >= 3 else False return render( request, "newtpl/register/team_info.html", {"target_team": target_team, "members": members, "full": full} ) except Exception as e: logger.error(unicode(e).replace("\n", "\t")) messages.add_message(request, messages.INFO, unicode(e)) return redirect("Register:team_info", team.pk)
def viewAcceptedTeams(request): logger.info(unicode(request).replace("\n", "\t")) try: admin = request.session.get("admin", None) if not admin: messages.add_message(request, messages.INFO, unicode("Invalid Key")) return redirect("Register:admin_login") all_team_list = Team.getAllTeams() ac_team_list = all_team_list.filter(status="Accepted") # ac_team_list = all_team_list.filter(status = 'Finals') # ac_team_list = all_team_list.filter(status = 'Bronze') teams = [] for team in ac_team_list: members = Contestant.getTeamContestant(team) teams.append({"info": team, "members": members}) return render(request, "newtpl/register/view_accepted_teams.html", {"teams": teams}) except Exception as e: logger.error(unicode(e).replace("\n", "\t")) messages.add_message(request, messages.INFO, unicode(e)) return redirect("Register:view_accepted_teams")
def viewAcceptedTeams(request): logger.info(unicode(request).replace('\n', '\t')) try: admin = request.session.get('admin', None) if not admin: messages.add_message(request, messages.INFO, unicode('Invalid Key')) return redirect('Register:admin_login') all_team_list = Team.getAllTeams() ac_team_list = all_team_list.filter(status = 'Accepted') #ac_team_list = all_team_list.filter(status = 'Finals') #ac_team_list = all_team_list.filter(status = 'Bronze') teams = [] for team in ac_team_list: members = Contestant.getTeamContestant(team) teams.append({'info': team, 'members': members}) return render(request, 'newtpl/register/view_accepted_teams.html', {'teams': teams}) except Exception as e: logger.error(unicode(e).replace('\n', '\t')) messages.add_message(request, messages.INFO, unicode(e)) return redirect('Register:view_accepted_teams')
def viewAllTeams(request): logger.info(unicode(request).replace('\n', '\t')) try: admin = request.session.get('admin', None) if not admin: messages.add_message(request, messages.INFO, unicode('Invalid Key')) return redirect('Register:admin_login') team_list = Team.getAllTeams() pending = team_list.filter(status = 'Pending').count() accepted = team_list.filter(status = 'Accepted').count() failed = team_list.filter(status = 'Failed').count() skipped = team_list.filter(status = 'Skipped').count() teams = [] for team in team_list: members = Contestant.getTeamContestant(team) teams.append({'info': team, 'members': members}) return render(request, 'newtpl/register/view_teams.html', {'teams': teams, 'pending': pending, 'accepted': accepted, 'failed': failed, 'skipped': skipped}) except Exception as e: logger.error(unicode(e).replace('\n', '\t')) messages.add_message(request, messages.INFO, unicode(e)) return redirect('Register:view_teams')