diff --git a/.env.sample b/.env.sample index 9bdaa98e05..a6c295beaf 100644 --- a/.env.sample +++ b/.env.sample @@ -3,7 +3,7 @@ DJANGO_SUPERUSER_EMAIL=benefits-admin@calitp.org DJANGO_SUPERUSER_PASSWORD=superuser12345! DJANGO_DB_RESET=true -DJANGO_DB_DIR=. +DJANGO_STORAGE_DIR=. DJANGO_DB_FILE=django.db DJANGO_DB_FIXTURES="benefits/core/migrations/local_fixtures.json" diff --git a/appcontainer/nginx.conf b/appcontainer/nginx.conf index b0fe492bdb..244598c39e 100644 --- a/appcontainer/nginx.conf +++ b/appcontainer/nginx.conf @@ -72,6 +72,13 @@ http { add_header Cache-Control public; } + # path for uploaded files + location /media/ { + alias /home/calitp/app/data/uploads/; + expires 1y; + add_header Cache-Control public; + } + location / { # checks for static file, if not found proxy to app try_files $uri @proxy_to_app; diff --git a/benefits/core/context_processors.py b/benefits/core/context_processors.py index 9ec635b21f..a0235dc18a 100644 --- a/benefits/core/context_processors.py +++ b/benefits/core/context_processors.py @@ -15,7 +15,7 @@ def unique_values(original_list): def _agency_context(agency: models.TransitAgency): - return { + agency_context = { "eligibility_index_url": agency.eligibility_index_url, "help_templates": unique_values([f.help_template for f in agency.enrollment_flows.all() if f.help_template]), "info_url": agency.info_url, @@ -25,6 +25,16 @@ def _agency_context(agency: models.TransitAgency): "slug": agency.slug, } + if agency.logo_large and agency.logo_small: + agency_context.update( + { + "logo_small_url": agency.logo_small.url, + "logo_large_url": agency.logo_large.url, + } + ) + + return agency_context + def agency(request): """Context processor adds some information about the active agency to the request context.""" diff --git a/benefits/core/migrations/0031_transitagency_logo.py b/benefits/core/migrations/0031_transitagency_logo.py new file mode 100644 index 0000000000..365610c752 --- /dev/null +++ b/benefits/core/migrations/0031_transitagency_logo.py @@ -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, + ), + ), + ] diff --git a/benefits/core/migrations/local_fixtures.json b/benefits/core/migrations/local_fixtures.json index 19a7a3984a..c17d4fc43a 100644 --- a/benefits/core/migrations/local_fixtures.json +++ b/benefits/core/migrations/local_fixtures.json @@ -69,7 +69,9 @@ "transit_processor_client_id": "", "transit_processor_client_secret_name": "cst-transit-processor-client-secret", "staff_group": 2, - "customer_service_group": 2 + "customer_service_group": 2, + "logo_large": "agencies/cst-lg.png", + "logo_small": "agencies/cst-sm.png" } }, { diff --git a/benefits/core/models.py b/benefits/core/models.py index 3b8b930797..86e63b6a18 100644 --- a/benefits/core/models.py +++ b/benefits/core/models.py @@ -5,6 +5,7 @@ from functools import cached_property import importlib import logging +import os import uuid from django.conf import settings @@ -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.""" @@ -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 diff --git a/benefits/core/templates/core/includes/modal--agency-selector.html b/benefits/core/templates/core/includes/modal--agency-selector.html index 9b1f9ff2f5..57389097ba 100644 --- a/benefits/core/templates/core/includes/modal--agency-selector.html +++ b/benefits/core/templates/core/includes/modal--agency-selector.html @@ -12,12 +12,12 @@