From b110eaad87d984d4243d3104ddd756c60dddd9cb Mon Sep 17 00:00:00 2001 From: Ivlev Denis Date: Thu, 19 Jul 2018 15:38:04 +0300 Subject: [PATCH 1/4] LIL-596. Fix non paid schedule template (cherry picked from commit 6760feb) --- apps/school/templates/blocks/schedule.html | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/apps/school/templates/blocks/schedule.html b/apps/school/templates/blocks/schedule.html index 2e4c6457..89ce9222 100644 --- a/apps/school/templates/blocks/schedule.html +++ b/apps/school/templates/blocks/schedule.html @@ -8,21 +8,25 @@ {% for school_schedule in school_schedules %} {% with current_live_lesson=school_schedule.current_live_lesson %}
-
+
{{ school_schedule }}
+ {% comment %} {% if current_live_lesson %} - +
{{ current_live_lesson.date }}
{% endif %} + {% endcomment %}
{{ school_schedule.start_at }} (МСК)
- + {% comment %} + {% include './pay_btn.html' %} + {% endcomment %}
-
+
{% thumbnail current_live_lesson.cover.image "70x70" crop="center" as im %} @@ -31,7 +35,7 @@ {% endthumbnail %}
-
+
{{ school_schedule.title }} {% if current_live_lesson and current_live_lesson.title %} , {{ current_live_lesson.title }} From 90f5eebcb7f19cca69694726668dc842d2a89a32 Mon Sep 17 00:00:00 2001 From: gzbender Date: Sat, 21 Jul 2018 01:36:05 +0500 Subject: [PATCH 2/4] =?UTF-8?q?LIL-597=20=D0=9F=D0=BE=D0=BA=D0=B0=D0=B7?= =?UTF-8?q?=D1=8B=D0=B2=D0=B0=D1=82=D1=8C=20=D0=B7=D0=B0=D0=BF=D0=B8=D1=81?= =?UTF-8?q?=D0=B8=20=D1=83=D1=80=D0=BE=D0=BA=D0=BE=D0=B2=20=D0=B7=D0=B0=20?= =?UTF-8?q?=D0=B2=D1=81=D1=91=20=D0=B2=D1=80=D0=B5=D0=BC=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/school/views.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/school/views.py b/apps/school/views.py index 7f4ab734..90602ec0 100644 --- a/apps/school/views.py +++ b/apps/school/views.py @@ -223,8 +223,7 @@ class SummerSchoolView(TemplateView): school_schedules_purchased = [] if school_payment_exists and is_previous: live_lessons = LiveLesson.objects.filter( - date__gte=school_payment.last().date_start, - date__range=[(now_time - timedelta(days=8)).date(), (now_time - timedelta(days=1)).date()], + date__lt=(now_time - timedelta(days=1)).date(), deactivated_at__isnull=True, ) live_lessons_exists = live_lessons.exists() From 404c48c9b3d4bd221906e1b63e8ac680b90cd892 Mon Sep 17 00:00:00 2001 From: cfwme Date: Tue, 24 Jul 2018 07:42:34 +0000 Subject: [PATCH 3/4] Revert "Merge branch 'hotfix/lil-597' into 'master'" This reverts merge request !73 --- apps/school/views.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/school/views.py b/apps/school/views.py index 90602ec0..7f4ab734 100644 --- a/apps/school/views.py +++ b/apps/school/views.py @@ -223,7 +223,8 @@ class SummerSchoolView(TemplateView): school_schedules_purchased = [] if school_payment_exists and is_previous: live_lessons = LiveLesson.objects.filter( - date__lt=(now_time - timedelta(days=1)).date(), + date__gte=school_payment.last().date_start, + date__range=[(now_time - timedelta(days=8)).date(), (now_time - timedelta(days=1)).date()], deactivated_at__isnull=True, ) live_lessons_exists = live_lessons.exists() From 55bb4bb70cef8a5dad963f667577a56ac7bd4bd7 Mon Sep 17 00:00:00 2001 From: gzbender Date: Tue, 24 Jul 2018 18:26:01 +0500 Subject: [PATCH 4/4] =?UTF-8?q?LIL-597=20=D0=9F=D0=BE=D0=BA=D0=B0=D0=B7?= =?UTF-8?q?=D1=8B=D0=B2=D0=B0=D1=82=D1=8C=20=D0=B7=D0=B0=D0=BF=D0=B8=D1=81?= =?UTF-8?q?=D0=B8=20=D1=83=D1=80=D0=BE=D0=BA=D0=BE=D0=B2=20=D0=B7=D0=B0=20?= =?UTF-8?q?=D0=B2=D1=81=D1=91=20=D0=B2=D1=80=D0=B5=D0=BC=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../templates/summer/schedule_purchased.html | 20 ++++++----- apps/school/views.py | 33 +++++++++++++++---- 2 files changed, 38 insertions(+), 15 deletions(-) diff --git a/apps/school/templates/summer/schedule_purchased.html b/apps/school/templates/summer/schedule_purchased.html index 63e963fd..4de81091 100644 --- a/apps/school/templates/summer/schedule_purchased.html +++ b/apps/school/templates/summer/schedule_purchased.html @@ -38,15 +38,17 @@ {% if is_previous and not live_lessons_exists %} Записей уроков пока нет {% else %} - {% for school_schedule in school_schedules %} - {% if is_previous %} - {% if school_schedule.previous_live_lesson in live_lessons %} - {% include './_schedule_purchased_item.html' with school_schedule=school_schedule live_lesson=school_schedule.previous_live_lesson %} - {% endif %} - {% else %} - {% include './_schedule_purchased_item.html' with school_schedule=school_schedule live_lesson=school_schedule.current_live_lesson %} - {% endif %} - {% endfor %} + {% if is_previous %} + {% for live_lesson in live_lessons %} + {% if live_lesson.school_schedule %} + {% include './_schedule_purchased_item.html' with school_schedule=live_lesson.school_schedule live_lesson=live_lesson %} + {% endif %} + {% endfor %} + {% else %} + {% for school_schedule in school_schedules %} + {% include './_schedule_purchased_item.html' with school_schedule=school_schedule live_lesson=school_schedule.current_live_lesson %} + {% endfor %} + {% endif %} {% endif %}
diff --git a/apps/school/views.py b/apps/school/views.py index 7f4ab734..3c1b478a 100644 --- a/apps/school/views.py +++ b/apps/school/views.py @@ -4,7 +4,7 @@ from paymentwall import Pingback from django.contrib.auth import get_user_model from django.contrib.auth.decorators import login_required, user_passes_test 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.shortcuts import get_object_or_404 from django.utils.decorators import method_decorator @@ -174,6 +174,8 @@ class SummerSchoolView(TemplateView): context = super().get_context_data() 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) now_time = now() try: 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 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: + 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( user=self.request.user, status__in=[ @@ -221,12 +240,14 @@ class SummerSchoolView(TemplateView): school_payment_exists_future = False school_purchased_future = False school_schedules_purchased = [] - if school_payment_exists and is_previous: + if all_schedules_purchased and is_previous: live_lessons = LiveLesson.objects.filter( - date__gte=school_payment.last().date_start, - date__range=[(now_time - timedelta(days=8)).date(), (now_time - timedelta(days=1)).date()], + date__range=[month_start, yesterday], 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() else: live_lessons = None @@ -240,7 +261,7 @@ class SummerSchoolView(TemplateView): 'is_purchased': school_payment_exists, 'is_purchased_future': school_payment_exists_future, '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_purchased_future': school_purchased_future, 'subscription_ends': school_payment.filter(add_days=False).first().date_end if school_payment_exists else None,