diff --git a/api/v1/views.py b/api/v1/views.py index 6fbde9c6..41cd881a 100644 --- a/api/v1/views.py +++ b/api/v1/views.py @@ -419,7 +419,7 @@ class AuthorRequestViewSet(ExtendedModelViewSet): class PaymentViewSet(ExtendedModelViewSet): - queryset = Payment.objects.order_by('-created_at') + queryset = Payment.objects.filter(status__isnull=False).order_by('-created_at') serializer_class = PaymentSerializer permission_classes = (IsAdmin,) filter_fields = ('status',) diff --git a/apps/payment/models.py b/apps/payment/models.py index 10146971..8dbbccb6 100644 --- a/apps/payment/models.py +++ b/apps/payment/models.py @@ -2,6 +2,7 @@ import arrow from paymentwall import Pingback from polymorphic.models import PolymorphicModel +from polymorphic.managers import PolymorphicManager from django.db import models from django.contrib.auth import get_user_model @@ -73,6 +74,12 @@ class AuthorBalance(models.Model): return self.amount * config.SERVICE_COMMISSION / 100 +class PaymentManger(PolymorphicManager): + + def all(self): + return self.filter(status__isnull=False) + + class Payment(PolymorphicModel): PW_STATUS_CHOICES = ( (Pingback.PINGBACK_TYPE_REGULAR, 'regular',), @@ -93,13 +100,12 @@ class Payment(PolymorphicModel): created_at = models.DateTimeField(auto_now_add=True) update_at = models.DateTimeField(auto_now=True) - non_polymorphic = models.Manager() + objects = PaymentManger() class Meta: verbose_name = 'Платеж' verbose_name_plural = 'Платежи' ordering = ('created_at',) - base_manager_name = 'non_polymorphic' def calc_commission(self): return self.amount * config.SERVICE_COMMISSION / 100 diff --git a/apps/payment/views.py b/apps/payment/views.py index 608d94d3..412b5516 100644 --- a/apps/payment/views.py +++ b/apps/payment/views.py @@ -6,6 +6,7 @@ from urllib.parse import urlsplit from django.contrib import messages from django.contrib.auth.decorators import login_required +from django.core.exceptions import DisallowedHost from django.http import HttpResponse from django.shortcuts import redirect, get_object_or_404 from django.views.generic import View, TemplateView @@ -247,4 +248,5 @@ class PaymentwallCallbackView(View): payment.author_balance.save() return HttpResponse('OK') else: + raise DisallowedHost return HttpResponse(status=403) diff --git a/apps/school/models.py b/apps/school/models.py index 1e6a44c6..ad9efb2e 100644 --- a/apps/school/models.py +++ b/apps/school/models.py @@ -44,7 +44,8 @@ class SchoolSchedule(models.Model): return dict(self.WEEKDAY_CHOICES).get(self.weekday, '') def is_online(self): - return now().isoweekday() == self.weekday and now().time() >= self.start_at + end_at = datetime.combine(now().today(), self.start_at) + timedelta(hours=2) + return self.start_at <= now().time() and end_at.time() >= now().time() def current_live_lesson(self): now_time = now() diff --git a/apps/user/models.py b/apps/user/models.py index fd94ab81..6adf6cf4 100644 --- a/apps/user/models.py +++ b/apps/user/models.py @@ -24,7 +24,6 @@ class UserManager(BaseUserManager): username = email if not password: password = self.make_random_password() - super().save(*args, **kwargs) email = self.normalize_email(email) username = self.model.normalize_username(username) user = self.model(username=username, email=email, **extra_fields) diff --git a/apps/user/templates/user/payment-history.html b/apps/user/templates/user/payment-history.html index f39fa3ff..5643dfa5 100644 --- a/apps/user/templates/user/payment-history.html +++ b/apps/user/templates/user/payment-history.html @@ -75,7 +75,7 @@
История платежей
- {% if request.user.payments.all|length %} + {% if request.user.payments.all.exists %} {% for payment in request.user.payments.all %}
{% if payment.course %} @@ -83,7 +83,6 @@ {% else %}
Школа. {% if payment.date_start and payment.date_end %}{{ payment.date_start }} - {{ payment.date_end }}{% endif %} - {{ payment }}
{% endif %} {% if payment.balance %} diff --git a/apps/user/templates/user/profile.html b/apps/user/templates/user/profile.html index 0dbd54b2..c1bb7f81 100644 --- a/apps/user/templates/user/profile.html +++ b/apps/user/templates/user/profile.html @@ -71,6 +71,7 @@ КУРСЫ {% endif %} +
@@ -89,6 +90,13 @@
{% endif %} +
+
+
+ {% include "course/school.html" %} +
+
+
diff --git a/apps/user/views.py b/apps/user/views.py index bf2a6ebd..a771152e 100644 --- a/apps/user/views.py +++ b/apps/user/views.py @@ -17,6 +17,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.urls import reverse_lazy from django.utils.decorators import method_decorator from django.utils.timezone import now @@ -63,6 +64,26 @@ class UserView(DetailView): ], ), ).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_payment'] = school_payment + if school_payment.exists() and school_payment.last().date_end: + context['school_days_left'] = (school_payment.last().date_end - now().date()).days + context['school_schedules'] = SchoolSchedule.objects.filter( + weekday__in=school_schedules_purchased if school_payment.exists() else [], + ) + return context