{{ school_schedule }}
- {% if request.user_agent.is_mobile and school_schedule.trial_lesson %}
+ {% if not is_purchased and request.user_agent.is_mobile and school_schedule.trial_lesson %}
Пробный урок
{% endif %}
@@ -20,7 +20,7 @@
{% else %}
{% include './day_pay_btn.html' %}
{% endif %}
- {% if not request.user_agent.is_mobile and school_schedule.trial_lesson %}
+ {% if not is_purchased and not request.user_agent.is_mobile and school_schedule.trial_lesson %}
Пробный урок
{% endif %}
diff --git a/apps/school/views.py b/apps/school/views.py
index 3816c0eb..1728d443 100644
--- a/apps/school/views.py
+++ b/apps/school/views.py
@@ -140,21 +140,9 @@ class SchoolView(TemplateView):
pass
school_schedules_dict = {ss.weekday: ss for ss in school_schedules}
school_schedules_dict[0] = school_schedules_dict.get(7)
- all_schedules_purchased = []
+ live_lessons = None
+ live_lessons_exists = False
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 = list(map(lambda x: 1 if x == 7 else x+1, all_schedules_purchased))
-
school_payment = SchoolPayment.objects.filter(
user=self.request.user,
status__in=[
@@ -173,18 +161,32 @@ class SchoolView(TemplateView):
else:
school_payment_exists = False
school_schedules_purchased = []
- if all_schedules_purchased and is_previous:
- live_lessons = LiveLesson.objects.filter(
- date__range=[yesterday - timedelta(days=7), yesterday],
- deactivated_at__isnull=True,
- date__week_day__in=all_schedules_purchased,
- ).order_by('-date')
+ if is_previous:
+ prev_range = [yesterday - timedelta(days=7), yesterday]
+ live_lessons = []
+ # берем все подписки, которые были в периоде
+ for sp in SchoolPayment.objects.filter(
+ date_start__lte=prev_range[1],
+ date_end__gte=prev_range[0],
+ user=self.request.user,
+ status__in=[
+ Pingback.PINGBACK_TYPE_REGULAR,
+ Pingback.PINGBACK_TYPE_GOODWILL,
+ Pingback.PINGBACK_TYPE_RISK_REVIEWED_ACCEPTED,
+ ],
+ ):
+ # берем все уроки в оплаченном промежутке
+ 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')
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
- live_lessons_exists = False
+ live_lessons = live_lessons or None
context.update({
'online': online,
'live_lessons': live_lessons,
diff --git a/apps/user/templates/user/profile.html b/apps/user/templates/user/profile.html
index e8a81d33..9bddf2b0 100644
--- a/apps/user/templates/user/profile.html
+++ b/apps/user/templates/user/profile.html
@@ -64,10 +64,7 @@
-
-
+
{% if is_author %}
- {% if is_purchased_future %}
-
-
-
Ваша подписка начинается {{school_purchased_future.date_start}}
-
-
- {% else %}
- {% if is_purchased %}
- {% include "blocks/schedule_purchased.html" %}
- {% else %}
-
+ {% endif %}
{% if paid.exists %}
{% include "course/course_items.html" with course_items=paid %}
- {% else %}
+ {% endif %}
+ {% if not is_school_purchased and not paid.exists %}