def get(self, request): now = datetime.now() nowWeekday = Weekday.to_django_weekday(now.weekday()) activities = Activity.objects.exclude(publication_date__gt=now).\ exclude(end_date__lt=now).exclude(publication_date__isnull=True).\ filter(is_frontpage=True).order_by('-publication_date') articles = Article.objects.exclude(publication_date__gt=now).\ exclude(publication_date__isnull=True).filter(is_frontpage=True).\ order_by('-publication_date') sessions = Session.objects.filter(sport__is_open=True).\ filter(Q(weekday=nowWeekday) | Q(weekday=(nowWeekday+1)%7) | Q(weekday=(nowWeekday+2)%7) ).\ order_by('weekday').order_by('start_time') informations = Information.objects.filter(is_important=True, is_published=True).\ filter(Q(start_date__lt=now) | Q(start_date__isnull=True)).\ filter(Q(end_date__gt=now) | Q(end_date__isnull=True)).\ order_by('-end_date') is_past = False match = Match.objects.filter(date__gt=now).order_by('date').first() if not match: match = Match.objects.filter(date__lt=now).order_by('-date').first() is_past = True days = [now,now+timedelta(1),now+timedelta(2)] weekdays = [Weekday.to_django_weekday(day.weekday()) for day in days] content = {'activities': activities, 'articles': articles, 'num_frontpage': range(activities.count() + articles.count()), 'days_sessionsPerDay': zip(days, [sessions.filter(weekday=weekday) for weekday in weekdays]), 'match': {'is_past': is_past, 'object': match}, 'informations': informations} return render(request, self.template_name, content)
def clean(self): if self.cancelled_session.weekday is not None and\ Weekday.to_django_weekday(self.cancellation_date.weekday())\ != self.cancelled_session.weekday: raise ValidationError(_('Weekdays are not matching.')) if self.cancelled_session.weekday is None and\ self.cancellation_date != self.cancelled_session.date: raise ValidationError(_('Dates are not matching.'))