示例#1
0
文件: views.py 项目: csdl/makahiki
def prize_summary(request, round_name):
    """display summary of the winners."""

    round_name = round_name.replace('-', ' ').capitalize()
    individual_team_prize = Prize.objects.filter(round=RoundSetting.objects.get(name=round_name),
                         competition_type="points",
                         award_to="individual_team")
    teams = Team.objects.all()

    if individual_team_prize:
        individual_team_prize = individual_team_prize[0]
        for team in teams:
            team.leader = individual_team_prize.leader(team=team)

    team_energy_goal_prize = Prize.objects.filter(round=RoundSetting.objects.get(name=round_name),
                         competition_type="energy_goal",
                         award_to="team_overall")
    energy_team_ra = None
    if team_energy_goal_prize:
        team_energy_goal_prize = team_energy_goal_prize[0]
        energy_team_ra = Profile.objects.filter(team__name=team_energy_goal_prize.leader(),
                               is_ra=True)

    team_points_prize = Prize.objects.filter(round=RoundSetting.objects.get(name=round_name),
                                             competition_type="points",
                                             award_to="team_overall")
    point_team_ra = None
    if team_points_prize:
        team_points_prize = team_points_prize[0]
        point_team_ra = Profile.objects.filter(team__name=team_points_prize.leader(),
                                                is_ra=True)

    points_leader = score_mgr.player_points_leaders(round_name=round_name)
    if points_leader:
        points_leader = points_leader[0]
    return render_to_response("view_prizes/summary.html", {
        "team_energy_goal_prize": team_energy_goal_prize,
        "energy_team_ra": energy_team_ra,
        "goal": resource_goal.resource_goal_ranks("energy", round_name)[0]["completions"],

        "team_points_prize": team_points_prize,
        "team_point": team_mgr.team_points_leaders(round_name=round_name)[0]["points"],
        "team_participation": team_mgr.team_active_participation(
            round_name=round_name)[0].active_participation,
        "point_team_ra": point_team_ra,

        "individual_overall_prize": Prize.objects.filter(
                                    round=RoundSetting.objects.get(name=round_name),
                                                  competition_type="points",
                                                  award_to="individual_overall")[0],
        "individual_point": points_leader["points"] if points_leader else None,

        "individual_team_prize": individual_team_prize,
        "teams": teams
    }, context_instance=RequestContext(request))
示例#2
0
def points_leaders(num_results=None, round_name=None):
    """Returns the points leaders out of all users, as a dictionary object
    with profile__name and points.
    """
    entries = score_mgr.player_points_leaders(num_results=num_results, round_name=round_name)
    if entries:
        return entries
    else:
        results = Profile.objects.all().extra(select={'profile__name': 'name', 'points': 0}).values(
            'profile__name', 'points')
        if num_results:
            results = results[:num_results]
        return results
示例#3
0
def points_leaders(num_results=None, round_name=None):
    """Returns the points leaders out of all users, as a dictionary object
    with profile__name and points.
    """
    entries = score_mgr.player_points_leaders(num_results=num_results,
                                              round_name=round_name)
    if entries:
        return entries
    else:
        results = Profile.objects.all().extra(select={
            'profile__name': 'name',
            'points': 0
        }).values('profile__name', 'points')
        if num_results:
            results = results[:num_results]
        return results
示例#4
0
def prize_summary(request, round_name):
    """display summary of the winners."""

    round_name = round_name.replace('-', ' ').capitalize()
    individual_team_prize = Prize.objects.filter(
        round=RoundSetting.objects.get(name=round_name),
        competition_type="points",
        award_to="individual_team")
    teams = Team.objects.all()

    if individual_team_prize:
        individual_team_prize = individual_team_prize[0]
        for team in teams:
            team.leader = individual_team_prize.leader(team=team)

    team_energy_goal_prize = Prize.objects.filter(
        round=RoundSetting.objects.get(name=round_name),
        competition_type="energy_goal",
        award_to="team_overall")
    energy_team_ra = None
    if team_energy_goal_prize:
        team_energy_goal_prize = team_energy_goal_prize[0]
        energy_team_ra = Profile.objects.filter(
            team__name=team_energy_goal_prize.leader(), is_ra=True)

    team_points_prize = Prize.objects.filter(
        round=RoundSetting.objects.get(name=round_name),
        competition_type="points",
        award_to="team_overall")
    point_team_ra = None
    if team_points_prize:
        team_points_prize = team_points_prize[0]
        point_team_ra = Profile.objects.filter(
            team__name=team_points_prize.leader(), is_ra=True)

    points_leader = score_mgr.player_points_leaders(round_name=round_name)
    if points_leader:
        points_leader = points_leader[0]
    return render_to_response("view_prizes/summary.html", {
        "team_energy_goal_prize":
        team_energy_goal_prize,
        "energy_team_ra":
        energy_team_ra,
        "goal":
        resource_goal.resource_goal_ranks("energy",
                                          round_name)[0]["completions"],
        "team_points_prize":
        team_points_prize,
        "team_point":
        team_mgr.team_points_leaders(round_name=round_name)[0]["points"],
        "team_participation":
        team_mgr.team_active_participation(
            round_name=round_name)[0].active_participation,
        "point_team_ra":
        point_team_ra,
        "individual_overall_prize":
        Prize.objects.filter(round=RoundSetting.objects.get(name=round_name),
                             competition_type="points",
                             award_to="individual_overall")[0],
        "individual_point":
        points_leader["points"] if points_leader else None,
        "individual_team_prize":
        individual_team_prize,
        "teams":
        teams
    },
                              context_instance=RequestContext(request))