Skip to content

Commit 104c6ea

Browse files
berinhardewdurbin
andauthored
Use EthicalAds to place logos under Sponsors page (python#1981)
* Minimal working code to place sponsors logos * Replace thumbnail logo by EthicalAds integration * Create fallback to prevent 500 error when local development * Refactor by adding slug to sponsor model * restore anchor link and sponsor name under logo on sponsors page Co-authored-by: Ee Durbin <ewdurbin@gmail.com>
1 parent 3a42133 commit 104c6ea

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

sponsors/models/sponsors.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from allauth.account.models import EmailAddress
55
from django.conf import settings
66
from django.db import models
7+
from django.core.exceptions import ObjectDoesNotExist
78
from django.template.defaultfilters import slugify
89
from django.urls import reverse
910
from django_countries.fields import CountryField

sponsors/templatetags/sponsors.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ def benefit_name_for_display(benefit, package):
7676
@register.filter
7777
def ideal_size(image, ideal_dimension):
7878
ideal_dimension = int(ideal_dimension)
79+
try:
80+
w, h = image.width, image.height
81+
except FileNotFoundError:
82+
# local dev doesn't have all images if DB is a copy from prod environment
83+
# this is just a fallback to return ideal_dimension instead
84+
w, h = ideal_dimension, ideal_dimension
85+
7986
return int(
80-
image.width * math.sqrt((100 * ideal_dimension) / (image.width * image.height))
87+
w * math.sqrt((100 * ideal_dimension) / (w * h))
8188
)

templates/base.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
<meta http-equiv="cleartype" content="on">
2424
<meta http-equiv="imagetoolbar" content="false">{# Kills IE6's images toolbar. Still useful. #}
2525

26+
<script async
27+
src="https://media.ethicalads.io/media/client/v1.4.0/ethicalads.min.js"
28+
integrity="sha256-U3hKDidudIaxBDEzwGJApJgPEf2mWk6cfMWghrAa6i0= sha384-UcmsCqcNRSLW/dV3Lo1oCi2/VaurXbib6p4HyUEOeIa/4OpsrnucrugAefzVZJfI sha512-q4t1L4xEjGV2R4hzqCa41P8jrgFUS8xTb8rdNv4FGvw7FpydVj/kkxBJHOiaoxHa8olCcx1Slk9K+3sNbsM4ug=="
29+
crossorigin="anonymous"
30+
></script>
2631
<script src="{{ STATIC_URL }}js/libs/modernizr.js"></script>
2732

2833
{% stylesheet 'style' %}

templates/sponsors/partials/sponsors-list.html

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,24 @@ <h3 class="widget-title">Job Board Sponsors</h3>
3838
{% if placement_info.sponsorships %}
3939
<div title="{{ package.name }} Sponsors" align="center">
4040
{% with dimension=placement_info.logo_dimension %}
41-
{% with thumbnail_res=dimension|add:"x"|add:dimension %}
4241

4342
<h1 style="font-size: {% if forloop.first %}350%{% else %}300%{% endif %}">{{ package }} Sponsors</h1>
4443

4544
<div style="display: grid; grid-gap: 2em; grid-template-columns: repeat(auto-fit, minmax({{ dimension }}px, 0fr)); grid-template-rows: repeat(1, minmax({{ dimension }}px, 0fr)); align-items: center; justify-content: center;">
4645
{% for sponsorship in placement_info.sponsorships %}
47-
<div id={{ sponsorship.sponsor.name|slugify }}>
48-
<a href="{{ sponsorship.sponsor.landing_page_url }}">
49-
{% thumbnail sponsorship.sponsor.web_logo thumbnail_res format="PNG" quality=100 as im %}
50-
<img src="{{ im.url }}" alt="{{ sponsorship.sponsor.name }} logo" style="max-width:{{ im|ideal_size:dimension }}px;height:auto;width:auto;">
51-
{% endthumbnail %}
52-
</a>
53-
54-
<p>{{ sponsorship.sponsor.name }}</p>
55-
</div>
46+
<div id="{{ sponsorship.sponsor.slug }}">
47+
<div
48+
data-ea-publisher="psf"
49+
data-ea-type="psf-image-only"
50+
data-ea-force-ad="{{ sponsorship.sponsor.slug }}-psf-sponsors"
51+
style="max-width:{{ sponsorship.sponsor.web_logo|ideal_size:dimension }}px;height:auto;width:auto;"
52+
></div>
53+
<p>{{ sponsorship.sponsor.name }}</p>
54+
</div>
5655
{% endfor %}
5756
</div>
5857

5958
{% endwith %}
60-
{% endwith %}
6159
</div>
6260
{% endif %}
6361
{% endfor %}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy