From a3cdbd9fd9796843884272b83c8e4473eb159064 Mon Sep 17 00:00:00 2001 From: Bernardo Fontes Date: Wed, 10 Aug 2022 18:36:09 +0200 Subject: [PATCH 1/8] Add missing migration after changing ordring of packages The ordering in Meta was change by 0197bd584c56621c251f9d20352396e029c0af30 --- sponsors/migrations/0086_auto_20220810_1635.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 sponsors/migrations/0086_auto_20220810_1635.py diff --git a/sponsors/migrations/0086_auto_20220810_1635.py b/sponsors/migrations/0086_auto_20220810_1635.py new file mode 100644 index 000000000..6ce364e6e --- /dev/null +++ b/sponsors/migrations/0086_auto_20220810_1635.py @@ -0,0 +1,17 @@ +# Generated by Django 2.2.24 on 2022-08-10 16:35 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('sponsors', '0085_auto_20220730_0945'), + ] + + operations = [ + migrations.AlterModelOptions( + name='sponsorshippackage', + options={'ordering': ('-year', 'order')}, + ), + ] From b22be2db6f931cb67786d0b5c2aa387c3d9e5905 Mon Sep 17 00:00:00 2001 From: Bernardo Fontes Date: Wed, 10 Aug 2022 18:49:47 +0200 Subject: [PATCH 2/8] Rename TieredQuantity to TieredBenefit (both configuration and feature objects) --- sponsors/admin.py | 6 ++--- .../commands/fullfill_pycon_2022.py | 4 +-- .../migrations/0087_auto_20220810_1647.py | 26 +++++++++++++++++++ sponsors/models/__init__.py | 6 ++--- sponsors/models/benefits.py | 24 ++++++++--------- sponsors/models/sponsorship.py | 4 +-- sponsors/templatetags/sponsors.py | 4 +-- sponsors/tests/test_managers.py | 8 +++--- sponsors/tests/test_models.py | 26 +++++++++---------- sponsors/tests/test_templatetags.py | 4 +-- 10 files changed, 69 insertions(+), 43 deletions(-) create mode 100644 sponsors/migrations/0087_auto_20220810_1647.py diff --git a/sponsors/admin.py b/sponsors/admin.py index 0d655a194..2e7620939 100644 --- a/sponsors/admin.py +++ b/sponsors/admin.py @@ -67,8 +67,8 @@ class BenefitFeatureConfigurationInline(StackedPolymorphicInline): class LogoPlacementConfigurationInline(StackedPolymorphicInline.Child): model = LogoPlacementConfiguration - class TieredQuantityConfigurationInline(StackedPolymorphicInline.Child): - model = TieredQuantityConfiguration + class TieredBenefitConfigurationInline(StackedPolymorphicInline.Child): + model = TieredBenefitConfiguration class EmailTargetableConfigurationInline(StackedPolymorphicInline.Child): model = EmailTargetableConfiguration @@ -96,7 +96,7 @@ class ProvidedFileAssetConfigurationInline(StackedPolymorphicInline.Child): model = BenefitFeatureConfiguration child_inlines = [ LogoPlacementConfigurationInline, - TieredQuantityConfigurationInline, + TieredBenefitConfigurationInline, EmailTargetableConfigurationInline, RequiredImgAssetConfigurationInline, RequiredTextAssetConfigurationInline, diff --git a/sponsors/management/commands/fullfill_pycon_2022.py b/sponsors/management/commands/fullfill_pycon_2022.py index 6f2f59e7f..86ee26a1e 100644 --- a/sponsors/management/commands/fullfill_pycon_2022.py +++ b/sponsors/management/commands/fullfill_pycon_2022.py @@ -16,7 +16,7 @@ SponsorBenefit, BenefitFeature, ProvidedTextAsset, - TieredQuantity, + TieredBenefit, ) API_KEY = settings.PYCON_API_KEY @@ -77,7 +77,7 @@ def handle(self, **options): .all() ): try: - quantity = BenefitFeature.objects.instance_of(TieredQuantity).get( + quantity = BenefitFeature.objects.instance_of(TieredBenefit).get( sponsor_benefit=sponsorbenefit ) except BenefitFeature.DoesNotExist: diff --git a/sponsors/migrations/0087_auto_20220810_1647.py b/sponsors/migrations/0087_auto_20220810_1647.py new file mode 100644 index 000000000..49080ba78 --- /dev/null +++ b/sponsors/migrations/0087_auto_20220810_1647.py @@ -0,0 +1,26 @@ +# Generated by Django 2.2.24 on 2022-08-10 16:47 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('contenttypes', '0002_remove_content_type_name'), + ('sponsors', '0086_auto_20220810_1635'), + ] + + operations = [ + migrations.RenameModel( + old_name='TieredQuantity', + new_name='TieredBenefit', + ), + migrations.RenameModel( + old_name='TieredQuantityConfiguration', + new_name='TieredBenefitConfiguration', + ), + migrations.AlterModelOptions( + name='tieredbenefit', + options={'base_manager_name': 'objects', 'verbose_name': 'Tiered Benefit', 'verbose_name_plural': 'Tiered Benefits'}, + ), + ] diff --git a/sponsors/models/__init__.py b/sponsors/models/__init__.py index 51f2886dd..11f1f1df4 100644 --- a/sponsors/models/__init__.py +++ b/sponsors/models/__init__.py @@ -7,9 +7,9 @@ from .assets import GenericAsset, ImgAsset, TextAsset, FileAsset, ResponseAsset from .notifications import SponsorEmailNotificationTemplate, SPONSOR_TEMPLATE_HELP_TEXT from .sponsors import Sponsor, SponsorContact, SponsorBenefit -from .benefits import BaseLogoPlacement, BaseTieredQuantity, BaseEmailTargetable, BenefitFeatureConfiguration, \ - LogoPlacementConfiguration, TieredQuantityConfiguration, EmailTargetableConfiguration, BenefitFeature, \ - LogoPlacement, EmailTargetable, TieredQuantity, RequiredImgAsset, RequiredImgAssetConfiguration, \ +from .benefits import BaseLogoPlacement, BaseTieredBenefit, BaseEmailTargetable, BenefitFeatureConfiguration, \ + LogoPlacementConfiguration, TieredBenefitConfiguration, EmailTargetableConfiguration, BenefitFeature, \ + LogoPlacement, EmailTargetable, TieredBenefit, RequiredImgAsset, RequiredImgAssetConfiguration, \ RequiredTextAssetConfiguration, RequiredTextAsset, RequiredResponseAssetConfiguration, RequiredResponseAsset, \ ProvidedTextAssetConfiguration, ProvidedTextAsset, ProvidedFileAssetConfiguration, ProvidedFileAsset from .sponsorship import Sponsorship, SponsorshipProgram, SponsorshipBenefit, Sponsorship, SponsorshipPackage, \ diff --git a/sponsors/models/benefits.py b/sponsors/models/benefits.py index d0223c2b6..1f81069fb 100644 --- a/sponsors/models/benefits.py +++ b/sponsors/models/benefits.py @@ -47,7 +47,7 @@ class Meta: abstract = True -class BaseTieredQuantity(models.Model): +class BaseTieredBenefit(models.Model): package = models.ForeignKey("sponsors.SponsorshipPackage", on_delete=models.CASCADE) quantity = models.PositiveIntegerField() @@ -394,18 +394,18 @@ def __str__(self): return f"Logo Configuration for {self.get_publisher_display()} at {self.get_logo_place_display()}" -class TieredQuantityConfiguration(BaseTieredQuantity, BenefitFeatureConfiguration): +class TieredBenefitConfiguration(BaseTieredBenefit, BenefitFeatureConfiguration): """ Configuration for tiered quantities among packages """ - class Meta(BaseTieredQuantity.Meta, BenefitFeatureConfiguration.Meta): + class Meta(BaseTieredBenefit.Meta, BenefitFeatureConfiguration.Meta): verbose_name = "Tiered Benefit Configuration" verbose_name_plural = "Tiered Benefit Configurations" @property def benefit_feature_class(self): - return TieredQuantity + return TieredBenefit def get_benefit_feature_kwargs(self, **kwargs): if kwargs["sponsor_benefit"].sponsorship.package == self.package: @@ -413,7 +413,7 @@ def get_benefit_feature_kwargs(self, **kwargs): return None def __str__(self): - return f"Tiered Quantity Configuration for {self.benefit} and {self.package} ({self.quantity})" + return f"Tiered Benefit Configuration for {self.benefit} and {self.package} ({self.quantity})" def display_modifier(self, name, **kwargs): if kwargs.get("package") != self.package: @@ -431,7 +431,7 @@ class EmailTargetableConfiguration(BaseEmailTargetable, BenefitFeatureConfigurat Configuration for email targeatable benefits """ - class Meta(BaseTieredQuantity.Meta, BenefitFeatureConfiguration.Meta): + class Meta(BaseTieredBenefit.Meta, BenefitFeatureConfiguration.Meta): verbose_name = "Email Targetable Configuration" verbose_name_plural = "Email Targetable Configurations" @@ -554,14 +554,14 @@ def __str__(self): return f"Logo for {self.get_publisher_display()} at {self.get_logo_place_display()}" -class TieredQuantity(BaseTieredQuantity, BenefitFeature): +class TieredBenefit(BaseTieredBenefit, BenefitFeature): """ - Tiered Quantity feature for sponsor benefits + Tiered Benefit feature for sponsor benefits """ - class Meta(BaseTieredQuantity.Meta, BenefitFeature.Meta): - verbose_name = "Tiered Quantity" - verbose_name_plural = "Tiered Quantities" + class Meta(BaseTieredBenefit.Meta, BenefitFeature.Meta): + verbose_name = "Tiered Benefit" + verbose_name_plural = "Tiered Benefits" def display_modifier(self, name, **kwargs): return f"{name} ({self.quantity})" @@ -575,7 +575,7 @@ class EmailTargetable(BaseEmailTargetable, BenefitFeature): For email targeatable benefits """ - class Meta(BaseTieredQuantity.Meta, BenefitFeature.Meta): + class Meta(BaseTieredBenefit.Meta, BenefitFeature.Meta): verbose_name = "Email Targetable Benefit" verbose_name_plural = "Email Targetable Benefits" diff --git a/sponsors/models/sponsorship.py b/sponsors/models/sponsorship.py index 4ba5ccd9f..59048bf53 100644 --- a/sponsors/models/sponsorship.py +++ b/sponsors/models/sponsorship.py @@ -24,7 +24,7 @@ from sponsors.models.assets import GenericAsset from sponsors.models.managers import SponsorshipPackageQuerySet, SponsorshipBenefitQuerySet, \ SponsorshipQuerySet, SponsorshipCurrentYearQuerySet -from sponsors.models.benefits import TieredQuantityConfiguration +from sponsors.models.benefits import TieredBenefitConfiguration from sponsors.models.sponsors import SponsorBenefit YEAR_VALIDATORS = [ @@ -514,7 +514,7 @@ def name_for_display(self, package=None): @cached_property def has_tiers(self): - return self.features_config.instance_of(TieredQuantityConfiguration).count() > 0 + return self.features_config.instance_of(TieredBenefitConfiguration).count() > 0 @transaction.atomic def clone(self, year: int): diff --git a/sponsors/templatetags/sponsors.py b/sponsors/templatetags/sponsors.py index bb5a19481..a9ad12791 100644 --- a/sponsors/templatetags/sponsors.py +++ b/sponsors/templatetags/sponsors.py @@ -5,7 +5,7 @@ from django.conf import settings from django.core.cache import cache -from ..models import Sponsorship, SponsorshipPackage, TieredQuantityConfiguration +from ..models import Sponsorship, SponsorshipPackage, TieredBenefitConfiguration from sponsors.models.enums import PublisherChoices, LogoPlacementChoices @@ -60,7 +60,7 @@ def list_sponsors(logo_place, publisher=PublisherChoices.FOUNDATION.value): @register.simple_tag def benefit_quantity_for_package(benefit, package): - quantity_configuration = TieredQuantityConfiguration.objects.filter( + quantity_configuration = TieredBenefitConfiguration.objects.filter( benefit=benefit, package=package ).first() if quantity_configuration is None: diff --git a/sponsors/tests/test_managers.py b/sponsors/tests/test_managers.py index 432389663..5bcb67b87 100644 --- a/sponsors/tests/test_managers.py +++ b/sponsors/tests/test_managers.py @@ -4,7 +4,7 @@ from django.conf import settings from django.test import TestCase -from ..models import Sponsorship, SponsorBenefit, LogoPlacement, TieredQuantity, RequiredTextAsset, RequiredImgAsset, \ +from ..models import Sponsorship, SponsorBenefit, LogoPlacement, TieredBenefit, RequiredTextAsset, RequiredImgAsset, \ BenefitFeature, SponsorshipPackage, SponsorshipBenefit, SponsorshipCurrentYear from sponsors.models.enums import LogoPlacementChoices, PublisherChoices @@ -109,7 +109,7 @@ def test_filter_sponsorship_by_benefit_feature_type(self): sponsorship_feature_1 = baker.make_recipe('sponsors.tests.finalized_sponsorship') sponsorship_feature_2 = baker.make_recipe('sponsors.tests.finalized_sponsorship') baker.make(LogoPlacement, sponsor_benefit__sponsorship=sponsorship_feature_1) - baker.make(TieredQuantity, sponsor_benefit__sponsorship=sponsorship_feature_2) + baker.make(TieredBenefit, sponsor_benefit__sponsorship=sponsorship_feature_2) with self.assertNumQueries(1): qs = list(Sponsorship.objects.includes_benefit_feature(LogoPlacement)) @@ -124,7 +124,7 @@ def setUp(self): self.benefit = baker.make(SponsorBenefit, sponsorship=self.sponsorship) def test_filter_benefits_from_sponsorship(self): - feature_1 = baker.make(TieredQuantity, sponsor_benefit=self.benefit) + feature_1 = baker.make(TieredBenefit, sponsor_benefit=self.benefit) feature_2 = baker.make(LogoPlacement, sponsor_benefit=self.benefit) baker.make(LogoPlacement) # benefit from other sponsor benefit @@ -135,7 +135,7 @@ def test_filter_benefits_from_sponsorship(self): self.assertIn(feature_2, qs) def test_filter_only_for_required_assets(self): - baker.make(TieredQuantity) + baker.make(TieredBenefit) text_asset = baker.make(RequiredTextAsset) img_asset = baker.make(RequiredImgAsset) diff --git a/sponsors/tests/test_models.py b/sponsors/tests/test_models.py index 0dad14bef..4436ba85e 100644 --- a/sponsors/tests/test_models.py +++ b/sponsors/tests/test_models.py @@ -21,8 +21,8 @@ Sponsorship, SponsorshipBenefit, SponsorshipPackage, - TieredQuantity, - TieredQuantityConfiguration, RequiredImgAssetConfiguration, RequiredImgAsset, ImgAsset, + TieredBenefit, + TieredBenefitConfiguration, RequiredImgAssetConfiguration, RequiredImgAsset, ImgAsset, RequiredTextAssetConfiguration, RequiredTextAsset, TextAsset, SponsorshipCurrentYear ) from ..exceptions import ( @@ -74,7 +74,7 @@ def test_list_related_sponsorships(self): def test_name_for_display_without_specifying_package(self): benefit = baker.make(SponsorshipBenefit, name='Benefit') benefit_config = baker.make( - TieredQuantityConfiguration, + TieredBenefitConfiguration, package__name='Package', benefit=benefit, quantity=10 @@ -674,17 +674,17 @@ def test_new_copy_also_add_benefit_feature_when_creating_sponsor_benefit(self): def test_new_copy_do_not_save_unexisting_features(self): benefit_config = baker.make( - TieredQuantityConfiguration, + TieredBenefitConfiguration, package__name='Another package', benefit=self.sponsorship_benefit, ) - self.assertEqual(0, TieredQuantity.objects.count()) + self.assertEqual(0, TieredBenefit.objects.count()) sponsor_benefit = SponsorBenefit.new_copy( self.sponsorship_benefit, sponsorship=self.sponsorship ) - self.assertEqual(0, TieredQuantity.objects.count()) + self.assertEqual(0, TieredBenefit.objects.count()) self.assertFalse(sponsor_benefit.features.exists()) def test_sponsor_benefit_name_for_display(self): @@ -694,7 +694,7 @@ def test_sponsor_benefit_name_for_display(self): self.assertEqual(sponsor_benefit.name_for_display, name) # apply display modifier from features benefit_config = baker.make( - TieredQuantity, + TieredBenefit, sponsor_benefit=sponsor_benefit, quantity=10 ) @@ -972,12 +972,12 @@ def test_clone_configuration_for_new_sponsorship_benefit(self): self.assertEqual(new_cfg.pk, repeated.pk) -class TieredQuantityConfigurationModelTests(TestCase): +class TieredBenefitConfigurationModelTests(TestCase): def setUp(self): self.package = baker.make(SponsorshipPackage, year=2022) self.config = baker.make( - TieredQuantityConfiguration, + TieredBenefitConfiguration, package=self.package, quantity=10, ) @@ -987,7 +987,7 @@ def test_get_benefit_feature_respecting_configuration(self): benefit_feature = self.config.get_benefit_feature(sponsor_benefit=sponsor_benefit) - self.assertIsInstance(benefit_feature, TieredQuantity) + self.assertIsInstance(benefit_feature, TieredBenefit) self.assertEqual(benefit_feature.package, self.package) self.assertEqual(benefit_feature.quantity, self.config.quantity) @@ -1016,7 +1016,7 @@ def test_clone_tiered_quantity_configuration(self): new_cfg, created = self.config.clone(benefit) self.assertTrue(created) - self.assertEqual(2, TieredQuantityConfiguration.objects.count()) + self.assertEqual(2, TieredBenefitConfiguration.objects.count()) self.assertEqual(self.config.quantity, new_cfg.quantity) self.assertNotEqual(self.package, new_cfg.package) self.assertEqual(self.package.slug, new_cfg.package.slug) @@ -1036,10 +1036,10 @@ def test_display_modifier_does_not_change_the_name(self): self.assertEqual(placement.display_modifier(name), name) -class TieredQuantityTests(TestCase): +class TieredBenefitTests(TestCase): def test_display_modifier_adds_quantity_to_the_name(self): - placement = baker.make(TieredQuantity, quantity=10) + placement = baker.make(TieredBenefit, quantity=10) name = 'Benefit' self.assertEqual(placement.display_modifier(name), 'Benefit (10)') diff --git a/sponsors/tests/test_templatetags.py b/sponsors/tests/test_templatetags.py index 927cbdeee..cabbb4c37 100644 --- a/sponsors/tests/test_templatetags.py +++ b/sponsors/tests/test_templatetags.py @@ -8,7 +8,7 @@ Sponsor, SponsorBenefit, SponsorshipBenefit, - TieredQuantityConfiguration, + TieredBenefitConfiguration, ) from ..templatetags.sponsors import ( benefit_name_for_display, @@ -69,7 +69,7 @@ def setUp(self): self.benefit = baker.make(SponsorshipBenefit) self.package = baker.make("sponsors.SponsorshipPackage") self.config = baker.make( - TieredQuantityConfiguration, + TieredBenefitConfiguration, benefit=self.benefit, package=self.package, ) From 9234da30ee376c14fa99399c15455685e702c5c4 Mon Sep 17 00:00:00 2001 From: Bernardo Fontes Date: Wed, 10 Aug 2022 18:55:50 +0200 Subject: [PATCH 3/8] Add display label field to base tiered benefits abstract model --- .../migrations/0088_auto_20220810_1655.py | 23 +++++++++++++++++++ sponsors/models/benefits.py | 6 +++++ 2 files changed, 29 insertions(+) create mode 100644 sponsors/migrations/0088_auto_20220810_1655.py diff --git a/sponsors/migrations/0088_auto_20220810_1655.py b/sponsors/migrations/0088_auto_20220810_1655.py new file mode 100644 index 000000000..f0203331b --- /dev/null +++ b/sponsors/migrations/0088_auto_20220810_1655.py @@ -0,0 +1,23 @@ +# Generated by Django 2.2.24 on 2022-08-10 16:55 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('sponsors', '0087_auto_20220810_1647'), + ] + + operations = [ + migrations.AddField( + model_name='tieredbenefit', + name='display_label', + field=models.CharField(blank=True, default='', help_text='If populated, this will be displayed instead of the quantity value.', max_length=32), + ), + migrations.AddField( + model_name='tieredbenefitconfiguration', + name='display_label', + field=models.CharField(blank=True, default='', help_text='If populated, this will be displayed instead of the quantity value.', max_length=32), + ), + ] diff --git a/sponsors/models/benefits.py b/sponsors/models/benefits.py index 1f81069fb..fdac7ba0e 100644 --- a/sponsors/models/benefits.py +++ b/sponsors/models/benefits.py @@ -50,6 +50,12 @@ class Meta: class BaseTieredBenefit(models.Model): package = models.ForeignKey("sponsors.SponsorshipPackage", on_delete=models.CASCADE) quantity = models.PositiveIntegerField() + display_label = models.CharField( + blank=True, + default="", + help_text="If populated, this will be displayed instead of the quantity value.", + max_length=32, + ) class Meta: abstract = True From 5befc8e1540fa66af16b3f7c7883f8faf9b97ac3 Mon Sep 17 00:00:00 2001 From: Bernardo Fontes Date: Wed, 10 Aug 2022 19:03:44 +0200 Subject: [PATCH 4/8] Update template tag to prioritize tiered benefit label over quantity --- sponsors/templatetags/sponsors.py | 2 +- sponsors/tests/test_templatetags.py | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/sponsors/templatetags/sponsors.py b/sponsors/templatetags/sponsors.py index a9ad12791..3c412b8ff 100644 --- a/sponsors/templatetags/sponsors.py +++ b/sponsors/templatetags/sponsors.py @@ -65,7 +65,7 @@ def benefit_quantity_for_package(benefit, package): ).first() if quantity_configuration is None: return "" - return quantity_configuration.quantity + return quantity_configuration.display_label or quantity_configuration.quantity @register.simple_tag diff --git a/sponsors/tests/test_templatetags.py b/sponsors/tests/test_templatetags.py index cabbb4c37..f891a6479 100644 --- a/sponsors/tests/test_templatetags.py +++ b/sponsors/tests/test_templatetags.py @@ -75,8 +75,14 @@ def setUp(self): ) def test_return_config_quantity(self): - quantity = benefit_quantity_for_package(self.benefit.pk, self.package.pk) - self.assertEqual(quantity, self.config.quantity) + display = benefit_quantity_for_package(self.benefit.pk, self.package.pk) + self.assertEqual(display, self.config.quantity) + + def test_return_config_label_if_configured(self): + self.config.display_label = "Custom label" + self.config.save(update_fields=["display_label"]) + display = benefit_quantity_for_package(self.benefit.pk, self.package.pk) + self.assertEqual(display, self.config.display_label) def test_return_empty_string_if_mismatching_benefit_or_package(self): other_benefit = baker.make(SponsorshipBenefit) From e2ccf087af7f5e2512198d57358073c03f4f3191 Mon Sep 17 00:00:00 2001 From: Bernardo Fontes Date: Wed, 10 Aug 2022 19:11:26 +0200 Subject: [PATCH 5/8] Add assertions to make sure display label is correctly configured and cloned --- sponsors/tests/test_models.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sponsors/tests/test_models.py b/sponsors/tests/test_models.py index 4436ba85e..05a3574ea 100644 --- a/sponsors/tests/test_models.py +++ b/sponsors/tests/test_models.py @@ -979,6 +979,7 @@ def setUp(self): self.config = baker.make( TieredBenefitConfiguration, package=self.package, + display_label="Foo", quantity=10, ) @@ -990,6 +991,7 @@ def test_get_benefit_feature_respecting_configuration(self): self.assertIsInstance(benefit_feature, TieredBenefit) self.assertEqual(benefit_feature.package, self.package) self.assertEqual(benefit_feature.quantity, self.config.quantity) + self.assertEqual(benefit_feature.display_label, "Foo") def test_do_not_return_feature_if_benefit_from_other_package(self): sponsor_benefit = baker.make(SponsorBenefit, sponsorship__package__name='Other') @@ -1018,6 +1020,7 @@ def test_clone_tiered_quantity_configuration(self): self.assertTrue(created) self.assertEqual(2, TieredBenefitConfiguration.objects.count()) self.assertEqual(self.config.quantity, new_cfg.quantity) + self.assertEqual("Foo", new_cfg.display_label) self.assertNotEqual(self.package, new_cfg.package) self.assertEqual(self.package.slug, new_cfg.package.slug) self.assertEqual(2023, new_cfg.package.year) From f2872e094114aa1c065a6716c15abcfaf750ac7c Mon Sep 17 00:00:00 2001 From: Bernardo Fontes Date: Wed, 10 Aug 2022 19:14:47 +0200 Subject: [PATCH 6/8] Update display modifiers to prioritize label instead of quantity --- sponsors/models/benefits.py | 4 ++-- sponsors/tests/test_models.py | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/sponsors/models/benefits.py b/sponsors/models/benefits.py index fdac7ba0e..51ec1870e 100644 --- a/sponsors/models/benefits.py +++ b/sponsors/models/benefits.py @@ -424,7 +424,7 @@ def __str__(self): def display_modifier(self, name, **kwargs): if kwargs.get("package") != self.package: return name - return f"{name} ({self.quantity})" + return f"{name} ({self.display_label or self.quantity})" def get_clone_kwargs(self, new_benefit): kwargs = super().get_clone_kwargs(new_benefit) @@ -570,7 +570,7 @@ class Meta(BaseTieredBenefit.Meta, BenefitFeature.Meta): verbose_name_plural = "Tiered Benefits" def display_modifier(self, name, **kwargs): - return f"{name} ({self.quantity})" + return f"{name} ({self.display_label or self.quantity})" def __str__(self): return f"{self.quantity} of {self.sponsor_benefit} for {self.package}" diff --git a/sponsors/tests/test_models.py b/sponsors/tests/test_models.py index 05a3574ea..ac55ce7bc 100644 --- a/sponsors/tests/test_models.py +++ b/sponsors/tests/test_models.py @@ -1004,7 +1004,14 @@ def test_display_modifier_only_modifies_name_if_same_package(self): name = "Benefit" other_package = baker.make(SponsorshipPackage) + # modifies for the same package as the config + label prioritized + self.config.save(update_fields=["display_label"]) + modified_name = self.config.display_modifier(name, package=self.package) + self.assertEqual(modified_name, f"{name} (Foo)") + # modifies for the same package as the config + self.config.display_label = "" + self.config.save(update_fields=["display_label"]) modified_name = self.config.display_modifier(name, package=self.package) self.assertEqual(modified_name, f"{name} (10)") @@ -1046,6 +1053,11 @@ def test_display_modifier_adds_quantity_to_the_name(self): name = 'Benefit' self.assertEqual(placement.display_modifier(name), 'Benefit (10)') + def test_display_modifier_adds_display_label_to_the_name(self): + placement = baker.make(TieredBenefit, quantity=10, display_label="Foo") + name = 'Benefit' + self.assertEqual(placement.display_modifier(name), 'Benefit (Foo)') + class RequiredImgAssetConfigurationTests(TestCase): From 15c2f222ec65aac4e3b312fc8d9599f8b7207732 Mon Sep 17 00:00:00 2001 From: Ee Durbin Date: Thu, 11 Aug 2022 14:58:42 -0400 Subject: [PATCH 7/8] correct migrations --- sponsors/migrations/0086_auto_20220810_1635.py | 17 ----------------- sponsors/migrations/0087_auto_20220810_1647.py | 2 +- 2 files changed, 1 insertion(+), 18 deletions(-) delete mode 100644 sponsors/migrations/0086_auto_20220810_1635.py diff --git a/sponsors/migrations/0086_auto_20220810_1635.py b/sponsors/migrations/0086_auto_20220810_1635.py deleted file mode 100644 index 6ce364e6e..000000000 --- a/sponsors/migrations/0086_auto_20220810_1635.py +++ /dev/null @@ -1,17 +0,0 @@ -# Generated by Django 2.2.24 on 2022-08-10 16:35 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('sponsors', '0085_auto_20220730_0945'), - ] - - operations = [ - migrations.AlterModelOptions( - name='sponsorshippackage', - options={'ordering': ('-year', 'order')}, - ), - ] diff --git a/sponsors/migrations/0087_auto_20220810_1647.py b/sponsors/migrations/0087_auto_20220810_1647.py index 49080ba78..41043bf4f 100644 --- a/sponsors/migrations/0087_auto_20220810_1647.py +++ b/sponsors/migrations/0087_auto_20220810_1647.py @@ -7,7 +7,7 @@ class Migration(migrations.Migration): dependencies = [ ('contenttypes', '0002_remove_content_type_name'), - ('sponsors', '0086_auto_20220810_1635'), + ('sponsors', '0086_auto_20220809_1655'), ] operations = [ From 5e6a5cf8e3d82b2aa20dbd2632083a276898fe99 Mon Sep 17 00:00:00 2001 From: Bernardo Fontes Date: Fri, 12 Aug 2022 14:53:39 +0200 Subject: [PATCH 8/8] Update fixture file to match table new name --- fixtures/sponsors.json | 184 ++++++++++++++++++++--------------------- 1 file changed, 92 insertions(+), 92 deletions(-) diff --git a/fixtures/sponsors.json b/fixtures/sponsors.json index 6cdc1ff29..ae5146275 100644 --- a/fixtures/sponsors.json +++ b/fixtures/sponsors.json @@ -1239,7 +1239,7 @@ "fields": { "polymorphic_ctype": [ "sponsors", - "tieredquantityconfiguration" + "tieredbenefitconfiguration" ], "benefit": 62 } @@ -1250,7 +1250,7 @@ "fields": { "polymorphic_ctype": [ "sponsors", - "tieredquantityconfiguration" + "tieredbenefitconfiguration" ], "benefit": 62 } @@ -1261,7 +1261,7 @@ "fields": { "polymorphic_ctype": [ "sponsors", - "tieredquantityconfiguration" + "tieredbenefitconfiguration" ], "benefit": 62 } @@ -1272,7 +1272,7 @@ "fields": { "polymorphic_ctype": [ "sponsors", - "tieredquantityconfiguration" + "tieredbenefitconfiguration" ], "benefit": 64 } @@ -1283,7 +1283,7 @@ "fields": { "polymorphic_ctype": [ "sponsors", - "tieredquantityconfiguration" + "tieredbenefitconfiguration" ], "benefit": 64 } @@ -1294,7 +1294,7 @@ "fields": { "polymorphic_ctype": [ "sponsors", - "tieredquantityconfiguration" + "tieredbenefitconfiguration" ], "benefit": 64 } @@ -1305,7 +1305,7 @@ "fields": { "polymorphic_ctype": [ "sponsors", - "tieredquantityconfiguration" + "tieredbenefitconfiguration" ], "benefit": 64 } @@ -1316,7 +1316,7 @@ "fields": { "polymorphic_ctype": [ "sponsors", - "tieredquantityconfiguration" + "tieredbenefitconfiguration" ], "benefit": 64 } @@ -1327,7 +1327,7 @@ "fields": { "polymorphic_ctype": [ "sponsors", - "tieredquantityconfiguration" + "tieredbenefitconfiguration" ], "benefit": 64 } @@ -1338,7 +1338,7 @@ "fields": { "polymorphic_ctype": [ "sponsors", - "tieredquantityconfiguration" + "tieredbenefitconfiguration" ], "benefit": 64 } @@ -1349,7 +1349,7 @@ "fields": { "polymorphic_ctype": [ "sponsors", - "tieredquantityconfiguration" + "tieredbenefitconfiguration" ], "benefit": 64 } @@ -1360,7 +1360,7 @@ "fields": { "polymorphic_ctype": [ "sponsors", - "tieredquantityconfiguration" + "tieredbenefitconfiguration" ], "benefit": 65 } @@ -1371,7 +1371,7 @@ "fields": { "polymorphic_ctype": [ "sponsors", - "tieredquantityconfiguration" + "tieredbenefitconfiguration" ], "benefit": 65 } @@ -1382,7 +1382,7 @@ "fields": { "polymorphic_ctype": [ "sponsors", - "tieredquantityconfiguration" + "tieredbenefitconfiguration" ], "benefit": 65 } @@ -1393,7 +1393,7 @@ "fields": { "polymorphic_ctype": [ "sponsors", - "tieredquantityconfiguration" + "tieredbenefitconfiguration" ], "benefit": 65 } @@ -1404,7 +1404,7 @@ "fields": { "polymorphic_ctype": [ "sponsors", - "tieredquantityconfiguration" + "tieredbenefitconfiguration" ], "benefit": 65 } @@ -1415,7 +1415,7 @@ "fields": { "polymorphic_ctype": [ "sponsors", - "tieredquantityconfiguration" + "tieredbenefitconfiguration" ], "benefit": 65 } @@ -1426,7 +1426,7 @@ "fields": { "polymorphic_ctype": [ "sponsors", - "tieredquantityconfiguration" + "tieredbenefitconfiguration" ], "benefit": 75 } @@ -1437,7 +1437,7 @@ "fields": { "polymorphic_ctype": [ "sponsors", - "tieredquantityconfiguration" + "tieredbenefitconfiguration" ], "benefit": 75 } @@ -1448,7 +1448,7 @@ "fields": { "polymorphic_ctype": [ "sponsors", - "tieredquantityconfiguration" + "tieredbenefitconfiguration" ], "benefit": 75 } @@ -1459,7 +1459,7 @@ "fields": { "polymorphic_ctype": [ "sponsors", - "tieredquantityconfiguration" + "tieredbenefitconfiguration" ], "benefit": 75 } @@ -1470,7 +1470,7 @@ "fields": { "polymorphic_ctype": [ "sponsors", - "tieredquantityconfiguration" + "tieredbenefitconfiguration" ], "benefit": 75 } @@ -1481,7 +1481,7 @@ "fields": { "polymorphic_ctype": [ "sponsors", - "tieredquantityconfiguration" + "tieredbenefitconfiguration" ], "benefit": 75 } @@ -1492,7 +1492,7 @@ "fields": { "polymorphic_ctype": [ "sponsors", - "tieredquantityconfiguration" + "tieredbenefitconfiguration" ], "benefit": 75 } @@ -1580,7 +1580,7 @@ "fields": { "polymorphic_ctype": [ "sponsors", - "tieredquantityconfiguration" + "tieredbenefitconfiguration" ], "benefit": 24 } @@ -1591,7 +1591,7 @@ "fields": { "polymorphic_ctype": [ "sponsors", - "tieredquantityconfiguration" + "tieredbenefitconfiguration" ], "benefit": 24 } @@ -1602,7 +1602,7 @@ "fields": { "polymorphic_ctype": [ "sponsors", - "tieredquantityconfiguration" + "tieredbenefitconfiguration" ], "benefit": 24 } @@ -1624,7 +1624,7 @@ "fields": { "polymorphic_ctype": [ "sponsors", - "tieredquantityconfiguration" + "tieredbenefitconfiguration" ], "benefit": 73 } @@ -1635,7 +1635,7 @@ "fields": { "polymorphic_ctype": [ "sponsors", - "tieredquantityconfiguration" + "tieredbenefitconfiguration" ], "benefit": 73 } @@ -1646,7 +1646,7 @@ "fields": { "polymorphic_ctype": [ "sponsors", - "tieredquantityconfiguration" + "tieredbenefitconfiguration" ], "benefit": 73 } @@ -1657,7 +1657,7 @@ "fields": { "polymorphic_ctype": [ "sponsors", - "tieredquantityconfiguration" + "tieredbenefitconfiguration" ], "benefit": 73 } @@ -1668,7 +1668,7 @@ "fields": { "polymorphic_ctype": [ "sponsors", - "tieredquantityconfiguration" + "tieredbenefitconfiguration" ], "benefit": 73 } @@ -1679,7 +1679,7 @@ "fields": { "polymorphic_ctype": [ "sponsors", - "tieredquantityconfiguration" + "tieredbenefitconfiguration" ], "benefit": 73 } @@ -1690,7 +1690,7 @@ "fields": { "polymorphic_ctype": [ "sponsors", - "tieredquantityconfiguration" + "tieredbenefitconfiguration" ], "benefit": 77 } @@ -1701,7 +1701,7 @@ "fields": { "polymorphic_ctype": [ "sponsors", - "tieredquantityconfiguration" + "tieredbenefitconfiguration" ], "benefit": 77 } @@ -1712,7 +1712,7 @@ "fields": { "polymorphic_ctype": [ "sponsors", - "tieredquantityconfiguration" + "tieredbenefitconfiguration" ], "benefit": 77 } @@ -1723,7 +1723,7 @@ "fields": { "polymorphic_ctype": [ "sponsors", - "tieredquantityconfiguration" + "tieredbenefitconfiguration" ], "benefit": 77 } @@ -1734,7 +1734,7 @@ "fields": { "polymorphic_ctype": [ "sponsors", - "tieredquantityconfiguration" + "tieredbenefitconfiguration" ], "benefit": 77 } @@ -1745,7 +1745,7 @@ "fields": { "polymorphic_ctype": [ "sponsors", - "tieredquantityconfiguration" + "tieredbenefitconfiguration" ], "benefit": 77 } @@ -1756,7 +1756,7 @@ "fields": { "polymorphic_ctype": [ "sponsors", - "tieredquantityconfiguration" + "tieredbenefitconfiguration" ], "benefit": 77 } @@ -1943,7 +1943,7 @@ "fields": { "polymorphic_ctype": [ "sponsors", - "tieredquantityconfiguration" + "tieredbenefitconfiguration" ], "benefit": 64 } @@ -1954,7 +1954,7 @@ "fields": { "polymorphic_ctype": [ "sponsors", - "tieredquantityconfiguration" + "tieredbenefitconfiguration" ], "benefit": 65 } @@ -1998,7 +1998,7 @@ "fields": { "polymorphic_ctype": [ "sponsors", - "tieredquantityconfiguration" + "tieredbenefitconfiguration" ], "benefit": 64 } @@ -2009,7 +2009,7 @@ "fields": { "polymorphic_ctype": [ "sponsors", - "tieredquantityconfiguration" + "tieredbenefitconfiguration" ], "benefit": 65 } @@ -2020,7 +2020,7 @@ "fields": { "polymorphic_ctype": [ "sponsors", - "tieredquantityconfiguration" + "tieredbenefitconfiguration" ], "benefit": 77 } @@ -2031,7 +2031,7 @@ "fields": { "polymorphic_ctype": [ "sponsors", - "tieredquantityconfiguration" + "tieredbenefitconfiguration" ], "benefit": 77 } @@ -2152,7 +2152,7 @@ } }, { - "model": "sponsors.tieredquantityconfiguration", + "model": "sponsors.tieredbenefitconfiguration", "pk": 26, "fields": { "package": 1, @@ -2160,7 +2160,7 @@ } }, { - "model": "sponsors.tieredquantityconfiguration", + "model": "sponsors.tieredbenefitconfiguration", "pk": 27, "fields": { "package": 2, @@ -2168,7 +2168,7 @@ } }, { - "model": "sponsors.tieredquantityconfiguration", + "model": "sponsors.tieredbenefitconfiguration", "pk": 28, "fields": { "package": 3, @@ -2176,7 +2176,7 @@ } }, { - "model": "sponsors.tieredquantityconfiguration", + "model": "sponsors.tieredbenefitconfiguration", "pk": 29, "fields": { "package": 1, @@ -2184,7 +2184,7 @@ } }, { - "model": "sponsors.tieredquantityconfiguration", + "model": "sponsors.tieredbenefitconfiguration", "pk": 30, "fields": { "package": 2, @@ -2192,7 +2192,7 @@ } }, { - "model": "sponsors.tieredquantityconfiguration", + "model": "sponsors.tieredbenefitconfiguration", "pk": 31, "fields": { "package": 3, @@ -2200,7 +2200,7 @@ } }, { - "model": "sponsors.tieredquantityconfiguration", + "model": "sponsors.tieredbenefitconfiguration", "pk": 32, "fields": { "package": 4, @@ -2208,7 +2208,7 @@ } }, { - "model": "sponsors.tieredquantityconfiguration", + "model": "sponsors.tieredbenefitconfiguration", "pk": 33, "fields": { "package": 5, @@ -2216,7 +2216,7 @@ } }, { - "model": "sponsors.tieredquantityconfiguration", + "model": "sponsors.tieredbenefitconfiguration", "pk": 34, "fields": { "package": 6, @@ -2224,7 +2224,7 @@ } }, { - "model": "sponsors.tieredquantityconfiguration", + "model": "sponsors.tieredbenefitconfiguration", "pk": 35, "fields": { "package": 7, @@ -2232,7 +2232,7 @@ } }, { - "model": "sponsors.tieredquantityconfiguration", + "model": "sponsors.tieredbenefitconfiguration", "pk": 36, "fields": { "package": 8, @@ -2240,7 +2240,7 @@ } }, { - "model": "sponsors.tieredquantityconfiguration", + "model": "sponsors.tieredbenefitconfiguration", "pk": 37, "fields": { "package": 1, @@ -2248,7 +2248,7 @@ } }, { - "model": "sponsors.tieredquantityconfiguration", + "model": "sponsors.tieredbenefitconfiguration", "pk": 38, "fields": { "package": 2, @@ -2256,7 +2256,7 @@ } }, { - "model": "sponsors.tieredquantityconfiguration", + "model": "sponsors.tieredbenefitconfiguration", "pk": 39, "fields": { "package": 3, @@ -2264,7 +2264,7 @@ } }, { - "model": "sponsors.tieredquantityconfiguration", + "model": "sponsors.tieredbenefitconfiguration", "pk": 40, "fields": { "package": 4, @@ -2272,7 +2272,7 @@ } }, { - "model": "sponsors.tieredquantityconfiguration", + "model": "sponsors.tieredbenefitconfiguration", "pk": 41, "fields": { "package": 5, @@ -2280,7 +2280,7 @@ } }, { - "model": "sponsors.tieredquantityconfiguration", + "model": "sponsors.tieredbenefitconfiguration", "pk": 42, "fields": { "package": 6, @@ -2288,7 +2288,7 @@ } }, { - "model": "sponsors.tieredquantityconfiguration", + "model": "sponsors.tieredbenefitconfiguration", "pk": 43, "fields": { "package": 1, @@ -2296,7 +2296,7 @@ } }, { - "model": "sponsors.tieredquantityconfiguration", + "model": "sponsors.tieredbenefitconfiguration", "pk": 44, "fields": { "package": 2, @@ -2304,7 +2304,7 @@ } }, { - "model": "sponsors.tieredquantityconfiguration", + "model": "sponsors.tieredbenefitconfiguration", "pk": 45, "fields": { "package": 3, @@ -2312,7 +2312,7 @@ } }, { - "model": "sponsors.tieredquantityconfiguration", + "model": "sponsors.tieredbenefitconfiguration", "pk": 46, "fields": { "package": 4, @@ -2320,7 +2320,7 @@ } }, { - "model": "sponsors.tieredquantityconfiguration", + "model": "sponsors.tieredbenefitconfiguration", "pk": 47, "fields": { "package": 5, @@ -2328,7 +2328,7 @@ } }, { - "model": "sponsors.tieredquantityconfiguration", + "model": "sponsors.tieredbenefitconfiguration", "pk": 48, "fields": { "package": 6, @@ -2336,7 +2336,7 @@ } }, { - "model": "sponsors.tieredquantityconfiguration", + "model": "sponsors.tieredbenefitconfiguration", "pk": 49, "fields": { "package": 7, @@ -2344,7 +2344,7 @@ } }, { - "model": "sponsors.tieredquantityconfiguration", + "model": "sponsors.tieredbenefitconfiguration", "pk": 89, "fields": { "package": 1, @@ -2352,7 +2352,7 @@ } }, { - "model": "sponsors.tieredquantityconfiguration", + "model": "sponsors.tieredbenefitconfiguration", "pk": 90, "fields": { "package": 2, @@ -2360,7 +2360,7 @@ } }, { - "model": "sponsors.tieredquantityconfiguration", + "model": "sponsors.tieredbenefitconfiguration", "pk": 91, "fields": { "package": 3, @@ -2368,7 +2368,7 @@ } }, { - "model": "sponsors.tieredquantityconfiguration", + "model": "sponsors.tieredbenefitconfiguration", "pk": 93, "fields": { "package": 1, @@ -2376,7 +2376,7 @@ } }, { - "model": "sponsors.tieredquantityconfiguration", + "model": "sponsors.tieredbenefitconfiguration", "pk": 94, "fields": { "package": 2, @@ -2384,7 +2384,7 @@ } }, { - "model": "sponsors.tieredquantityconfiguration", + "model": "sponsors.tieredbenefitconfiguration", "pk": 95, "fields": { "package": 3, @@ -2392,7 +2392,7 @@ } }, { - "model": "sponsors.tieredquantityconfiguration", + "model": "sponsors.tieredbenefitconfiguration", "pk": 96, "fields": { "package": 4, @@ -2400,7 +2400,7 @@ } }, { - "model": "sponsors.tieredquantityconfiguration", + "model": "sponsors.tieredbenefitconfiguration", "pk": 97, "fields": { "package": 5, @@ -2408,7 +2408,7 @@ } }, { - "model": "sponsors.tieredquantityconfiguration", + "model": "sponsors.tieredbenefitconfiguration", "pk": 98, "fields": { "package": 6, @@ -2416,7 +2416,7 @@ } }, { - "model": "sponsors.tieredquantityconfiguration", + "model": "sponsors.tieredbenefitconfiguration", "pk": 99, "fields": { "package": 1, @@ -2424,7 +2424,7 @@ } }, { - "model": "sponsors.tieredquantityconfiguration", + "model": "sponsors.tieredbenefitconfiguration", "pk": 100, "fields": { "package": 2, @@ -2432,7 +2432,7 @@ } }, { - "model": "sponsors.tieredquantityconfiguration", + "model": "sponsors.tieredbenefitconfiguration", "pk": 101, "fields": { "package": 3, @@ -2440,7 +2440,7 @@ } }, { - "model": "sponsors.tieredquantityconfiguration", + "model": "sponsors.tieredbenefitconfiguration", "pk": 102, "fields": { "package": 4, @@ -2448,7 +2448,7 @@ } }, { - "model": "sponsors.tieredquantityconfiguration", + "model": "sponsors.tieredbenefitconfiguration", "pk": 103, "fields": { "package": 5, @@ -2456,7 +2456,7 @@ } }, { - "model": "sponsors.tieredquantityconfiguration", + "model": "sponsors.tieredbenefitconfiguration", "pk": 104, "fields": { "package": 6, @@ -2464,7 +2464,7 @@ } }, { - "model": "sponsors.tieredquantityconfiguration", + "model": "sponsors.tieredbenefitconfiguration", "pk": 105, "fields": { "package": 7, @@ -2472,7 +2472,7 @@ } }, { - "model": "sponsors.tieredquantityconfiguration", + "model": "sponsors.tieredbenefitconfiguration", "pk": 122, "fields": { "package": 9, @@ -2480,7 +2480,7 @@ } }, { - "model": "sponsors.tieredquantityconfiguration", + "model": "sponsors.tieredbenefitconfiguration", "pk": 123, "fields": { "package": 9, @@ -2488,7 +2488,7 @@ } }, { - "model": "sponsors.tieredquantityconfiguration", + "model": "sponsors.tieredbenefitconfiguration", "pk": 128, "fields": { "package": 11, @@ -2496,7 +2496,7 @@ } }, { - "model": "sponsors.tieredquantityconfiguration", + "model": "sponsors.tieredbenefitconfiguration", "pk": 129, "fields": { "package": 11, @@ -2504,7 +2504,7 @@ } }, { - "model": "sponsors.tieredquantityconfiguration", + "model": "sponsors.tieredbenefitconfiguration", "pk": 130, "fields": { "package": 9, @@ -2512,7 +2512,7 @@ } }, { - "model": "sponsors.tieredquantityconfiguration", + "model": "sponsors.tieredbenefitconfiguration", "pk": 131, "fields": { "package": 11,