|
|
|
|
@ -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): |
|
|
|
|
|