- {% if is_previous and not live_lessons_exists %}
- Записей уроков пока нет
- {% else %}
- {% if is_previous %}
- {% for live_lesson in live_lessons %}
- {% if live_lesson.school_schedule and live_lesson.title %}
- {% include 'blocks/schedule_item.html' with school_schedule=live_lesson.school_schedule live_lesson=live_lesson %}
- {% endif %}
- {% endfor %}
- {% else %}
- {% for school_schedule in school_schedules_sorted %}
- {% include 'blocks/schedule_item.html' with school_schedule=school_schedule live_lesson=school_schedule.current_live_lesson %}
- {% endfor %}
- {% endif %}
+ {% for school_schedule in school_schedules_sorted %}
+ {% include 'blocks/schedule_item.html' with school_schedule=school_schedule live_lesson=school_schedule.current_live_lesson %}
+ {% endfor %}
+ {% if prev_live_lessons_exists %}
+
+ {% for live_lesson in prev_live_lessons %}
+ {% if live_lesson.school_schedule and live_lesson.title %}
+ {% include 'blocks/schedule_item.html' with school_schedule=live_lesson.school_schedule live_lesson=live_lesson %}
+ {% endif %}
+ {% endfor %}
{% endif %}
diff --git a/apps/school/views.py b/apps/school/views.py
index a3cc379b..71029683 100644
--- a/apps/school/views.py
+++ b/apps/school/views.py
@@ -110,9 +110,7 @@ class SchoolView(TemplateView):
def get_context_data(self):
context = super().get_context_data()
- is_previous = 'is_previous' in self.request.GET
date_now = now().date()
- yesterday = date_now - timedelta(days=1)
now_time = now()
try:
school_schedule = SchoolSchedule.objects.get(weekday=now_time.isoweekday())
@@ -132,8 +130,8 @@ class SchoolView(TemplateView):
key=lambda ss: ss.current_live_lesson and ss.current_live_lesson.date)
except Exception:
school_schedules_sorted = school_schedules
- live_lessons = []
- live_lessons_exists = False
+ prev_live_lessons = []
+ prev_live_lessons_exists = False
subscription_ends = None
school_payment_exists = False
school_schedules_purchased = []
@@ -178,31 +176,29 @@ class SchoolView(TemplateView):
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 = []
+ # берем все подписки, которые были в периоде
+ for sp in prev_school_payments:
+ # берем все уроки в оплаченном промежутке
+ date_range = [max(sp.date_start, prev_range[0]), min(sp.date_end, prev_range[1])]
+ prev_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)
+ prev_live_lessons = LiveLesson.objects.filter(id__in=set(prev_live_lessons)).order_by('-date')
+ prev_live_lessons_exists = prev_live_lessons.exists()
+ if prev_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 prev_live_lessons:
+ ll.school_schedule = school_schedules_dict.get(ll.date.isoweekday())
+ else:
+ prev_live_lessons = []
context.update({
'online': online,
- 'live_lessons': live_lessons,
- 'live_lessons_exists': live_lessons_exists,
- 'is_previous': is_previous,
+ 'prev_live_lessons': prev_live_lessons,
+ 'prev_live_lessons_exists': prev_live_lessons_exists,
'course_items': Course.objects.filter(status=Course.PUBLISHED)[:6],
'is_purchased': school_payment_exists,
'is_purchased_future': False,