Skip to content

Commit c644d84

Browse files
committed
Story 2269: Enable Conditional S3 Storage for development
1 parent 4c539f8 commit c644d84

4 files changed

Lines changed: 39 additions & 0 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,3 +208,6 @@ test-logs.txt
208208
smoke-logs.txt
209209
extract_links.py.py
210210
extract_links.py
211+
212+
# Large static images
213+
static/static-large/*

core/templatetags/custom_static.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from django import template
2+
from django.conf import settings
3+
4+
register = template.Library()
5+
6+
7+
@register.simple_tag
8+
def large_static(file_path: str):
9+
# Strip any leading slashes to avoid footguns
10+
file_path = file_path.lstrip("/")
11+
if settings.LOCAL_DEVELOPMENT:
12+
return f"{settings.STATIC_URL}static-large/{file_path}"
13+
else:
14+
return f"{settings.STATIC_CONTENT_AWS_S3_ENDPOINT_URL}/{settings.STATIC_CONTENT_BUCKET_NAME}/static/{file_path}"

justfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ set dotenv-load := false
22
COMPOSE_FILE := "docker-compose.yml"
33
ENV_FILE := ".env"
44
DJANGO_VERSION := "5.2"
5+
VALID_BUCKETS := "boost.org.v2 stage.boost.org.v2 boost.org-cppal-dev-v2"
6+
57

68
@_default:
79
just --list
@@ -180,3 +182,12 @@ alias shell := console
180182

181183
@manage +args:
182184
docker compose run --rm web python manage.py {{ args }}
185+
186+
# Static File Management
187+
@down_sync_images BUCKET='stage.boost.org.v2': ## syncs all items from specified bucket to static/static-large for local development
188+
if echo {{VALID_BUCKETS}} | grep -q -w '{{BUCKET}}'; then \
189+
aws s3 sync s3://{{BUCKET}}/static/ static/static-large/; \
190+
echo "All missing or outdated static items synced."; \
191+
else \
192+
echo "Bucket name invalid."; \
193+
fi

templates/v3/examples/_v3_example_section.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,17 @@ <h3>{{ section_title }}</h3>
721721
</div>
722722
{% endwith %}
723723

724+
{% with section_title="Image Handling Example" %}
725+
{% load custom_static %}
726+
<div class="v3-examples-section__block" id="{{ section_title|slugify }}">
727+
<h3>{{ section_title }}</h3>
728+
<div class="v3-examples-section__example-box">
729+
{% large_static '/img/v3/learn-page/Learn_Octopus.png' as img_url %}
730+
<img src="{{img_url}}" />
731+
</div>
732+
</div>
733+
{% endwith %}
734+
724735
{% comment %}
725736
Position Fixed dark mode toggle for quick theme switching without scrolling to the header.
726737
{% endcomment %}

0 commit comments

Comments
 (0)