diff --git a/apps/school/models.py b/apps/school/models.py index a059172f..4eb71350 100644 --- a/apps/school/models.py +++ b/apps/school/models.py @@ -14,6 +14,7 @@ from apps.payment import models as payment_models class SchoolSchedule(models.Model): + WEEKDAY_SHORT_NAMES = ('пн', 'вт', 'ср', 'чт', 'пт', 'сб', 'вс') WEEKDAY_CHOICES = ( (1, 'понедельник'), (2, 'вторник'), diff --git a/apps/user/templates/user/profile.html b/apps/user/templates/user/profile.html index e8a81d33..0f77ec09 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 %} - {% endif %} -
-
+ {% if is_school_purchased %} + + {% 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