|
|
|
@ -4,7 +4,7 @@ from paymentwall import Pingback |
|
|
|
from django.contrib.auth import get_user_model |
|
|
|
from django.contrib.auth import get_user_model |
|
|
|
from django.contrib.auth.decorators import login_required, user_passes_test |
|
|
|
from django.contrib.auth.decorators import login_required, user_passes_test |
|
|
|
from django.db.utils import IntegrityError |
|
|
|
from django.db.utils import IntegrityError |
|
|
|
from django.db.models import Min, F, Func, Q |
|
|
|
from django.db.models import Min, F, Func, Q, Value |
|
|
|
from django.http import Http404 |
|
|
|
from django.http import Http404 |
|
|
|
from django.shortcuts import get_object_or_404 |
|
|
|
from django.shortcuts import get_object_or_404 |
|
|
|
from django.utils.decorators import method_decorator |
|
|
|
from django.utils.decorators import method_decorator |
|
|
|
@ -174,6 +174,8 @@ class SummerSchoolView(TemplateView): |
|
|
|
context = super().get_context_data() |
|
|
|
context = super().get_context_data() |
|
|
|
is_previous = 'is_previous' in self.request.GET |
|
|
|
is_previous = 'is_previous' in self.request.GET |
|
|
|
date_now = now().date() |
|
|
|
date_now = now().date() |
|
|
|
|
|
|
|
yesterday = date_now - timedelta(days=1) |
|
|
|
|
|
|
|
month_start = date_now.replace(day=1) |
|
|
|
now_time = now() |
|
|
|
now_time = now() |
|
|
|
try: |
|
|
|
try: |
|
|
|
school_schedule = SchoolSchedule.objects.get(weekday=now_time.isoweekday()) |
|
|
|
school_schedule = SchoolSchedule.objects.get(weekday=now_time.isoweekday()) |
|
|
|
@ -186,7 +188,24 @@ class SummerSchoolView(TemplateView): |
|
|
|
(end_at + timedelta(hours=1)).time() >= now_time.time() and |
|
|
|
(end_at + timedelta(hours=1)).time() >= now_time.time() and |
|
|
|
school_schedule.current_live_lesson() |
|
|
|
school_schedule.current_live_lesson() |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
school_schedules = SchoolSchedule.objects.all() |
|
|
|
|
|
|
|
school_schedules_dict = {ss.weekday: ss for ss in school_schedules} |
|
|
|
|
|
|
|
school_schedules_dict[0] = school_schedules_dict.get(7) |
|
|
|
if self.request.user.is_authenticated: |
|
|
|
if self.request.user.is_authenticated: |
|
|
|
|
|
|
|
all_schedules_purchased = SchoolPayment.objects.filter( |
|
|
|
|
|
|
|
user=self.request.user, |
|
|
|
|
|
|
|
status__in=[ |
|
|
|
|
|
|
|
Pingback.PINGBACK_TYPE_REGULAR, |
|
|
|
|
|
|
|
Pingback.PINGBACK_TYPE_GOODWILL, |
|
|
|
|
|
|
|
Pingback.PINGBACK_TYPE_RISK_REVIEWED_ACCEPTED, |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
date_start__range=[month_start, date_now], |
|
|
|
|
|
|
|
).annotate( |
|
|
|
|
|
|
|
joined_weekdays=Func(F('weekdays'), function='unnest',) |
|
|
|
|
|
|
|
).distinct().values_list('joined_weekdays', flat=True) |
|
|
|
|
|
|
|
all_schedules_purchased = map(lambda x: 1 if x == 7 else x+1, all_schedules_purchased) |
|
|
|
|
|
|
|
|
|
|
|
school_payment = SchoolPayment.objects.filter( |
|
|
|
school_payment = SchoolPayment.objects.filter( |
|
|
|
user=self.request.user, |
|
|
|
user=self.request.user, |
|
|
|
status__in=[ |
|
|
|
status__in=[ |
|
|
|
@ -221,12 +240,14 @@ class SummerSchoolView(TemplateView): |
|
|
|
school_payment_exists_future = False |
|
|
|
school_payment_exists_future = False |
|
|
|
school_purchased_future = False |
|
|
|
school_purchased_future = False |
|
|
|
school_schedules_purchased = [] |
|
|
|
school_schedules_purchased = [] |
|
|
|
if school_payment_exists and is_previous: |
|
|
|
if all_schedules_purchased and is_previous: |
|
|
|
live_lessons = LiveLesson.objects.filter( |
|
|
|
live_lessons = LiveLesson.objects.filter( |
|
|
|
date__gte=school_payment.last().date_start, |
|
|
|
date__range=[month_start, yesterday], |
|
|
|
date__range=[(now_time - timedelta(days=8)).date(), (now_time - timedelta(days=1)).date()], |
|
|
|
|
|
|
|
deactivated_at__isnull=True, |
|
|
|
deactivated_at__isnull=True, |
|
|
|
) |
|
|
|
date__week_day__in=all_schedules_purchased, |
|
|
|
|
|
|
|
).order_by('-date') |
|
|
|
|
|
|
|
for ll in live_lessons: |
|
|
|
|
|
|
|
ll.school_schedule = school_schedules_dict.get(ll.date.isoweekday()) |
|
|
|
live_lessons_exists = live_lessons.exists() |
|
|
|
live_lessons_exists = live_lessons.exists() |
|
|
|
else: |
|
|
|
else: |
|
|
|
live_lessons = None |
|
|
|
live_lessons = None |
|
|
|
@ -240,7 +261,7 @@ class SummerSchoolView(TemplateView): |
|
|
|
'is_purchased': school_payment_exists, |
|
|
|
'is_purchased': school_payment_exists, |
|
|
|
'is_purchased_future': school_payment_exists_future, |
|
|
|
'is_purchased_future': school_payment_exists_future, |
|
|
|
'min_school_price': SchoolSchedule.objects.aggregate(Min('month_price'))['month_price__min'], |
|
|
|
'min_school_price': SchoolSchedule.objects.aggregate(Min('month_price'))['month_price__min'], |
|
|
|
'school_schedules': SchoolSchedule.objects.all(), |
|
|
|
'school_schedules': school_schedules, |
|
|
|
'school_schedules_purchased': school_schedules_purchased, |
|
|
|
'school_schedules_purchased': school_schedules_purchased, |
|
|
|
'school_purchased_future': school_purchased_future, |
|
|
|
'school_purchased_future': school_purchased_future, |
|
|
|
'subscription_ends': school_payment.filter(add_days=False).first().date_end if school_payment_exists else None, |
|
|
|
'subscription_ends': school_payment.filter(add_days=False).first().date_end if school_payment_exists else None, |
|
|
|
|