Add add days functional to buy school

remotes/origin/hasaccess
Ivlev Denis 8 years ago
parent e5191ecb60
commit 8606806551
  1. 18
      apps/payment/migrations/0017_schoolpayment_add_days.py
  2. 1
      apps/payment/models.py
  3. 40
      apps/payment/views.py
  4. 2
      apps/school/views.py
  5. 6
      project/views.py

@ -0,0 +1,18 @@
# Generated by Django 2.0.4 on 2018-04-30 06:42
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('payment', '0016_auto_20180429_1308'),
]
operations = [
migrations.AddField(
model_name='schoolpayment',
name='add_days',
field=models.BooleanField(default=False, verbose_name='Докупленные дни'),
),
]

@ -143,6 +143,7 @@ class CoursePayment(Payment):
class SchoolPayment(Payment): class SchoolPayment(Payment):
weekdays = ArrayField(models.IntegerField(), size=7, verbose_name='Дни недели') weekdays = ArrayField(models.IntegerField(), size=7, verbose_name='Дни недели')
add_days = models.BooleanField('Докупленные дни', default=False)
date_start = models.DateField('Дата начала подписки', null=True, blank=True) date_start = models.DateField('Дата начала подписки', null=True, blank=True)
date_end = models.DateField('Дата окончания подписки', null=True, blank=True) date_end = models.DateField('Дата окончания подписки', null=True, blank=True)

@ -87,18 +87,32 @@ class SchoolBuyView(TemplateView):
host = urlsplit(self.request.META.get('HTTP_REFERER')) host = urlsplit(self.request.META.get('HTTP_REFERER'))
host = str(host[0]) + '://' + str(host[1]) host = str(host[0]) + '://' + str(host[1])
weekdays = set(request.GET.getlist('weekdays', [])) weekdays = set(request.GET.getlist('weekdays', []))
add_days = 'add_days' in request.GET
if not weekdays: if not weekdays:
messages.error(request, 'Выберите несколько дней недели.') messages.error(request, 'Выберите несколько дней недели.')
return redirect('index') return redirect('school:school')
try: try:
weekdays = [int(weekday) for weekday in weekdays] weekdays = [int(weekday) for weekday in weekdays]
except ValueError: except ValueError:
messages.error(request, 'Ошибка выбора дней недели.') messages.error(request, 'Ошибка выбора дней недели.')
return redirect('index') return redirect('school:school')
school_payment = SchoolPayment.objects.create( if add_days:
user=request.user, _school_payment = SchoolPayment.objects.get(
weekdays=weekdays, user=request.user,
) date_start__lte=now().date(),
date_end__gte=now().date(),
add_days=False,
)
school_payment = SchoolPayment.objects.create(
user=request.user,
weekdays=weekdays,
add_days=True,
)
else:
school_payment = SchoolPayment.objects.create(
user=request.user,
weekdays=weekdays,
)
product = Product( product = Product(
f'school_{school_payment.id}', f'school_{school_payment.id}',
school_payment.amount, school_payment.amount,
@ -166,8 +180,9 @@ class PaymentwallCallbackView(View):
if product_type_name == 'school': if product_type_name == 'school':
school_payment = SchoolPayment.objects.filter( school_payment = SchoolPayment.objects.filter(
user=payment.user, user=payment.user,
date_start__lte=now(), add_days=False,
date_end__gt=now(), date_start__lte=now().date(),
date_end__gte=now().date(),
status__in=[ status__in=[
Pingback.PINGBACK_TYPE_REGULAR, Pingback.PINGBACK_TYPE_REGULAR,
Pingback.PINGBACK_TYPE_GOODWILL, Pingback.PINGBACK_TYPE_GOODWILL,
@ -175,8 +190,12 @@ class PaymentwallCallbackView(View):
], ],
).last() ).last()
if school_payment: if school_payment:
date_start = school_payment.date_end + timedelta(days=1) if payment.add_days:
date_end = date_start + timedelta(days=30) date_start = now().date(),
date_end = school_payment.date_end,
else:
date_start = school_payment.date_end + timedelta(days=1)
date_end = date_start + timedelta(days=30)
else: else:
date_start = now() date_start = now()
date_end = now() + timedelta(days=30) date_end = now() + timedelta(days=30)
@ -197,6 +216,7 @@ class PaymentwallCallbackView(View):
'amount': payment.amount, 'amount': payment.amount,
'status': payment.status, 'status': payment.status,
'weekdays': payment.weekdays, 'weekdays': payment.weekdays,
'add_days': payment.add_days,
'date_start': payment.date_start, 'date_start': payment.date_start,
'date_end': payment.date_end, 'date_end': payment.date_end,
'created_at': payment.created_at, 'created_at': payment.created_at,

@ -99,7 +99,7 @@ class SchoolView(TemplateView):
width=date_now.weekday()-F('weekday') % 7, width=date_now.weekday()-F('weekday') % 7,
).order_by('-width'), ).order_by('-width'),
'school_schedules_purchased': school_schedules_purchased, 'school_schedules_purchased': school_schedules_purchased,
'subscription_ends': school_payment.first().date_end if school_payment_exists else None, 'subscription_ends': school_payment.filter(add_days=False).first().date_end if school_payment_exists else None,
}) })
return context return context

@ -48,12 +48,12 @@ class IndexView(TemplateView):
'online': online, 'online': online,
'course_items': Course.objects.filter(status=Course.PUBLISHED)[:6], 'course_items': Course.objects.filter(status=Course.PUBLISHED)[:6],
'is_purchased': school_payment_exists, 'is_purchased': school_payment_exists,
'min_school_price': SchoolSchedule.objects.all().aggregate(Min('month_price'))['month_price__min'], 'min_school_price': SchoolSchedule.objects.aggregate(Min('month_price'))['month_price__min'],
'school_schedules': SchoolSchedule.objects.all(), 'school_schedules': SchoolSchedule.objects.all(),
'school_schedules_purchased': school_schedules_purchased, 'school_schedules_purchased': school_schedules_purchased,
'teachers': User.objects.filter(role=User.TEACHER_ROLE, show_in_mainpage=True), 'teachers': User.objects.filter(role=User.TEACHER_ROLE, show_in_mainpage=True),
'subscription_ends': school_payment.first().date_end if school_payment_exists else None, 'subscription_ends': school_payment.filter(add_days=False).first().date_end if school_payment_exists else None,
'subscription_ends_humanize': school_payment.first().date_end_humanize if school_payment_exists else None, 'subscription_ends_humanize': school_payment.filter(add_days=False).first().date_end_humanize if school_payment_exists else None,
}) })
return context return context

Loading…
Cancel
Save