remotes/origin/editis_13-01-19
gzbender 7 years ago
parent 30766116da
commit a4fe58f74a
  1. 40
      apps/school/templates/summer/schedule_purchased.html
  2. 48
      apps/school/views.py

@ -20,38 +20,18 @@
</div>
</div>
<div class="casing__col">
{% if not profile %}
<div class="casing__head">
{% if is_previous %}
<div class="casing__title title">Запись уроков</div>
{% else %}
<div class="casing__title title">Новые уроки</div>
{% endif %}
<label class="casing__switcher switcher">
<span class="switcher__wrap">
<a href="{% url 'school:school' %}?is_previous=true" class="switcher__item{% if is_previous %} active{% endif %}">запись уроков</a>
<a href="{% url 'school:school' %}" class="switcher__item{% if not is_previous %} active{% endif %}">новые уроки</a>
</span>
</label>
</div>
{% endif %}
<div class="casing__timing timing js-timing">
<div class="timing__week">
{% 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 %}
<hr>
{% 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 %}
</div>
<div class="timing__week">

@ -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,

Loading…
Cancel
Save