+ {% endif %}
{% if paid.exists %}
{% include "course/course_items.html" with course_items=paid %}
- {% else %}
+ {% endif %}
+ {% if not is_school_purchased and not paid.exists %}
-
Нет приобретённых курсов!
+
Нет приобретённых продуктов!
diff --git a/apps/user/views.py b/apps/user/views.py
index 41a18cb0..f1559f4e 100644
--- a/apps/user/views.py
+++ b/apps/user/views.py
@@ -16,7 +16,7 @@ from django.contrib.auth import get_user_model
from django.contrib.auth.decorators import login_required, permission_required
from django.contrib.auth.hashers import check_password, make_password
from django.http import Http404
-from django.db.models import F, Func
+from django.db.models import F, Func, Sum, Min, Max
from django.urls import reverse_lazy
from django.utils.decorators import method_decorator
from django.utils.timezone import now
@@ -80,22 +80,18 @@ class ProfileView(TemplateView):
Pingback.PINGBACK_TYPE_RISK_REVIEWED_ACCEPTED,
],
)
- school_schedules_purchased = school_payment.annotate(
- joined_weekdays=Func(F('weekdays'), function='unnest',)
- ).values_list('joined_weekdays', flat=True).distinct()
- context['school_schedules_purchased'] = school_schedules_purchased
- context['school_payment'] = school_payment
- context['is_purchased'] = school_payment.exists()
+ context['is_school_purchased'] = school_payment.exists()
+ if context['is_school_purchased']:
+ school_schedules_purchased = school_payment.annotate(
+ joined_weekdays=Func(F('weekdays'), function='unnest',)
+ ).values_list('joined_weekdays', flat=True).distinct()
+ aggregated = school_payment.aggregate(Sum('amount'), Min('date_start'), Max('date_end'),)
+ context['school_purchased_weekdays'] = '-'.join(map(lambda wd: SchoolSchedule.WEEKDAY_SHORT_NAMES[wd-1],
+ set(sorted(school_schedules_purchased))))
+ context['school_purchased_price'] = aggregated.get('amount__sum') or 0
+ context['school_purchased_dates'] = [aggregated.get('date_start__min'), aggregated.get('date_end__max')]
+
context['profile'] = True
- if school_payment.exists() and school_payment.last().date_end:
- context['subscription_ends'] = school_payment.last().date_end
- context['school_schedules'] = SchoolSchedule.objects.filter(
- weekday__in=school_schedules_purchased if school_payment.exists() else [],
- ).all()
- context['all_school_schedules'] = SchoolSchedule.objects.all()
-
- context['is_purchased_future'] = False
- context['school_purchased_future'] = False
return context