from django.db.models import Min from django.contrib.auth import get_user_model from django.views.generic import TemplateView from django.utils.timezone import now from apps.course.models import Course from apps.school.models import SchoolSchedule User = get_user_model() class IndexView(TemplateView): template_name = 'templates/lilcity/main.html' def get_context_data(self): context = super().get_context_data() now_time = now() try: school_schedule = SchoolSchedule.objects.get(weekday=now_time.isoweekday()) except SchoolSchedule.DoesNotExist: online = False else: online = school_schedule.start_at <= now().time() and school_schedule.current_live_lesson() context.update({ 'online': online, 'course_items': Course.objects.filter(status=Course.PUBLISHED)[:6], 'school_schedules': SchoolSchedule.objects.all(), 'min_school_price': SchoolSchedule.objects.all().aggregate(Min('month_price'))['month_price__min'], 'authors': User.objects.filter(role=User.AUTHOR_ROLE, show_in_mainpage=True), }) return context class SchoolSchedulesView(TemplateView): template_name = 'templates/lilcity/school_schedules.html' def get_context_data(self): context = super().get_context_data() context['school_schedules'] = SchoolSchedule.objects.all() return context