def add_latest_results_to_context(context): """ Helper method to add latest results to a context dictionary. context = the view context (a dictionary) Returns: the context dictionary, with a 'latest_results' entry containing a list of results The latest_results list contains a maximum of one result per team. Results are only included if the team is active and the match was played this season. """ latest_results = [] current_season = Season.current() today = timezone.now().date() for team in ClubTeam.objects.only('pk'): match_qs = Match.objects.select_related('our_team', 'opp_team__club', 'venue', 'division__league', 'cup', 'season') match_qs = match_qs.filter(our_team__active=True, our_team_id=team.pk, date__lte=today, season=current_season) match_qs = match_qs.order_by('-date', '-time') if match_qs.exists(): # Have to ignore matches that are today but still in future. dt_now = datetime.now() for m in match_qs: if m.datetime() < dt_now: latest_results.append(m) break context['latest_results'] = latest_results
def addLatestResultsToContext(self, context): """ Helper method to add latest results to a context dictionary. context = the view context (a dictionary) Adds a 'latest_results' entry to the context dictionary containing a list of dates, with each date containing the matches played on that date, ordered by team position The latest_results list contains a maximum of one result per team. Results are only included if the team is active and the match was played this season. """ latest_results = [] current_season = Season.current() today = timezone.now().date() dt_now = datetime.now() for team in ClubTeam.objects.active().only('pk'): match_qs = Match.objects.select_related('our_team', 'opp_team__club', 'venue', 'division__league', 'cup', 'season') match_qs = match_qs.filter(our_team_id=team.pk, date__lte=today, season=current_season) match_qs = match_qs.order_by('-date', '-time') # Have to ignore matches that are today but still in future. for m in match_qs: if m.datetime() < dt_now: latest_results.append(m) break context['latest_results'] = self.group_by_date(latest_results, True)
def get_context_data(self, **kwargs): context = super(MemberListView, self).get_context_data(**kwargs) current_season = Season.current() context['props'] = { 'canViewMap': self.request.user.has_perm('members.view_personal_data'), 'currentSeason': current_season.slug, 'teams': list(ClubTeam.objects.active().exclude(slug__in=['indoor', 'mixed']).values('long_name', 'slug')), } return context
def get_context_data(self, **kwargs): context = super(VenueListView, self).get_context_data(**kwargs) current_season = Season.current() context['props'] = { 'currentSeason': current_season.slug, 'teams': js_clubteams(True), 'divisions': js_divisions(current_season), } return context
def get_season_from_kwargs(kwargs): """ Many URLs have an optional 'season_slug' parameter, specifying a particular season. If not specified, we default to 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: season = Season.current() return season
def get_context_data(self, **kwargs): context = super(GoalKingView, self).get_context_data(**kwargs) context['props'] = { 'seasons': list( GoalKing.objects.order_by('-season').values_list( 'season__slug', flat=True).distinct()), 'teams': list(ClubTeam.objects.active().values('long_name', 'slug')), 'current_season': Season.current().slug, } return context
def handle(self, *args, **options): errors = [] season = Season.current() try: # Update goal king GoalKing.update_for_season(season) except Exception as e: errors.append("Failed to update Goal-King: {}".format(e)) try: # Update Southerners league update_southerners_stats_for_season(season) except Exception as e: errors.append("Failed to update Southerners League: {}".format(e)) try: # Update opposition stats update_all_club_stats() except Exception as e: errors.append("Failed to update Opposition Club Stats: {}".format(e)) try: # Update ClubTeamSeasonParticipation stats update_participation_stats_for_season(season) except Exception as e: errors.append("Failed to update Club Team Season Participation Stats: {}".format(e)) # Scrape league tables participations = ClubTeamSeasonParticipation.objects.current().select_related('team', 'division') for participation in participations: try: DivisionResult.objects.league_table(season=season, division=participation.division).delete() try: league_scraper.get_east_leagues_nw_division(participation.division_tables_url, participation.division, season) except Exception as e: print "Failed to parse league table: {}".format(e) except Exception as e: errors.append("Failed to scrape league table from {}: {}".format(participation.division_tables_url, e)) try: # Delete all training session entries from before yesterday (we don't care about # training sessions in the past) self.purge_training_sessions() except Exception as e: errors.append("Failed to purge training sessions: {}".format(e)) if errors: send_mail("Nightly build task failed", "\n".join(errors), '*****@*****.**', ['*****@*****.**'])
def current(self): """ Returns just the participations for the current season""" return self.get_queryset().filter(season=Season.current())
def changefreq(self, item): if item == Season.current(): return 'monthly' else: return 'yearly'
def current(self): """ Returns only current committee membership, if any.""" return self.filter(season=Season.current()).order_by('position__index')
def changefreq(self, item): if item == Season.current(): return 'monthly' else: return 'never'
def priority(self, item): if item == Season.current(): return 1.0 else: return 0.7
def current(self): """ Returns only current squad membership, if any.""" return self.get_queryset().filter(season=Season.current())
def this_season(self): """Returns only training sessions for this season""" season = Season.current() return self.filter(datetime__gte=season.start, datetime__lte=season.end).order_by('datetime')
def this_season(self): """ Returns only this season's matches""" return self.by_season(Season.current())
def current(self): """ Returns only current committee membership, if any.""" return self.get_queryset().filter( season=Season.current()).order_by('position__index')
def handle(self, *args, **options): errors = [] season = Season.current() try: # Update goal king GoalKing.update_for_season(season) print('Updated Goal King entries for the current season') except Exception as e: errors.append("Failed to update Goal-King: {}".format(e)) try: # Update Southerners league update_southerners_stats_for_season(season) print('Updated Southerners league for the current season') except Exception as e: errors.append("Failed to update Southerners League: {}".format(e)) try: # Update opposition stats update_all_club_stats() print('Updated all opposition club stats') except Exception as e: errors.append( "Failed to update Opposition Club Stats: {}".format(e)) try: # Update ClubTeamSeasonParticipation stats update_participation_stats_for_season(season) print( 'Updated Club Team Season Participation stats for the current season' ) except Exception as e: errors.append( "Failed to update Club Team Season Participation Stats: {}". format(e)) try: # Delete all training session entries from before yesterday # (we don't care about training sessions in the past) yesterday = timezone.now() - timedelta(days=1) TrainingSession.objects.before(yesterday).delete() print("Purged all training sessions from before yesterday") except Exception as e: errors.append("Failed to purge training sessions: {}".format(e)) # Scrape league tables query = Q(division_tables_url__isnull=True) | Q(division_tables_url='') participations = ClubTeamSeasonParticipation.objects.current().exclude( query).select_related('team', 'division') for participation in participations: try: league_scraper.get_east_leagues_division( participation.division_tables_url, participation.division, season) print('Scraped league table for ' + participation.division_tables_url) except Exception as e: errors.append( "Failed to scrape league table from {}: {}".format( participation.division_tables_url, e)) for error in errors: print(error)
def current(self): """ Returns only current squad membership, if any.""" return self.filter(season=Season.current())
def current(self): """ Returns just the participations for the current season""" return self.filter(season=Season.current())