Esempio n. 1
0
    def get(self, request, player_id=None):
        player_id = int(player_id)

        context = self.get_context_data()

        try:
            player = Player.objects.get(id=player_id)
        except Player.DoesNotExist:
            raise Http404('Could not find player %d.' % player_id)

        teams = Team.objects\
            .filter(Q(member0=player) | Q(member1=player) | Q(member2=player) | Q(member3=player))\
            .select_related('member0', 'member1', 'member2', 'member3')\
            .order_by('mode', '-league')

        context['player'] = player
        context['bnet_url'] = get_bnet_url(player)
        context['teams'] = teams

        _, season_id = last_updated_info()

        for team in teams:
            if team.season_id == season_id:
                team.ladder_url \
                    = urlresolvers.reverse('ladder',
                                           kwargs={'version': Version.key_by_ids.get(team.version, Version.DEFAULT),
                                                   'mode': Mode.key_by_ids[team.mode],
                                                   'reverse': '',
                                                   'sort_key': 'ladder-rank'})\
                    + "?team=%d" % team.id

        return self.render_to_response(context)
Esempio n. 2
0
    def get(self, request, team_id=None):
        team_id = int(team_id)

        context = self.get_context_data()

        try:
            team = Team.objects.select_related('member0', 'member1', 'member2',
                                               'member3').get(id=team_id)
            context['team'] = team
        except Team.DoesNotExist:
            raise Http404('Could not find team %d.' % team_id)

        context['members'] = [
            m
            for m in [team.member0, team.member1, team.member2, team.member3]
            if m
        ]
        context['leagues'] = [
            League.name_by_ids[i]
            for i in range(League.BRONZE, League.GRANDMASTER + 1)
        ]
        context['seasons'] = get_season_list()
        context['last_updated'], season_id = last_updated_info()

        if team.season_id == season_id:
            url = reverse('ladder',
                          kwargs={'version': Version.key_by_ids.get(team.version),
                                  'mode': Mode.key_by_ids[team.mode],
                                  'reverse': '',
                                  'sort_key': 'ladder-rank'})\
                + "?team=%d" % team.id
            context['ladder_href'] = url

        return self.render_to_response(context)
Esempio n. 3
0
 def get_context_data(self, **kwargs):
     context = super().get_context_data(**kwargs)
     context['last_updated'], _ = last_updated_info()
     context['versions'] = list(reversed(Version.ranking_ids))
     context['leagues'] = list(reversed(League.ranking_ids))
     context['races'] = [r for r in Race.ranking_ids if r != Race.UNKNOWN
                         ] + [Race.UNKNOWN]  # Make better order.
     context['regions'] = [Region.ALL] + Region.ranking_ids
     context['seasons'] = get_season_list()
     context['mode_id'] = self.mode_id
     context['mode_got_race_stats'] = Mode.team_size(
         self.mode_id) == 1 or self.mode_id == Mode.ARCHON
     return context