8000 Add display label to Tiered Benefits by berinhard · Pull Request #2115 · python/pythondotorg · GitHub
[go: up one dir, main page]

Skip to content

Add display label to Tiered Benefits #2115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Aug 12, 2022
Prev Previous commit
Next Next commit
Update display modifiers to prioritize label instead of quantity
  • Loading branch information
berinhard authored and ewdurbin committed Aug 11, 2022
commit f2872e094114aa1c065a6716c15abcfaf750ac7c
4 changes: 2 additions & 2 deletions sponsors/models/benefits.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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}"
Expand Down
12 changes: 12 additions & 0 deletions sponsors/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)")

Expand Down Expand Up @@ -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):

Expand Down
0