You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
848 B
25 lines
848 B
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()
|
|
|
|
|
|
|