From 1045093cac26f739f9375005ac20c26262f76838 Mon Sep 17 00:00:00 2001 From: Christian Cueni Date: Wed, 1 Jul 2020 16:24:46 +0200 Subject: [PATCH] Add data migration --- server/core/hep_client.py | 10 +++---- server/users/admin.py | 4 +-- server/users/migrations/0020_license_isbn.py | 1 - .../migrations/0021_auto_20200701_1342.py | 29 +++++++++++++++++++ 4 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 server/users/migrations/0021_auto_20200701_1342.py diff --git a/server/core/hep_client.py b/server/core/hep_client.py index 0a5b2726..6af2e2c5 100644 --- a/server/core/hep_client.py +++ b/server/core/hep_client.py @@ -20,16 +20,16 @@ MYSKILLBOX_LICENSES = { 'duration': 365, 'name': 'Student 1 year' }, - "978-3-0355-1861-0": { - 'edition': TEACHER_KEY, - 'duration': 30, - 'name': 'Teacher test 1 month' - }, "978-3-0355-1862-7": { 'edition': STUDENT_KEY, 'duration': 30, 'name': 'Student test 1 month' }, + "978-3-0355-1861-0": { + 'edition': TEACHER_KEY, + 'duration': 30, + 'name': 'Teacher test 1 month' + }, "978-3-0355-1823-8": { 'edition': TEACHER_KEY, 'duration': 365, diff --git a/server/users/admin.py b/server/users/admin.py index f36af2aa..f9e270da 100644 --- a/server/users/admin.py +++ b/server/users/admin.py @@ -72,6 +72,6 @@ class UserSettingAdmin(admin.ModelAdmin): @admin.register(License) class LicenseAdmin(admin.ModelAdmin): - list_display = ('licensee',) - list_filter = ('licensee',) + list_display = ('licensee', 'for_role', 'expire_date', 'isbn') + list_filter = ('licensee', 'expire_date') raw_id_fields = ('licensee',) diff --git a/server/users/migrations/0020_license_isbn.py b/server/users/migrations/0020_license_isbn.py index 2d1ac78c..26269b49 100644 --- a/server/users/migrations/0020_license_isbn.py +++ b/server/users/migrations/0020_license_isbn.py @@ -2,7 +2,6 @@ from django.db import migrations, models - class Migration(migrations.Migration): dependencies = [ diff --git a/server/users/migrations/0021_auto_20200701_1342.py b/server/users/migrations/0021_auto_20200701_1342.py new file mode 100644 index 00000000..d308b40b --- /dev/null +++ b/server/users/migrations/0021_auto_20200701_1342.py @@ -0,0 +1,29 @@ +# Generated by Django 2.1.15 on 2020-07-01 13:42 + +from django.db import migrations +from users.managers import RoleManager + +STUDENT_4Y_ISBN = '978-3-0355-1397-4' +TEACHER_1Y_ISBN = '978-3-0355-1823-8' + + +def add_isbn_to_license(apps, schema_editor): + License = apps.get_model('users', 'License') + for existing_license in License.objects.all(): + if existing_license.for_role.key == RoleManager.TEACHER_KEY: + existing_license.isbn = TEACHER_1Y_ISBN + else: + existing_license.isbn = STUDENT_4Y_ISBN + + existing_license.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0020_license_isbn'), + ] + + operations = [ + migrations.RunPython(add_isbn_to_license, migrations.RunPython.noop), + ]