27 lines
756 B
Python
27 lines
756 B
Python
from django.core.management.base import BaseCommand
|
|
|
|
from users.models import License
|
|
|
|
|
|
class Command(BaseCommand):
|
|
help = """
|
|
Overwrites the License model's IBAN with the IBAN from the hep-JSON
|
|
"""
|
|
|
|
def add_arguments(self, parser):
|
|
parser.add_argument('--dry-run', action='store_true', dest='dry_run', default=False, help='Make dry-run')
|
|
|
|
def handle(self, *args, **options):
|
|
|
|
for license in License.objects.all():
|
|
isbn = license.get_hep_isbn()
|
|
|
|
if isbn == license.isbn:
|
|
continue
|
|
|
|
print(f'Setting ISBN for licenseID {license.id} from {license.isbn} to {isbn}')
|
|
|
|
if not options['dry_run']:
|
|
license.isbn = isbn
|
|
license.save()
|