Ejemplo n.º 1
0
    def get_context_data(self, **kwargs):
        context = super(ClubTeamDetailView, self).get_context_data(**kwargs)

        # The team is specified in the URL by its slug
        team = get_object_or_404(ClubTeam, slug=kwargs['slug'])
        context['clubteam'] = team

        # Get the seasons in which this team competed
        part_seasons = Season.objects.filter(clubteamseasonparticipation__team=team).order_by('-start')

        # The season may or may not be specified in the URL by its slug.
        # If it isn't, we use the current season
        season_slug = kwargs_or_none('season_slug', **kwargs)
        if season_slug is not None:
            season = Season.objects.get(slug=season_slug)
        else:
            # Default to the most recent season
            season = part_seasons[0]

        # Retrieve captaincy information for this team
        context['captains'] = TeamCaptaincy.get_captains(team, season)
        context['vice_captains'] = TeamCaptaincy.get_vice_captains(team, season)

        # Get the participation information for this team and season
        try:
            participation = ClubTeamSeasonParticipation.objects.select_related('division__league', 'season').get(team=team, season=season)
            context['participation'] = participation
        except ClubTeamSeasonParticipation.DoesNotExist:
            raise Http404

        add_season_selector(context, season, part_seasons)
        return context
Ejemplo n.º 2
0
    def get_context_data(self, **kwargs):
        context = super(CommitteeSeasonView, self).get_context_data(**kwargs)

        # If we're viewing this season's committee we may not have a season_slug keyword arg.
        season = get_season_from_kwargs(kwargs)

        all_members = CommitteeMembership.objects.select_related('position', 'member', 'season').by_season(season)

        context['general_committee'] = [m for m in all_members if m.position.gender == TeamGender.Mixed]
        ladies_committee = [m for m in all_members if m.position.gender == TeamGender.Ladies]
        mens_committee = [m for m in all_members if m.position.gender == TeamGender.Mens]

        context['ladies_captains'] = [{
            'name': "Ladies 1st team",
            'captain': next((m for m in ladies_committee if m.position.name == "Ladies' 1st XI Captain"), None),
            'vice_captain': next((m for m in ladies_committee if m.position.name == "Ladies' 1st XI Vice-Captain"), None)
        },{
            'name': "Ladies 2nd team",
            'captain': next((m for m in ladies_committee if m.position.name == "Ladies' 2nd XI Captain"), None),
            'vice_captain': next((m for m in ladies_committee if m.position.name == "Ladies' 2nd XI Vice-Captain"), None)
        },{
            'name': "Ladies 3rd team",
            'captain': next((m for m in ladies_committee if m.position.name == "Ladies' 3rd XI Captain"), None),
            'vice_captain': next((m for m in ladies_committee if m.position.name == "Ladies' 3rd XI Vice-Captain"), None)
        },{
            'name': "Ladies 4th team",
            'captain': next((m for m in ladies_committee if m.position.name == "Ladies' 4th XI Captain"), None),
            'vice_captain': next((m for m in ladies_committee if m.position.name == "Ladies' 4th XI Vice-Captain"), None)
        }]


        context['mens_captains'] = [{
            'name': "Mens 1st team",
            'captain': next((m for m in mens_committee if m.position.name == "Men's 1st XI Captain"), None),
            'vice_captain': next((m for m in mens_committee if m.position.name == "Men's 1st XI Vice-Captain"), None)
        },{
            'name': "Mens 2nd team",
            'captain': next((m for m in mens_committee if m.position.name == "Men's 2nd XI Captain"), None),
            'vice_captain': next((m for m in mens_committee if m.position.name == "Men's 2nd XI Vice-Captain"), None)
        },{
            'name': "Mens 3rd team",
            'captain': next((m for m in mens_committee if m.position.name == "Men's 3rd XI Captain"), None),
            'vice_captain': next((m for m in mens_committee if m.position.name == "Men's 3rd XI Vice-Captain"), None)
        },{
            'name': "Mens 4th team",
            'captain': next((m for m in mens_committee if m.position.name == "Men's 4th XI Captain"), None),
            'vice_captain': next((m for m in mens_committee if m.position.name == "Men's 4th XI Vice-Captain"), None)
        },{
            'name': "Mens 5th team",
            'captain': next((m for m in mens_committee if m.position.name == "Men's 5th XI Captain"), None),
            'vice_captain': next((m for m in mens_committee if m.position.name == "Men's 5th XI Vice-Captain"), None)
        }]

        add_season_selector(context, season, Season.objects.reversed())
        return context
Ejemplo n.º 3
0
    def get_context_data(self, **kwargs):
        context = super(ClubTeamDetailView, self).get_context_data(**kwargs)

        # The team is specified in the URL by its slug
        team = get_object_or_404(ClubTeam, slug=kwargs['slug'])
        context['team'] = team

        # Get the seasons in which this team competed
        part_seasons = Season.objects.filter(
            clubteamseasonparticipation__team=team).order_by('-start')

        # The season may or may not be specified in the URL by its slug.
        # If it isn't, we use the current season
        season_slug = kwargs_or_none('season_slug', **kwargs)
        if season_slug is not None:
            season = Season.objects.get(slug=season_slug)
        else:
            # Default to the most recent season
            season = part_seasons[0]

        # Get the participation information for this team and season
        try:
            participation = ClubTeamSeasonParticipation.objects.select_related(
                'division__league', 'season').get(team=team, season=season)
            context['participation'] = participation
        except ClubTeamSeasonParticipation.DoesNotExist:
            raise Http404

        add_season_selector(
            context, season, list(part_seasons.values_list('slug', flat=True)))

        context['props'] = {
            'teamId': team.id,
            'teamGenderlessName': team.genderless_abbr_name(),
            'seasonId': season.id,
            'division': {
                'id': participation.division.id if participation.division else None,
                'name': "{}".format(participation.division),
                'fixturesUrl': participation.division_fixtures_url,
                'leagueTableUrl': participation.division_tables_url,
            },
            'matchFilters': {
                'pageSize': 1000,
                'ourTeam_Slug': team.slug,
                'season_Slug': season.slug,
            },
        }

        return context
Ejemplo n.º 4
0
    def get_context_data(self, **kwargs):
        """ Gets the context data for the view.

            In addition to the 'goalking_list' item, the following are also added to the context:
            - season:               the season these stats applies to
            - season_list:          a list of all seasons
        """
        context = super(AccidentalTouristSeasonView, self).get_context_data(**kwargs)
        season = get_season_from_kwargs(kwargs)

        context['goalking_list'] = self.get_goalking_list(season)

        add_season_selector(context, season, Season.objects.reversed())

        return context
Ejemplo n.º 5
0
    def get_context_data(self, **kwargs):
        """ Gets the context data for the view.

            In addition to the 'team_list' item, the following are also added to the context:
            - season:               the season these stats applies to
            - season_list:          a list of all seasons
            - is_current_season:    True if season == Season.current()
        """
        context = super(SouthernersSeasonView, self).get_context_data(**kwargs)
        season = get_season_from_kwargs(kwargs)

        context['team_list'] = self.get_southerners_list(season)

        add_season_selector(context, season, Season.objects.reversed())

        return context
Ejemplo n.º 6
0
    def get_context_data(self, **kwargs):
        """ Gets the context data for the view.

            In addition to the 'team_list' item, the following are also added to the context:
            - season:               the season these stats applies to
            - season_slug_list:     a list of all seasons
            - is_current_season:    True if season == Season.current()
        """
        context = super(SouthernersSeasonView, self).get_context_data(**kwargs)
        season = get_season_from_kwargs(kwargs)

        context['team_list'] = self.get_southerners_list(season)

        season_slug_list = list(Southerner.objects.order_by(
            '-season').values_list('season__slug', flat=True).distinct())

        add_season_selector(context, season, season_slug_list)

        return context
Ejemplo n.º 7
0
    def get_context_data(self, **kwargs):
        context = super(CommitteeSeasonView, self).get_context_data(**kwargs)

        # If we're viewing this season's committee we may not have a season_slug keyword arg.
        season = get_season_from_kwargs(kwargs)

        all_members = CommitteeMembership.objects.select_related(
            'position', 'member', 'season').filter(season=season).order_by('position__index')

        context['general_committee'] = [
            m for m in all_members if m.position.gender == TeamGender.Mixed]
        ladies_committee = [
            m for m in all_members if m.position.gender == TeamGender.Ladies]
        mens_committee = [
            m for m in all_members if m.position.gender == TeamGender.Mens]

        ladies_team_names = list(
            ClubTeam.objects.ladies().values_list('long_name', flat=True))
        mens_team_names = list(
            ClubTeam.objects.mens().values_list('long_name', flat=True))

        context['mens_captains'] = self.get_captains(
            mens_committee, mens_team_names)

        context['ladies_captains'] = self.get_captains(
            ladies_committee, ladies_team_names)

        context['mixed_captains'] = {
            'name': "Mixed XI",
            'captain': next((m for m in mens_committee if m.position.name == "Men's Mixed XI Co-Captain"), None),
            'vice_captain': next((m for m in ladies_committee if m.position.name == "Ladies' Mixed XI Co-Captain"), None)
        }

        season_slug_list = list(CommitteeMembership.objects.order_by(
            '-season').values_list('season__slug', flat=True).distinct())

        add_season_selector(
            context, season, season_slug_list)

        return context
Ejemplo n.º 8
0
    def get_context_data(self, **kwargs):
        """ Gets the context data for the view.

            In addition to the 'goalking_list' item, the following are also added to the context:
            - season:               the season these stats applies to
            - season_list:          a list of all seasons
        """
        context = super(AccidentalTouristSeasonView,
                        self).get_context_data(**kwargs)
        season = get_season_from_kwargs(kwargs)

        context['goalking_list'] = self.get_goalking_list(season)

        context['max_miles'] = context['goalking_list'][0].total_miles

        season_slug_list = list(
            GoalKing.objects.order_by('-season').values_list(
                'season__slug', flat=True).distinct())

        add_season_selector(context, season, season_slug_list)

        return context
Ejemplo n.º 9
0
    def get_context_data(self, **kwargs):
        context = super(MatchesBySeasonView, self).get_context_data(**kwargs)
        season = get_season_from_kwargs(kwargs)

        match_qs = Match.objects.select_related('our_team', 'opp_team__club', 'venue',
                                                'division__league', 'cup', 'season')
        match_qs = match_qs.filter(season=season)
        match_qs = match_qs.defer('report_body', 'pre_match_hype')
        match_qs = match_qs.order_by('date', 'time')

        # Group matches by calendar year (e.g. Sept-Dec in one group, Jan-April in the other)
        year1 = [m for m in match_qs if m.date.year == season.start.year]
        year2 = [m for m in match_qs if m.date.year == season.end.year]

        matches_by_year = {
            season.start.year: self.group_by_month(year1),
            season.end.year: self.group_by_month(year2)
        }

        context['matches_by_year'] = matches_by_year

        add_season_selector(context, season, Season.objects.reversed())

        return context