diff --git a/apps/school/models.py b/apps/school/models.py index 0f5f6f60..4ca57fe2 100644 --- a/apps/school/models.py +++ b/apps/school/models.py @@ -46,19 +46,6 @@ class SchoolSchedule(models.Model): def is_online(self): return now().isoweekday() == self.weekday and now().time() >= self.start_at - def is_purchased(self): - date_now = now().date() - try: - school_payment = payment_models.SchoolPayment.objects.get( - weekdays__contains=[self.weekday], - date_start__lte=date_now, - date_end__gte=date_now, - ) - except payment_models.SchoolPayment.DoesNotExist: - return False - else: - return school_payment.is_deliverable() - def current_live_lesson(self): now_time = now() live_lesson = LiveLesson.objects.filter( diff --git a/apps/school/templates/blocks/_schedule_purchased_item.html b/apps/school/templates/blocks/_schedule_purchased_item.html index 84422eb2..62a3b274 100644 --- a/apps/school/templates/blocks/_schedule_purchased_item.html +++ b/apps/school/templates/blocks/_schedule_purchased_item.html @@ -1,5 +1,5 @@ {% load static %} {% load thumbnail %} -
+
@@ -11,12 +11,13 @@
{{ school_schedule.start_at }} (МСК)
- {% if school_schedule.is_purchased %} + {% if school_schedule.weekday in school_schedules_purchased %} {% if live_lesson %} {% include './open_lesson.html' %} {% endif %} - {% include './pay_btn.html' %} {% else %} + {% include './pay_btn.html' %} + {% endif %}
{% comment %} diff --git a/apps/school/views.py b/apps/school/views.py index 93f517c0..773f8797 100644 --- a/apps/school/views.py +++ b/apps/school/views.py @@ -79,16 +79,23 @@ class SchoolView(TemplateView): is_previous = 'is_previous' in self.request.GET date_now = now().date() if self.request.user.is_authenticated: - school_payment = SchoolPayment.objects.filter(user=self.request.user, date_start__lte=date_now, date_end__gte=date_now) + school_payment = SchoolPayment.objects.filter( + user=self.request.user, + date_start__lte=date_now, + date_end__gte=date_now + ) school_payment_exists = school_payment.exists() + school_schedules_purchased = school_payment.values_list('weekdays', flat=True)[0] else: school_payment_exists = False + school_schedules_purchased = [] context.update({ 'is_previous': is_previous, 'course_items': Course.objects.filter(status=Course.PUBLISHED)[:6], 'is_purchased': school_payment_exists, 'min_school_price': SchoolSchedule.objects.aggregate(Min('month_price'))['month_price__min'], 'school_schedules': SchoolSchedule.objects.all(), + 'school_schedules_purchased': school_schedules_purchased, 'subscription_ends': school_payment.first().date_end if school_payment_exists else None, }) return context