diff --git a/server/users/management/commands/reset_license_duration.py b/server/users/management/commands/reset_license_duration.py new file mode 100644 index 00000000..61f21402 --- /dev/null +++ b/server/users/management/commands/reset_license_duration.py @@ -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) diff --git a/server/users/managers.py b/server/users/managers.py index 2a545850..b0a6578b 100644 --- a/server/users/managers.py +++ b/server/users/managers.py @@ -147,14 +147,15 @@ class LicenseManager(models.Manager): else: 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.save() return new_license - def _create_license_for_role(self, licensee, expiry_date, raw, role, order_id): - return self.create(licensee=licensee, expire_date=expiry_date, raw=raw, for_role=role, order_id=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, + isbn=isbn) def get_active_license_for_user(self, user): licenses = self.filter(licensee=user, expire_date__gte=timezone.now()).order_by('-expire_date')