Skip to content

Commit 77dff45

Browse files
committed
allow white logos for pypi footer
1 parent c84ea20 commit 77dff45

File tree

6 files changed

+62
-0
lines changed

6 files changed

+62
-0
lines changed

apps/sponsors/admin.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,7 @@ class SponsorshipAdmin(ImportExportActionModelAdmin, admin.ModelAdmin):
559559
"get_sponsor_description",
560560
"get_sponsor_landing_page_url",
561561
"get_sponsor_web_logo",
562+
"get_sponsor_white_logo",
562563
"get_sponsor_print_logo",
563564
"get_sponsor_primary_phone",
564565
"get_sponsor_mailing_address",
@@ -630,6 +631,7 @@ def get_readonly_fields(self, request, obj):
630631
"get_sponsor_description",
631632
"get_sponsor_landing_page_url",
632633
"get_sponsor_web_logo",
634+
"get_sponsor_white_logo",
633635
"get_sponsor_print_logo",
634636
"get_sponsor_primary_phone",
635637
"get_sponsor_mailing_address",
@@ -749,6 +751,22 @@ def get_sponsor_web_logo(self, obj):
749751
context = Context({"img": img})
750752
return mark_safe(template.render(context)) # noqa: S308
751753

754+
@admin.display(description="White Logo")
755+
def get_sponsor_white_logo(self, obj):
756+
"""Render and return the sponsor's white logo as a thumbnail image."""
757+
img = obj.sponsor.white_logo
758+
if not img:
759+
return "---"
760+
if img.name and img.name.lower().endswith(".svg"):
761+
return format_html(
762+
'<img src="{}" style="max-width:150px;max-height:150px;background:#333"/>',
763+
img.url,
764+
)
765+
html = "{% load thumbnail %}{% thumbnail img '150x150' format='PNG' quality=100 as im %}<img src='{{ im.url}}' style='background:#333'/>{% endthumbnail %}"
766+
template = Template(html)
767+
context = Context({"img": img})
768+
return mark_safe(template.render(context)) # noqa: S308
769+
752770
@admin.display(description="Print Logo")
753771
def get_sponsor_print_logo(self, obj):
754772
"""Render and return the sponsor's print logo as a thumbnail image."""

apps/sponsors/api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def get(self, request, *args, **kwargs):
5353
"level_order": sponsorship.package.order,
5454
"description": sponsor.description,
5555
"logo": sponsor.web_logo.url,
56+
"white_logo": sponsor.white_logo.url if sponsor.white_logo else None,
5657
"sponsor_url": sponsor.landing_page_url,
5758
"start_date": sponsorship.start_date,
5859
"end_date": sponsorship.end_date,

apps/sponsors/forms.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,11 @@ class SponsorshipApplicationForm(forms.Form):
229229
help_text="For display on our sponsor webpage. High resolution PNG or JPG, smallest dimension no less than 256px",
230230
required=False,
231231
)
232+
white_logo = forms.ImageField(
233+
label="Sponsor white logo",
234+
help_text="For display on dark backgrounds (e.g. PyPI footer). Transparent PNG, smallest dimension no less than 256px",
235+
required=False,
236+
)
232237
print_logo = forms.FileField(
233238
label="Sponsor print logo",
234239
help_text="For printed materials, signage, and projection. SVG or EPS",
@@ -396,6 +401,7 @@ def save(self):
396401
landing_page_url=self.cleaned_data.get("landing_page_url", ""),
397402
twitter_handle=self.cleaned_data["twitter_handle"],
398403
linked_in_page_url=self.cleaned_data["linked_in_page_url"],
404+
white_logo=self.cleaned_data.get("white_logo"),
399405
print_logo=self.cleaned_data.get("print_logo"),
400406
country_of_incorporation=self.cleaned_data.get("country_of_incorporation", ""),
401407
state_of_incorporation=self.cleaned_data.get("state_of_incorporation", ""),
@@ -606,6 +612,11 @@ class SponsorUpdateForm(forms.ModelForm):
606612
help_text="For display on our sponsor webpage. High resolution PNG or JPG, smallest dimension no less than 256px",
607613
required=False,
608614
)
615+
white_logo = forms.ImageField(
616+
widget=forms.widgets.FileInput,
617+
help_text="For display on dark backgrounds (e.g. PyPI footer). Transparent PNG, smallest dimension no less than 256px",
618+
required=False,
619+
)
609620
print_logo = forms.FileField(
610621
widget=forms.widgets.FileInput,
611622
help_text="For printed materials, signage, and projection. SVG or EPS",
@@ -647,6 +658,7 @@ class Meta:
647658
"twitter_handle",
648659
"linked_in_page_url",
649660
"web_logo",
661+
"white_logo",
650662
"print_logo",
651663
"primary_phone",
652664
"mailing_address_line_1",
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Generated by Django 5.2.11 on 2026-04-06 18:04
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
dependencies = [
8+
("sponsors", "0103_alter_benefitfeature_polymorphic_ctype_and_more"),
9+
]
10+
11+
operations = [
12+
migrations.AddField(
13+
model_name="sponsor",
14+
name="white_logo",
15+
field=models.ImageField(
16+
blank=True,
17+
help_text="For display on dark backgrounds (e.g. PyPI footer). Transparent PNG, smallest dimension no less than 256px",
18+
null=True,
19+
upload_to="sponsor_white_logos",
20+
verbose_name="White logo",
21+
),
22+
),
23+
]

apps/sponsors/models/sponsors.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ class Sponsor(ContentManageable):
4949
help_text="For display on our sponsor webpage. High resolution PNG or JPG, smallest dimension no less than "
5050
"256px",
5151
)
52+
white_logo = models.ImageField(
53+
upload_to="sponsor_white_logos",
54+
blank=True,
55+
null=True,
56+
verbose_name="White logo",
57+
help_text="For display on dark backgrounds (e.g. PyPI footer). Transparent PNG, smallest dimension no less than 256px",
58+
)
5259
print_logo = models.FileField(
5360
upload_to="sponsor_print_logos",
5461
validators=[FileExtensionValidator(["eps", "epsfepsi", "svg", "png"])],

apps/sponsors/serializers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class LogoPlacementSerializer(serializers.Serializer):
1616
sponsor_slug = serializers.CharField()
1717
description = serializers.CharField()
1818
logo = serializers.URLField()
19+
white_logo = serializers.URLField(required=False, allow_null=True)
1920
start_date = serializers.DateField()
2021
end_date = serializers.DateField()
2122
sponsor_url = serializers.URLField()

0 commit comments

Comments
 (0)