|
|
|
|
@ -111,8 +111,6 @@ class SchoolView(TemplateView): |
|
|
|
|
is_previous = 'is_previous' in self.request.GET |
|
|
|
|
date_now = now().date() |
|
|
|
|
yesterday = date_now - timedelta(days=1) |
|
|
|
|
# month_start = date_now.replace(day=1) |
|
|
|
|
month_start = datetime(2018, 7, 1).date() |
|
|
|
|
now_time = now() |
|
|
|
|
try: |
|
|
|
|
school_schedule = SchoolSchedule.objects.get(weekday=now_time.isoweekday()) |
|
|
|
|
@ -128,14 +126,18 @@ class SchoolView(TemplateView): |
|
|
|
|
|
|
|
|
|
school_schedules = SchoolSchedule.objects.all() |
|
|
|
|
try: |
|
|
|
|
school_schedules_sorted = sorted(school_schedules, key=lambda ss: ss.current_live_lesson and ss.current_live_lesson.date) |
|
|
|
|
school_schedules_sorted = sorted(school_schedules, |
|
|
|
|
key=lambda ss: ss.current_live_lesson and ss.current_live_lesson.date) |
|
|
|
|
except Exception: |
|
|
|
|
pass |
|
|
|
|
school_schedules_dict = {ss.weekday: ss for ss in school_schedules} |
|
|
|
|
school_schedules_dict[0] = school_schedules_dict.get(7) |
|
|
|
|
live_lessons = None |
|
|
|
|
live_lessons = [] |
|
|
|
|
live_lessons_exists = False |
|
|
|
|
subscription_ends = None |
|
|
|
|
school_payment_exists = False |
|
|
|
|
school_schedules_purchased = [] |
|
|
|
|
school_purchased_future = False |
|
|
|
|
prev_school_payments = None |
|
|
|
|
prev_range = [date_now - timedelta(days=8), date_now] |
|
|
|
|
if self.request.user.is_authenticated: |
|
|
|
|
school_payment = SchoolPayment.objects.filter( |
|
|
|
|
user=self.request.user, |
|
|
|
|
@ -161,15 +163,8 @@ class SchoolView(TemplateView): |
|
|
|
|
school_schedules_purchased = school_payment.annotate( |
|
|
|
|
joined_weekdays=Func(F('weekdays'), function='unnest',) |
|
|
|
|
).values_list('joined_weekdays', flat=True).distinct() |
|
|
|
|
else: |
|
|
|
|
school_payment_exists = False |
|
|
|
|
school_schedules_purchased = [] |
|
|
|
|
school_purchased_future = False |
|
|
|
|
if is_previous: |
|
|
|
|
prev_range = [yesterday - timedelta(days=7), date_now] |
|
|
|
|
live_lessons = [] |
|
|
|
|
# берем все подписки, которые были в периоде |
|
|
|
|
for sp in SchoolPayment.objects.filter( |
|
|
|
|
|
|
|
|
|
prev_school_payments = SchoolPayment.objects.filter( |
|
|
|
|
date_start__lt=prev_range[1], |
|
|
|
|
date_end__gte=prev_range[0], |
|
|
|
|
user=self.request.user, |
|
|
|
|
@ -178,21 +173,28 @@ class SchoolView(TemplateView): |
|
|
|
|
Pingback.PINGBACK_TYPE_GOODWILL, |
|
|
|
|
Pingback.PINGBACK_TYPE_RISK_REVIEWED_ACCEPTED, |
|
|
|
|
], |
|
|
|
|
): |
|
|
|
|
# берем все уроки в оплаченном промежутке |
|
|
|
|
date_range = [max(sp.date_start, prev_range[0]), min(sp.date_end, prev_range[1])] |
|
|
|
|
live_lessons += LiveLesson.objects.filter( |
|
|
|
|
date__range=date_range, |
|
|
|
|
deactivated_at__isnull=True, |
|
|
|
|
date__week_day__in=list(map(lambda x: 1 if x == 7 else x+1, sp.weekdays)), |
|
|
|
|
).values_list('id', flat=True) |
|
|
|
|
live_lessons = LiveLesson.objects.filter(id__in=set(live_lessons)).order_by('-date') |
|
|
|
|
live_lessons_exists = live_lessons.exists() |
|
|
|
|
if live_lessons_exists: |
|
|
|
|
for ll in live_lessons: |
|
|
|
|
ll.school_schedule = school_schedules_dict.get(ll.date.isoweekday()) |
|
|
|
|
else: |
|
|
|
|
live_lessons = None |
|
|
|
|
weekdays__len__gt=0, |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
if is_previous: |
|
|
|
|
# берем все подписки, которые были в периоде |
|
|
|
|
for sp in prev_school_payments: |
|
|
|
|
# берем все уроки в оплаченном промежутке |
|
|
|
|
date_range = [max(sp.date_start, prev_range[0]), min(sp.date_end, prev_range[1])] |
|
|
|
|
live_lessons += LiveLesson.objects.filter( |
|
|
|
|
date__range=date_range, |
|
|
|
|
deactivated_at__isnull=True, |
|
|
|
|
date__week_day__in=list(map(lambda x: 1 if x == 7 else x+1, sp.weekdays)), |
|
|
|
|
).values_list('id', flat=True) |
|
|
|
|
live_lessons = LiveLesson.objects.filter(id__in=set(live_lessons)).order_by('-date') |
|
|
|
|
live_lessons_exists = live_lessons.exists() |
|
|
|
|
if live_lessons_exists: |
|
|
|
|
school_schedules_dict = {ss.weekday: ss for ss in school_schedules} |
|
|
|
|
school_schedules_dict[0] = school_schedules_dict.get(7) |
|
|
|
|
for ll in live_lessons: |
|
|
|
|
ll.school_schedule = school_schedules_dict.get(ll.date.isoweekday()) |
|
|
|
|
else: |
|
|
|
|
live_lessons = [] |
|
|
|
|
|
|
|
|
|
context.update({ |
|
|
|
|
'online': online, |
|
|
|
|
@ -207,6 +209,7 @@ class SchoolView(TemplateView): |
|
|
|
|
'school_schedules': school_schedules, |
|
|
|
|
'school_schedules_purchased': school_schedules_purchased, |
|
|
|
|
'school_purchased_future': school_purchased_future, |
|
|
|
|
'prev_school_payments_exists': prev_school_payments and prev_school_payments.exists(), |
|
|
|
|
'subscription_ends': subscription_ends, |
|
|
|
|
'prolong_date_start': subscription_ends + timedelta(days=1) if subscription_ends else None, |
|
|
|
|
'allow_prolong': subscription_ends - date_now <= timedelta(days=7) |
|
|
|
|
|