From a76fa6dfa5af3b2a83e87dd270cdeefa59f6a8d6 Mon Sep 17 00:00:00 2001 From: Ivlev Denis Date: Mon, 30 Apr 2018 14:29:56 +0300 Subject: [PATCH] Add check previous live lessons exists --- apps/school/templates/blocks/schedule_purchased.html | 4 ++++ apps/school/views.py | 11 ++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/apps/school/templates/blocks/schedule_purchased.html b/apps/school/templates/blocks/schedule_purchased.html index e0fa5f45..e1da8dcb 100644 --- a/apps/school/templates/blocks/schedule_purchased.html +++ b/apps/school/templates/blocks/schedule_purchased.html @@ -33,6 +33,9 @@
+ {% if is_previous and not live_lessons_exists %} + Записей уроков пока нет + {% else %} {% for school_schedule in school_schedules %} {% if is_previous %} {% include './_schedule_purchased_item.html' with school_schedule=school_schedule live_lesson=school_schedule.previous_live_lesson %} @@ -40,6 +43,7 @@ {% include './_schedule_purchased_item.html' with school_schedule=school_schedule live_lesson=school_schedule.current_live_lesson %} {% endif %} {% endfor %} + {% endif %}
{% comment %} previous week schedules {% endcomment %} diff --git a/apps/school/views.py b/apps/school/views.py index 267c7f67..10886f6f 100644 --- a/apps/school/views.py +++ b/apps/school/views.py @@ -1,4 +1,4 @@ -from datetime import datetime +from datetime import datetime, timedelta from django.contrib.auth import get_user_model from django.contrib.auth.decorators import login_required, user_passes_test @@ -104,8 +104,17 @@ class SchoolView(TemplateView): else: school_payment_exists = False school_schedules_purchased = [] + if school_payment_exists and is_previous: + live_lessons_exists = LiveLesson.objects.filter( + 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, + ).exists() + else: + live_lessons_exists = False context.update({ 'online': online, + 'live_lessons_exists': live_lessons_exists, 'is_previous': is_previous, 'course_items': Course.objects.filter(status=Course.PUBLISHED)[:6], 'is_purchased': school_payment_exists,