Merge branch 'dev' into 'master'

Dev

See merge request lilcity/backend!15
remotes/origin/hasaccess
Ivlev Denis 8 years ago
commit b82582263c
  1. 2
      api/v1/views.py
  2. 10
      apps/payment/models.py
  3. 2
      apps/payment/views.py
  4. 3
      apps/school/models.py
  5. 1
      apps/user/models.py
  6. 3
      apps/user/templates/user/payment-history.html
  7. 8
      apps/user/templates/user/profile.html
  8. 21
      apps/user/views.py

@ -419,7 +419,7 @@ class AuthorRequestViewSet(ExtendedModelViewSet):
class PaymentViewSet(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 serializer_class = PaymentSerializer
permission_classes = (IsAdmin,) permission_classes = (IsAdmin,)
filter_fields = ('status',) filter_fields = ('status',)

@ -2,6 +2,7 @@ import arrow
from paymentwall import Pingback from paymentwall import Pingback
from polymorphic.models import PolymorphicModel from polymorphic.models import PolymorphicModel
from polymorphic.managers import PolymorphicManager
from django.db import models from django.db import models
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
@ -73,6 +74,12 @@ class AuthorBalance(models.Model):
return self.amount * config.SERVICE_COMMISSION / 100 return self.amount * config.SERVICE_COMMISSION / 100
class PaymentManger(PolymorphicManager):
def all(self):
return self.filter(status__isnull=False)
class Payment(PolymorphicModel): class Payment(PolymorphicModel):
PW_STATUS_CHOICES = ( PW_STATUS_CHOICES = (
(Pingback.PINGBACK_TYPE_REGULAR, 'regular',), (Pingback.PINGBACK_TYPE_REGULAR, 'regular',),
@ -93,13 +100,12 @@ class Payment(PolymorphicModel):
created_at = models.DateTimeField(auto_now_add=True) created_at = models.DateTimeField(auto_now_add=True)
update_at = models.DateTimeField(auto_now=True) update_at = models.DateTimeField(auto_now=True)
non_polymorphic = models.Manager() objects = PaymentManger()
class Meta: class Meta:
verbose_name = 'Платеж' verbose_name = 'Платеж'
verbose_name_plural = 'Платежи' verbose_name_plural = 'Платежи'
ordering = ('created_at',) ordering = ('created_at',)
base_manager_name = 'non_polymorphic'
def calc_commission(self): def calc_commission(self):
return self.amount * config.SERVICE_COMMISSION / 100 return self.amount * config.SERVICE_COMMISSION / 100

@ -6,6 +6,7 @@ from urllib.parse import urlsplit
from django.contrib import messages from django.contrib import messages
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.core.exceptions import DisallowedHost
from django.http import HttpResponse from django.http import HttpResponse
from django.shortcuts import redirect, get_object_or_404 from django.shortcuts import redirect, get_object_or_404
from django.views.generic import View, TemplateView from django.views.generic import View, TemplateView
@ -247,4 +248,5 @@ class PaymentwallCallbackView(View):
payment.author_balance.save() payment.author_balance.save()
return HttpResponse('OK') return HttpResponse('OK')
else: else:
raise DisallowedHost
return HttpResponse(status=403) return HttpResponse(status=403)

@ -44,7 +44,8 @@ class SchoolSchedule(models.Model):
return dict(self.WEEKDAY_CHOICES).get(self.weekday, '') return dict(self.WEEKDAY_CHOICES).get(self.weekday, '')
def is_online(self): 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): def current_live_lesson(self):
now_time = now() now_time = now()

@ -24,7 +24,6 @@ class UserManager(BaseUserManager):
username = email username = email
if not password: if not password:
password = self.make_random_password() password = self.make_random_password()
super().save(*args, **kwargs)
email = self.normalize_email(email) email = self.normalize_email(email)
username = self.model.normalize_username(username) username = self.model.normalize_username(username)
user = self.model(username=username, email=email, **extra_fields) user = self.model(username=username, email=email, **extra_fields)

@ -75,7 +75,7 @@
<div class="title title_sm">История платежей</div> <div class="title title_sm">История платежей</div>
<div class="transactions"> <div class="transactions">
<div class="transactions__wrap"> <div class="transactions__wrap">
{% if request.user.payments.all|length %} {% if request.user.payments.all.exists %}
{% for payment in request.user.payments.all %} {% for payment in request.user.payments.all %}
<div class="transactions__row"> <div class="transactions__row">
{% if payment.course %} {% if payment.course %}
@ -83,7 +83,6 @@
{% else %} {% else %}
<div class="transactions__cell"> <div class="transactions__cell">
Школа. {% if payment.date_start and payment.date_end %}{{ payment.date_start }} - {{ payment.date_end }}{% endif %} Школа. {% if payment.date_start and payment.date_end %}{{ payment.date_start }} - {{ payment.date_end }}{% endif %}
{{ payment }}
</div> </div>
{% endif %} {% endif %}
{% if payment.balance %} {% if payment.balance %}

@ -71,6 +71,7 @@
<span class="mobile-hide">КУРСЫ</span> <span class="mobile-hide">КУРСЫ</span>
</button> </button>
{% endif %} {% endif %}
<button class="tabs__btn js-tabs-btn">ШКОЛА</button>
</div> </div>
<div class="tabs__container"> <div class="tabs__container">
<div class="tabs__item js-tabs-item"> <div class="tabs__item js-tabs-item">
@ -89,6 +90,13 @@
</div> </div>
</div> </div>
{% endif %} {% endif %}
<div class="tabs__item js-tabs-item">
<div class="courses courses_scroll">
<div class="courses__list">
{% include "course/school.html" %}
</div>
</div>
</div>
</div> </div>
</div> </div>
</div> </div>

@ -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.decorators import login_required, permission_required
from django.contrib.auth.hashers import check_password, make_password from django.contrib.auth.hashers import check_password, make_password
from django.http import Http404 from django.http import Http404
from django.db.models import F, Func
from django.urls import reverse_lazy from django.urls import reverse_lazy
from django.utils.decorators import method_decorator from django.utils.decorators import method_decorator
from django.utils.timezone import now from django.utils.timezone import now
@ -63,6 +64,26 @@ class UserView(DetailView):
], ],
), ),
).distinct() ).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 return context

Loading…
Cancel
Save