Skip to content

Commit

Permalink
feat: add a property for a small and large agency logo
Browse files Browse the repository at this point in the history
  • Loading branch information
lalver1 committed Nov 14, 2024
1 parent af10ab1 commit 6f4337f
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 1 deletion.
36 changes: 36 additions & 0 deletions benefits/core/migrations/0031_transitagency_logo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Generated by Django 5.1.2 on 2024-11-14 18:05

import benefits.core.models
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("core", "0030_enrollmentevent_extra_claims"),
]

operations = [
migrations.AddField(
model_name="transitagency",
name="logo_large",
field=models.ImageField(
blank=True,
default=None,
help_text="The large version of the transit agency's logo.",
null=True,
upload_to=benefits.core.models.agency_logo_large,
),
),
migrations.AddField(
model_name="transitagency",
name="logo_small",
field=models.ImageField(
blank=True,
default=None,
help_text="The small version of the transit agency's logo.",
null=True,
upload_to=benefits.core.models.agency_logo_small,
),
),
]
28 changes: 28 additions & 0 deletions benefits/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from functools import cached_property
import importlib
import logging
import os
import uuid

from django.conf import settings
Expand Down Expand Up @@ -126,6 +127,19 @@ def __str__(self):
return self.name


def _agency_logo(instance, filename, size):
base, ext = os.path.splitext(filename)
return f"agencies/{instance.slug}-{size}" + ext


def agency_logo_small(instance, filename):
return _agency_logo(instance, filename, "sm")


def agency_logo_large(instance, filename):
return _agency_logo(instance, filename, "lg")


class TransitAgency(models.Model):
"""An agency offering transit service."""

Expand Down Expand Up @@ -191,6 +205,20 @@ class TransitAgency(models.Model):
help_text="The group of users who are allowed to do in-person eligibility verification and enrollment.",
related_name="+",
)
logo_large = models.ImageField(
default=None,
null=True,
blank=True,
upload_to=agency_logo_large,
help_text="The large version of the transit agency's logo.",
)
logo_small = models.ImageField(
default=None,
null=True,
blank=True,
upload_to=agency_logo_small,
help_text="The small version of the transit agency's logo.",
)

def __str__(self):
return self.long_name
Expand Down
22 changes: 21 additions & 1 deletion tests/pytest/core/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@

import pytest

from benefits.core.models import SecretNameField, EnrollmentFlow, TransitAgency, EnrollmentEvent, EnrollmentMethods
from benefits.core.models import (
SecretNameField,
EnrollmentFlow,
TransitAgency,
EnrollmentEvent,
EnrollmentMethods,
agency_logo_small,
agency_logo_large,
)
import benefits.secrets


Expand Down Expand Up @@ -413,6 +421,18 @@ def test_TransitAgency_for_user_in_group_not_linked_to_any_agency():
assert TransitAgency.for_user(user) is None


@pytest.mark.django_db
def test_agency_logo_small(model_TransitAgency):

assert agency_logo_small(model_TransitAgency, "local_filename.png") == "agencies/test-sm.png"


@pytest.mark.django_db
def test_agency_logo_large(model_TransitAgency):

assert agency_logo_large(model_TransitAgency, "local_filename.png") == "agencies/test-lg.png"


@pytest.mark.django_db
def test_EnrollmentEvent_create(model_TransitAgency, model_EnrollmentFlow):
ts = timezone.now()
Expand Down

0 comments on commit 6f4337f

Please sign in to comment.