From 8fb1fe5a8df4599fbe7a3e50e01c4042a1757834 Mon Sep 17 00:00:00 2001 From: gzbender Date: Sun, 29 Jul 2018 19:10:44 +0500 Subject: [PATCH] =?UTF-8?q?Fix=20LIL-572=20=D0=9D=D0=B5=D0=B7=D0=B0=D1=80?= =?UTF-8?q?=D0=B5=D0=B3=D0=B0=D0=BD=D0=BD=D1=8B=D0=B5=20=D0=BF=D0=BE=D0=BB?= =?UTF-8?q?=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D1=82=D0=B5=D0=BB=D0=B8=20=D0=B2?= =?UTF-8?q?=D0=B8=D0=B4=D1=8F=D1=82=20=D1=87=D0=B5=D1=80=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=B8=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/user/templates/user/profile.html | 72 ++++++++++++------------ apps/user/views.py | 80 ++++++++++++++------------- 2 files changed, 79 insertions(+), 73 deletions(-) diff --git a/apps/user/templates/user/profile.html b/apps/user/templates/user/profile.html index 6b0f0b07..44ddb48c 100644 --- a/apps/user/templates/user/profile.html +++ b/apps/user/templates/user/profile.html @@ -78,54 +78,54 @@
{% if owner %} -
- {% if is_purchased_future %} -
-
-
Ваша подписка начинается {{school_purchased_future.date_start}}
-
-
- {% else %} - {% if is_purchased %} - {% include "blocks/schedule_purchased.html" %} - {% else %} -
-
-
Вы не подписаны на лагерь!
-
- Купить подписку +
+ {% if is_purchased_future %} +
+
+
Ваша подписка начинается {{school_purchased_future.date_start}}
-
- {% endif %} - {% endif %} -
-
-
-
- {% if paid.exists %} - {% include "course/course_items.html" with course_items=paid %} + {% else %} + {% if is_purchased %} + {% include "blocks/schedule_purchased.html" %} {% else %}
-
Нет приобретённых курсов!
+
Вы не подписаны на лагерь!
{% endif %} + {% endif %} +
+
+
+
+ {% if paid.exists %} + {% include "course/course_items.html" with course_items=paid %} + {% else %} +
+
+
Нет приобретённых курсов!
+ +
+
+ {% endif %} +
-
{% endif %}
diff --git a/apps/user/views.py b/apps/user/views.py index 500d8404..6530c309 100644 --- a/apps/user/views.py +++ b/apps/user/views.py @@ -56,56 +56,62 @@ class UserView(DetailView): else: context['simple_user'] = True context['guest'] = True - context['owner'] = self.request.user.id == self.object.id + owner = self.request.user.id == self.object.id if context['guest'] and self.object.role <= User.USER_ROLE: raise Http404() - context['published'] = Course.objects.filter( + published = Course.objects.filter( author=self.object, ) - context['paid'] = Course.objects.filter( - payments__in=CoursePayment.objects.filter( + if not owner: + published = published.filter(status=Course.PUBLISHED) + else: + context['paid'] = Course.objects.filter( + payments__in=CoursePayment.objects.filter( + user=self.object, + status__in=[ + Pingback.PINGBACK_TYPE_REGULAR, + Pingback.PINGBACK_TYPE_GOODWILL, + Pingback.PINGBACK_TYPE_RISK_REVIEWED_ACCEPTED, + ], + ), + ).distinct() + school_payment = SchoolPayment.objects.filter( user=self.object, + date_start__lte=now(), + date_end__gt=now(), status__in=[ Pingback.PINGBACK_TYPE_REGULAR, Pingback.PINGBACK_TYPE_GOODWILL, Pingback.PINGBACK_TYPE_RISK_REVIEWED_ACCEPTED, ], - ), - ).distinct() - school_payment = SchoolPayment.objects.filter( - user=self.object, - date_start__lte=now(), - date_end__gt=now(), - status__in=[ - Pingback.PINGBACK_TYPE_REGULAR, - Pingback.PINGBACK_TYPE_GOODWILL, - 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() - - school_payment_future = SchoolPayment.objects.filter( - user=self.object, - date_start__gte=now(), - date_end__gte=now() - ) + ) + 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() + + school_payment_future = SchoolPayment.objects.filter( + user=self.object, + date_start__gte=now(), + date_end__gte=now() + ) + + context['is_purchased_future'] = school_payment_future.exists() + context['school_purchased_future'] = school_payment_future.last() - context['is_purchased_future'] = school_payment_future.exists() - context['school_purchased_future'] = school_payment_future.last() + context['owner'] = owner + context['published'] = published return context