From 07c0567c2faa67ffe0b10b74f3adc7ba55214817 Mon Sep 17 00:00:00 2001 From: gzbender Date: Fri, 8 Feb 2019 14:31:31 +0500 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D1=82=D1=8C=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=BB=D0=B5=20"=D0=BF=D1=80=D0=BE=D0=B4=D0=BE?= =?UTF-8?q?=D0=BB=D0=B6=D0=B8=D1=82=D0=B5=D0=BB=D1=8C=D0=BD=D0=BE=D1=81?= =?UTF-8?q?=D1=82=D1=8C=20=D0=B4=D0=BE=D1=81=D1=82=D1=83=D0=BF=D0=B0"=20?= =?UTF-8?q?=D1=83=20=D0=BA=D1=83=D1=80=D1=81=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/course/templates/course/_items.html | 13 +++++++++---- apps/course/views.py | 17 +++++++++++++---- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/apps/course/templates/course/_items.html b/apps/course/templates/course/_items.html index acbccf69..070f5dbc 100644 --- a/apps/course/templates/course/_items.html +++ b/apps/course/templates/course/_items.html @@ -50,11 +50,16 @@ {{ course.category | upper }} {% if not course.is_free %} - {% if course.old_price %} -
{{ course.old_price|floatformat:"-2" }}₽
+ {% if course.buy_again_price %} +
{{ course.price|floatformat:"-2" }}₽
+
{{ course.buy_again_price|floatformat:"-2" }}₽
+ {% else %} + {% if course.old_price %} +
{{ course.old_price|floatformat:"-2" }}₽
+ {% endif %} +
{{ course.price|floatformat:"-2" }}₽
{% endif %} -
{{ course.price|floatformat:"-2" }}₽
{% endif %} {{ course.title }} diff --git a/apps/course/views.py b/apps/course/views.py index fe9d5810..1f0a101f 100644 --- a/apps/course/views.py +++ b/apps/course/views.py @@ -1,5 +1,6 @@ -from paymentwall import Pingback +from datetime import timedelta +from paymentwall import Pingback from django.contrib.auth import get_user_model from django.contrib.auth.decorators import login_required from django.db.models import Q @@ -14,7 +15,7 @@ from django.views.decorators.http import require_http_methods from django.utils.translation import gettext as _ from django.utils.timezone import now -from apps.payment.models import AuthorBalance +from apps.payment.models import AuthorBalance, CoursePayment from .models import Course, Like, Lesson, CourseComment, LessonComment from .filters import CourseFilter @@ -244,9 +245,8 @@ class CourseView(DetailView): context['payment'] = payment context['access_duration'] = ((payment.access_expire - now().date()).days + 1) if payment else self.object.access_duration context['paid'] = bool(payment) - context['can_buy_again'] = bool(self.object.price) and (context['access_duration'] < 7 if payment else + context['can_buy_again'] = bool(self.object.price) and (context['access_duration'] <= 7 if payment else payments.filter(access_expire__lt=now().date()).exists()) - context['course_price'] = self.object.price / 2 if context['can_buy_again'] else self.object.price context['pending'] = self.object.payments.filter( user=self.request.user, status=Pingback.PINGBACK_TYPE_RISK_UNDER_REVIEW, @@ -257,6 +257,8 @@ class CourseView(DetailView): context['is_owner'] = self.object.author == self.request.user context['is_admin'] = self.request.user.role == User.ADMIN_ROLE context['has_full_access'] = context['is_owner'] or context['is_admin'] + + context['course_price'] = self.object.price / 2 if context.get('can_buy_again') else self.object.price return context def get_queryset(self): @@ -325,6 +327,13 @@ class CoursesView(ListView): context['age_name'] = dict(Course.AGE_CHOICES).get(age, '') else: context['age_name'] = '' + if self.request.user.is_authenticated: + can_buy_again_courses = list(CoursePayment.objects.filter(user=self.request.user, + status__in=CoursePayment.PW_PAID_STATUSES, + access_expire__lte=now().date() + timedelta(7)).values_list('course_id', flat=True)) + for course in context['course_items']: + if course.id in can_buy_again_courses: + course.buy_again_price = course.price / 2 return context def get_template_names(self):