Merge branch 'hotfix/LIL-659' into 'master'

Hotfix/lil 659

See merge request lilcity/backend!143
remotes/origin/hotfix/LIL-661
cfwme 7 years ago
commit 8ee240f5c8
  1. 48
      apps/school/views.py

@ -140,21 +140,9 @@ class SchoolView(TemplateView):
pass pass
school_schedules_dict = {ss.weekday: ss for ss in school_schedules} school_schedules_dict = {ss.weekday: ss for ss in school_schedules}
school_schedules_dict[0] = school_schedules_dict.get(7) school_schedules_dict[0] = school_schedules_dict.get(7)
all_schedules_purchased = [] live_lessons = None
live_lessons_exists = False
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 = list(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=[
@ -173,18 +161,32 @@ class SchoolView(TemplateView):
else: else:
school_payment_exists = False school_payment_exists = False
school_schedules_purchased = [] school_schedules_purchased = []
if all_schedules_purchased and is_previous: if is_previous:
live_lessons = LiveLesson.objects.filter( prev_range = [yesterday - timedelta(days=7), yesterday]
date__range=[yesterday - timedelta(days=7), yesterday], live_lessons = []
deactivated_at__isnull=True, # берем все подписки, которые были в периоде
date__week_day__in=all_schedules_purchased, for sp in SchoolPayment.objects.filter(
).order_by('-date') date_start__lte=prev_range[1],
date_end__gte=prev_range[0],
user=self.request.user,
status__in=[
Pingback.PINGBACK_TYPE_REGULAR,
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')
for ll in live_lessons: for ll in live_lessons:
ll.school_schedule = school_schedules_dict.get(ll.date.isoweekday()) ll.school_schedule = school_schedules_dict.get(ll.date.isoweekday())
live_lessons_exists = live_lessons.exists() live_lessons_exists = live_lessons.exists()
else: live_lessons = live_lessons or None
live_lessons = None
live_lessons_exists = False
context.update({ context.update({
'online': online, 'online': online,
'live_lessons': live_lessons, 'live_lessons': live_lessons,

Loading…
Cancel
Save