remotes/origin/feature/testing_courses_30-01-19
commit
45427829f8
27 changed files with 421 additions and 198 deletions
@ -0,0 +1,40 @@ |
||||
from datetime import timedelta |
||||
|
||||
from django.core.management.base import BaseCommand |
||||
|
||||
from apps.payment.models import CoursePayment |
||||
from apps.course.models import Course |
||||
|
||||
|
||||
class Command(BaseCommand): |
||||
help = 'Fix access duration in all paid courses' |
||||
|
||||
def add_arguments(self, parser): |
||||
parser.add_argument('access_duration', type=int, help='New access duration',) |
||||
|
||||
def handle(self, *args, **options): |
||||
access_duration = options.get('access_duration') |
||||
for course in Course.objects.filter(price__gt=0): |
||||
course.access_duration = access_duration |
||||
course.save() |
||||
|
||||
for payment in CoursePayment.objects.filter(status__in=CoursePayment.PW_PAID_STATUSES): |
||||
payment.access_expire = payment.created_at.date() + timedelta(days=payment.course.access_duration) |
||||
payment.save() |
||||
|
||||
|
||||
''' |
||||
TEST |
||||
|
||||
select c.id, c.title, cp.access_duration |
||||
from |
||||
course_course c, |
||||
(select cp.course_id, count(*), cp.access_expire - date_trunc('day', p.created_at) access_duration |
||||
from payment_coursepayment cp, |
||||
payment_payment p |
||||
where p.id = cp.payment_ptr_id and p.status = 0 |
||||
group by cp.course_id, cp.access_expire - date_trunc('day', p.created_at)) cp |
||||
where cp.course_id = c.id |
||||
order by c.title |
||||
''' |
||||
|
||||
@ -0,0 +1,18 @@ |
||||
# Generated by Django 2.0.7 on 2019-02-06 17:10 |
||||
|
||||
from django.db import migrations, models |
||||
|
||||
|
||||
class Migration(migrations.Migration): |
||||
|
||||
dependencies = [ |
||||
('course', '0047_course_old_price'), |
||||
] |
||||
|
||||
operations = [ |
||||
migrations.AlterField( |
||||
model_name='course', |
||||
name='duration', |
||||
field=models.IntegerField(default=0, verbose_name='Продолжительность доступа к курсу'), |
||||
), |
||||
] |
||||
@ -0,0 +1,18 @@ |
||||
# Generated by Django 2.0.7 on 2019-02-07 15:51 |
||||
|
||||
from django.db import migrations |
||||
|
||||
|
||||
class Migration(migrations.Migration): |
||||
|
||||
dependencies = [ |
||||
('course', '0048_auto_20190206_1710'), |
||||
] |
||||
|
||||
operations = [ |
||||
migrations.RenameField( |
||||
model_name='course', |
||||
old_name='duration', |
||||
new_name='access_duration', |
||||
), |
||||
] |
||||
@ -0,0 +1,8 @@ |
||||
# TODO: test_course_access_duration |
||||
''' |
||||
сделать поле "продолжительность доступа" у курсов: автор указывает продолжительность, |
||||
после покупки по истечению указанного кол-ва дней у пользователя нет доступа к курсу, |
||||
но он может его купить с 50% скидкой, при покупке курса появляется надпись "осталось Х дней доступа", |
||||
так же за неделю до окончания можно купить курс еще раз с 50% скидкой, при этом доступ продлевается |
||||
на указанное кол-во дней в продолжительности |
||||
''' |
||||
@ -0,0 +1,18 @@ |
||||
from datetime import timedelta |
||||
|
||||
from django.core.management.base import BaseCommand |
||||
from django.db.models import F |
||||
|
||||
from apps.payment.models import CoursePayment |
||||
|
||||
|
||||
class Command(BaseCommand): |
||||
help = 'Fill payment.access_expire where it is not filled' |
||||
|
||||
def handle(self, *args, **options): |
||||
|
||||
for payment in CoursePayment.objects.filter(access_expire__isnull=True): |
||||
payment.access_expire = payment.created_at.date() + timedelta(days=payment.course.access_duration) |
||||
payment.save() |
||||
|
||||
|
||||
@ -0,0 +1,18 @@ |
||||
# Generated by Django 2.0.7 on 2019-02-06 17:10 |
||||
|
||||
from django.db import migrations, models |
||||
|
||||
|
||||
class Migration(migrations.Migration): |
||||
|
||||
dependencies = [ |
||||
('payment', '0030_auto_20190114_1649'), |
||||
] |
||||
|
||||
operations = [ |
||||
migrations.AddField( |
||||
model_name='coursepayment', |
||||
name='access_expired', |
||||
field=models.DateField(null=True, verbose_name='Доступ к курсу до даты'), |
||||
), |
||||
] |
||||
@ -0,0 +1,18 @@ |
||||
# Generated by Django 2.0.7 on 2019-02-07 12:33 |
||||
|
||||
from django.db import migrations |
||||
|
||||
|
||||
class Migration(migrations.Migration): |
||||
|
||||
dependencies = [ |
||||
('payment', '0031_coursepayment_access_expired'), |
||||
] |
||||
|
||||
operations = [ |
||||
migrations.RenameField( |
||||
model_name='coursepayment', |
||||
old_name='access_expired', |
||||
new_name='access_expire', |
||||
), |
||||
] |
||||
Loading…
Reference in new issue