Skip to content
This repository has been archived by the owner on Aug 16, 2024. It is now read-only.

Commit

Permalink
Add a priority for sponsor tier ordering (#95)
Browse files Browse the repository at this point in the history
* Allow flexibility in Python minor version

* Add a priority field to sponsorship tiers, and order by the inverse
  • Loading branch information
AetherUnbound authored Mar 6, 2024
1 parent 2758a2d commit 03878f8
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 11 deletions.
11 changes: 7 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ license = "MIT"
# usually defined in the runtime.txt.
# NOTE: THIS MUST BE PINNED! If you change it here, also change it in
# the GitHub actions, the Dockerfile, and the Heroku config
python = "3.10.4"
python = "^3.10.4"
# we don't really care too much about the boto3 version
# but boto3's version constraints make dependency resolution
# take tens of minutes. Update the boto3 pin to the latest version
Expand Down
21 changes: 21 additions & 0 deletions sponsors/migrations/0005_sponsortier_priority.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 5.0.2 on 2024-03-06 19:10

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("sponsors", "0004_auto_20210114_0411"),
]

operations = [
migrations.AddField(
model_name="sponsortier",
name="priority",
field=models.PositiveSmallIntegerField(
default=0,
help_text="Sorting order on the page (higher number means higher up)",
),
),
]
5 changes: 5 additions & 0 deletions sponsors/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,16 @@ class SponsorTier(models.Model):
name = models.CharField(max_length=255)
slug = models.SlugField(max_length=255, blank=True)
type = models.CharField(max_length=255, choices=TYPE_CHOICES)
priority = models.PositiveSmallIntegerField(
default=0,
help_text="Sorting order on the page (higher number means higher up)",
)

panels = [
FieldPanel("name"),
FieldPanel("slug"),
FieldPanel("type"),
FieldPanel("priority"),
]

def __str__(self):
Expand Down
16 changes: 10 additions & 6 deletions sponsors/templatetags/sponsor_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,20 @@ def non_profit_sponsors():

@register.simple_tag
def corporate_tiers():
return SponsorTier.objects.filter(
sponsors__isnull=False, type=SponsorTier.CORPORATE
).distinct()
return (
SponsorTier.objects.filter(sponsors__isnull=False, type=SponsorTier.CORPORATE)
.order_by("-priority")
.distinct()
)


@register.simple_tag
def npo_tiers():
return SponsorTier.objects.filter(
sponsors__isnull=False, type=SponsorTier.NPO
).distinct()
return (
SponsorTier.objects.filter(sponsors__isnull=False, type=SponsorTier.NPO)
.order_by("-priority")
.distinct()
)


@register.inclusion_tag("sponsors/sponsor_logos_smol.html")
Expand Down

0 comments on commit 03878f8

Please sign in to comment.