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> </div>
<div class="casing__col"> <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="casing__timing timing js-timing">
<div class="timing__week"> <div class="timing__week">
{% if is_previous and not live_lessons_exists %} {% for school_schedule in school_schedules_sorted %}
Записей уроков пока нет {% include 'blocks/schedule_item.html' with school_schedule=school_schedule live_lesson=school_schedule.current_live_lesson %}
{% else %} {% endfor %}
{% if is_previous %} {% if prev_live_lessons_exists %}
{% for live_lesson in live_lessons %} <hr>
{% if live_lesson.school_schedule and live_lesson.title %} {% for live_lesson in prev_live_lessons %}
{% include 'blocks/schedule_item.html' with school_schedule=live_lesson.school_schedule live_lesson=live_lesson %} {% if live_lesson.school_schedule and live_lesson.title %}
{% endif %} {% include 'blocks/schedule_item.html' with school_schedule=live_lesson.school_schedule live_lesson=live_lesson %}
{% endfor %} {% endif %}
{% else %} {% endfor %}
{% 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 %}
{% endif %} {% endif %}
</div> </div>
<div class="timing__week"> <div class="timing__week">

@ -110,9 +110,7 @@ class SchoolView(TemplateView):
def get_context_data(self): def get_context_data(self):
context = super().get_context_data() context = super().get_context_data()
is_previous = 'is_previous' in self.request.GET
date_now = now().date() date_now = now().date()
yesterday = date_now - timedelta(days=1)
now_time = now() now_time = now()
try: try:
school_schedule = SchoolSchedule.objects.get(weekday=now_time.isoweekday()) 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) key=lambda ss: ss.current_live_lesson and ss.current_live_lesson.date)
except Exception: except Exception:
school_schedules_sorted = school_schedules school_schedules_sorted = school_schedules
live_lessons = [] prev_live_lessons = []
live_lessons_exists = False prev_live_lessons_exists = False
subscription_ends = None subscription_ends = None
school_payment_exists = False school_payment_exists = False
school_schedules_purchased = [] school_schedules_purchased = []
@ -178,31 +176,29 @@ class SchoolView(TemplateView):
weekdays__len__gt=0, weekdays__len__gt=0,
) )
if is_previous: # берем все подписки, которые были в периоде
# берем все подписки, которые были в периоде for sp in prev_school_payments:
for sp in prev_school_payments: # берем все уроки в оплаченном промежутке
# берем все уроки в оплаченном промежутке date_range = [max(sp.date_start, prev_range[0]), min(sp.date_end, prev_range[1])]
date_range = [max(sp.date_start, prev_range[0]), min(sp.date_end, prev_range[1])] prev_live_lessons = LiveLesson.objects.filter(
live_lessons += LiveLesson.objects.filter( date__range=date_range,
date__range=date_range, deactivated_at__isnull=True,
deactivated_at__isnull=True, date__week_day__in=list(map(lambda x: 1 if x == 7 else x+1, sp.weekdays)),
date__week_day__in=list(map(lambda x: 1 if x == 7 else x+1, sp.weekdays)), ).values_list('id', flat=True)
).values_list('id', flat=True) prev_live_lessons = LiveLesson.objects.filter(id__in=set(prev_live_lessons)).order_by('-date')
live_lessons = LiveLesson.objects.filter(id__in=set(live_lessons)).order_by('-date') prev_live_lessons_exists = prev_live_lessons.exists()
live_lessons_exists = live_lessons.exists() if prev_live_lessons_exists:
if live_lessons_exists: 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) for ll in prev_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()) else:
else: prev_live_lessons = []
live_lessons = []
context.update({ context.update({
'online': online, 'online': online,
'live_lessons': live_lessons, 'prev_live_lessons': prev_live_lessons,
'live_lessons_exists': live_lessons_exists, 'prev_live_lessons_exists': prev_live_lessons_exists,
'is_previous': is_previous,
'course_items': Course.objects.filter(status=Course.PUBLISHED)[:6], 'course_items': Course.objects.filter(status=Course.PUBLISHED)[:6],
'is_purchased': school_payment_exists, 'is_purchased': school_payment_exists,
'is_purchased_future': False, 'is_purchased_future': False,

Loading…
Cancel
Save