You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
99 lines
3.8 KiB
99 lines
3.8 KiB
from datetime import datetime, timedelta
|
|
|
|
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
|
|
from apps.payment.models import SchoolPayment
|
|
|
|
User = get_user_model()
|
|
|
|
|
|
class AboutView(TemplateView):
|
|
template_name = 'templates/lilcity/about.html'
|
|
|
|
|
|
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
|
|
online_coming_soon = False
|
|
school_schedule = None
|
|
else:
|
|
end_at = datetime.combine(now_time.today(), school_schedule.start_at)
|
|
online = (
|
|
school_schedule.start_at <= now_time.time() and
|
|
(end_at + timedelta(hours=2)).time() >= now_time.time() and
|
|
school_schedule.current_live_lesson()
|
|
)
|
|
online_coming_soon = (
|
|
school_schedule.start_at > now_time.time() and
|
|
(
|
|
datetime.combine(datetime.today(), school_schedule.start_at) - timedelta(hours=12)
|
|
).time() <= now_time.time() and
|
|
school_schedule.current_live_lesson()
|
|
)
|
|
|
|
date_now = now_time.date()
|
|
if self.request.user.is_authenticated:
|
|
school_payment = SchoolPayment.objects.filter(
|
|
user=self.request.user,
|
|
date_start__lte=date_now,
|
|
date_end__gte=date_now
|
|
)
|
|
school_payment_exists = school_payment.exists()
|
|
school_schedules_purchased = school_payment.values_list('weekdays', flat=True)
|
|
school_schedules_purchased = school_schedules_purchased[0] if school_schedules_purchased else []
|
|
|
|
school_payment_future = SchoolPayment.objects.filter(
|
|
user=self.request.user,
|
|
date_start__gte=date_now,
|
|
date_end__gte=date_now
|
|
)
|
|
|
|
school_payment_exists_future = school_payment_future.exists()
|
|
school_purchased_future = school_payment_future.last()
|
|
|
|
else:
|
|
school_payment_exists = False
|
|
school_payment_exists_future = False
|
|
school_purchased_future = False
|
|
school_schedules_purchased = []
|
|
|
|
context.update({
|
|
'online': online,
|
|
'online_coming_soon': online_coming_soon,
|
|
'school_schedule': school_schedule,
|
|
'course_items': Course.objects.filter(status=Course.PUBLISHED)[:6],
|
|
'is_purchased': school_payment_exists,
|
|
'min_school_price': SchoolSchedule.objects.aggregate(Min('month_price'))['month_price__min'],
|
|
'school_schedules': SchoolSchedule.objects.all(),
|
|
'school_schedules_purchased': school_schedules_purchased,
|
|
'teachers': User.objects.filter(role=User.TEACHER_ROLE, show_in_mainpage=True),
|
|
'subscription_ends': school_payment.filter(add_days=False).first().date_end if school_payment_exists else None,
|
|
'subscription_ends_humanize': school_payment.filter(add_days=False).first().date_end_humanize if school_payment_exists else None,
|
|
|
|
'school_purchased_future': school_purchased_future,
|
|
'is_purchased_future': school_payment_exists_future,
|
|
|
|
})
|
|
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
|
|
|