From ede46459175f25f29b194f61267ef663d63e93a5 Mon Sep 17 00:00:00 2001 From: Adam Stankiewicz Date: Thu, 31 Oct 2024 09:32:02 -0400 Subject: [PATCH] fix: migrations, django admin --- license_manager/apps/api/serializers.py | 9 ++-- license_manager/apps/subscriptions/admin.py | 13 +++-- ...ubscriptionexpirationmessaging_and_more.py | 53 +++++++++++++++++++ 3 files changed, 65 insertions(+), 10 deletions(-) create mode 100644 license_manager/apps/subscriptions/migrations/0074_historicalcustomsubscriptionexpirationmessaging_and_more.py diff --git a/license_manager/apps/api/serializers.py b/license_manager/apps/api/serializers.py index e3125b26..9a5735a7 100644 --- a/license_manager/apps/api/serializers.py +++ b/license_manager/apps/api/serializers.py @@ -371,7 +371,7 @@ def get_subscription_for_auto_applied_licenses(self, obj): subscription_plan = obj.auto_applicable_subscription return subscription_plan.uuid if subscription_plan else None - def has_custom_license_expiration_messaging_v2(self, obj): + def get_has_custom_license_expiration_messaging_v2(self, obj): custom_subscription_expiration_messaging = obj.custom_subscription_expiration_messaging if custom_subscription_expiration_messaging: return custom_subscription_expiration_messaging.has_custom_license_expiration_messaging @@ -383,20 +383,19 @@ def get_modal_header_text_v2(self, obj): return custom_subscription_expiration_messaging.modal_header_text return None - - def expired_subscription_modal_messaging_v2(self, obj): + def get_expired_subscription_modal_messaging_v2(self, obj): custom_subscription_expiration_messaging = obj.custom_subscription_expiration_messaging if custom_subscription_expiration_messaging: return custom_subscription_expiration_messaging.expired_subscription_modal_messaging return None - def button_label_in_modal_v2(self, obj): + def get_button_label_in_modal_v2(self, obj): custom_subscription_expiration_messaging = obj.custom_subscription_expiration_messaging if custom_subscription_expiration_messaging: return custom_subscription_expiration_messaging.button_label_in_modal return None - def url_for_button_in_modal_v2(self, obj): + def get_url_for_button_in_modal_v2(self, obj): custom_subscription_expiration_messaging = obj.custom_subscription_expiration_messaging if custom_subscription_expiration_messaging: return custom_subscription_expiration_messaging.url_for_button_in_modal diff --git a/license_manager/apps/subscriptions/admin.py b/license_manager/apps/subscriptions/admin.py index 17d64662..82304860 100644 --- a/license_manager/apps/subscriptions/admin.py +++ b/license_manager/apps/subscriptions/admin.py @@ -27,6 +27,7 @@ ) from license_manager.apps.subscriptions.models import ( CustomerAgreement, + CustomSubscriptionExpirationMessaging, License, LicenseEvent, LicenseTransferJob, @@ -402,6 +403,13 @@ def save_model(self, request, obj, form, change): obj.provision_licenses() +@admin.register(CustomSubscriptionExpirationMessaging) +class CustomSubscriptionExpirationMessagingAdmin(DjangoQLSearchMixin, admin.ModelAdmin): + list_display = ( + 'customer_agreement', + 'has_custom_license_expiration_messaging', + ) + @admin.register(CustomerAgreement) class CustomerAgreementAdmin(admin.ModelAdmin): form = CustomerAgreementAdminForm @@ -418,11 +426,6 @@ class CustomerAgreementAdmin(admin.ModelAdmin): 'license_duration_before_purge', 'disable_onboarding_notifications', 'enable_auto_applied_subscriptions_with_universal_link', - 'has_custom_license_expiration_messaging', - 'modal_header_text', - 'expired_subscription_modal_messaging', - 'button_label_in_modal', - 'url_for_button_in_modal', ) custom_fields = ('subscription_for_auto_applied_licenses',) diff --git a/license_manager/apps/subscriptions/migrations/0074_historicalcustomsubscriptionexpirationmessaging_and_more.py b/license_manager/apps/subscriptions/migrations/0074_historicalcustomsubscriptionexpirationmessaging_and_more.py new file mode 100644 index 00000000..f3c5b9c4 --- /dev/null +++ b/license_manager/apps/subscriptions/migrations/0074_historicalcustomsubscriptionexpirationmessaging_and_more.py @@ -0,0 +1,53 @@ +# Generated by Django 4.2.16 on 2024-10-31 13:23 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion +import simple_history.models + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('subscriptions', '0073_remove_customeragreement_hyper_link_text_for_expired_modal_and_more'), + ] + + operations = [ + migrations.CreateModel( + name='HistoricalCustomSubscriptionExpirationMessaging', + fields=[ + ('id', models.IntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')), + ('has_custom_license_expiration_messaging', models.BooleanField(default=False, help_text='Indicates if the customer has a unique license expiration experience, instead of the standard one.')), + ('modal_header_text', models.CharField(blank=True, help_text='The bold text that will appear as the header in the expiration modal.', max_length=512, null=True)), + ('expired_subscription_modal_messaging', models.TextField(blank=True, help_text='The content of a modal that will appear to learners upon subscription expiration. This text can be used for custom guidance per customer.', null=True)), + ('button_label_in_modal', models.CharField(blank=True, help_text='The text that will appear as on the button in the expiration modal', max_length=255, null=True)), + ('url_for_button_in_modal', models.CharField(blank=True, help_text='The URL that should underly the sole button in the expiration modal', max_length=512, null=True)), + ('history_id', models.AutoField(primary_key=True, serialize=False)), + ('history_date', models.DateTimeField()), + ('history_change_reason', models.CharField(max_length=100, null=True)), + ('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)), + ('customer_agreement', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='subscriptions.customeragreement')), + ('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)), + ], + options={ + 'verbose_name': 'historical custom subscription expiration messaging', + 'verbose_name_plural': 'historical custom subscription expiration messagings', + 'ordering': ('-history_date', '-history_id'), + 'get_latest_by': ('history_date', 'history_id'), + }, + bases=(simple_history.models.HistoricalChanges, models.Model), + ), + migrations.CreateModel( + name='CustomSubscriptionExpirationMessaging', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('has_custom_license_expiration_messaging', models.BooleanField(default=False, help_text='Indicates if the customer has a unique license expiration experience, instead of the standard one.')), + ('modal_header_text', models.CharField(blank=True, help_text='The bold text that will appear as the header in the expiration modal.', max_length=512, null=True)), + ('expired_subscription_modal_messaging', models.TextField(blank=True, help_text='The content of a modal that will appear to learners upon subscription expiration. This text can be used for custom guidance per customer.', null=True)), + ('button_label_in_modal', models.CharField(blank=True, help_text='The text that will appear as on the button in the expiration modal', max_length=255, null=True)), + ('url_for_button_in_modal', models.CharField(blank=True, help_text='The URL that should underly the sole button in the expiration modal', max_length=512, null=True)), + ('customer_agreement', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='custom_subscription_expiration_messaging', to='subscriptions.customeragreement')), + ], + ), + ]