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/school/templates/blocks/schedule_item.html b/apps/school/templates/blocks/schedule_item.html index 7e860a4e..272ae2db 100644 --- a/apps/school/templates/blocks/schedule_item.html +++ b/apps/school/templates/blocks/schedule_item.html @@ -4,7 +4,7 @@
{{ 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 %} - {% 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..103ff126 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 @@ -55,11 +55,11 @@ class ProfileView(TemplateView): def get_context_data(self, object): context = super().get_context_data() context['user'] = self.request.user - context['is_author'] = self.request.user.role == User.AUTHOR_ROLE context['published'] = Course.objects.filter( author=self.object, ) + context['is_author'] = context['published'] or self.request.user.role == User.AUTHOR_ROLE context['paid'] = Course.objects.filter( payments__in=CoursePayment.objects.filter( user=self.object, @@ -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['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_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['is_purchased_future'] = False - context['school_purchased_future'] = False + context['profile'] = True return context @@ -107,7 +103,7 @@ class UserView(DetailView): def get_context_data(self, object): context = super().get_context_data() context['published'] = Course.objects.filter( - author=self.object, + author=self.object, status=Course.PUBLISHED, ) return context diff --git a/web/src/sass/_common.sass b/web/src/sass/_common.sass index c959b913..90dcb490 100755 --- a/web/src/sass/_common.sass +++ b/web/src/sass/_common.sass @@ -1710,6 +1710,8 @@ a.grey-link color: $cl +t line-height: 1.33 + &__theme + text-transform: uppercase &__user margin-top: 20px &_two &__item