Save correct license for user
This commit is contained in:
parent
e77cb477c5
commit
dbd5f92fbd
|
|
@ -0,0 +1,17 @@
|
||||||
|
from django.utils.timezone import now
|
||||||
|
from django.core.management.base import BaseCommand
|
||||||
|
|
||||||
|
from users.models import License
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
help = 'Reset licenses that have a duration that is longer than the standard duration'
|
||||||
|
|
||||||
|
def add_arguments(self, parser):
|
||||||
|
parser.add_argument('--dry-run', action='store_true', dest='save', default=False, help='Make dry-run')
|
||||||
|
|
||||||
|
def handle(self, *args, **options):
|
||||||
|
today = now().date()
|
||||||
|
|
||||||
|
for license in License.objects.filter(expire_date__gte=today):
|
||||||
|
print(license)
|
||||||
|
|
@ -147,14 +147,15 @@ class LicenseManager(models.Manager):
|
||||||
else:
|
else:
|
||||||
user_role = Role.objects.get_default_student_role()
|
user_role = Role.objects.get_default_student_role()
|
||||||
|
|
||||||
new_license = self._create_license_for_role(licensee, expiry_date, raw, user_role, order_id)
|
new_license = self._create_license_for_role(licensee, expiry_date, raw, user_role, order_id, isbn)
|
||||||
new_license.licensee.license_expiry_date = new_license.expire_date
|
new_license.licensee.license_expiry_date = new_license.expire_date
|
||||||
new_license.licensee.save()
|
new_license.licensee.save()
|
||||||
|
|
||||||
return new_license
|
return new_license
|
||||||
|
|
||||||
def _create_license_for_role(self, licensee, expiry_date, raw, role, order_id):
|
def _create_license_for_role(self, licensee, expiry_date, raw, role, order_id, isbn):
|
||||||
return self.create(licensee=licensee, expire_date=expiry_date, raw=raw, for_role=role, order_id=order_id)
|
return self.create(licensee=licensee, expire_date=expiry_date, raw=raw, for_role=role, order_id=order_id,
|
||||||
|
isbn=isbn)
|
||||||
|
|
||||||
def get_active_license_for_user(self, user):
|
def get_active_license_for_user(self, user):
|
||||||
licenses = self.filter(licensee=user, expire_date__gte=timezone.now()).order_by('-expire_date')
|
licenses = self.filter(licensee=user, expire_date__gte=timezone.now()).order_by('-expire_date')
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue