Skip to content

Commit

Permalink
Merge pull request #249 from OpenUpSA/fix/people-page
Browse files Browse the repository at this point in the history
Fix/people page
  • Loading branch information
paulmwatson authored Dec 12, 2024
2 parents a5a84de + 1c4261d commit 8e5ca54
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
9 changes: 9 additions & 0 deletions pombola/core/templatetags/safe_image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django import template

register = template.Library()

@register.filter
def safe_image_width(image):
if image and hasattr(image, 'width'):
return image.width
return None
1 change: 1 addition & 0 deletions pombola/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@
BLOG_RSS_FEED = os.environ.get("BLOG_RSS_FEED", None)

THUMBNAIL_DEBUG = True
THUMBNAIL_FORMAT = 'PNG'

# ZA Hansard settings
HANSARD_CACHE = os.path.join(data_dir, "hansard_cache")
Expand Down
5 changes: 5 additions & 0 deletions pombola/south_africa/templates/core/organisation_people.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{% load pagination_tags %}
{% load staticfiles %}
{% load thumbnail %}
{% load safe_image %}


{% block title %}{{ object.name }} People{% endblock %}
Expand Down Expand Up @@ -45,7 +46,11 @@ <h3>Show</h3>

<a href="{{ person.get_absolute_url }}">
{% thumbnail person.primary_image "58x78" crop="center" as im %}
{% if im|safe_image_width %}
<img src="{{ im.url }}" alt="{{ person.name }}" width="{{ im.width }}" height="{{ im.height }}" />
{% else %}
<img src="{% static 'images/person-90x90.jpg' %}" height="58" width="58"/>
{% endif %}
{% empty %}
<img src="{% static 'images/person-90x90.jpg' %}" height="58" width="58"/>
{% endthumbnail %}
Expand Down
27 changes: 16 additions & 11 deletions pombola/south_africa/templates/core/person_list_item.html
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
{% load staticfiles %}
{% load thumbnail %}
{% load za_people_display %}
{% load safe_image %}

<a href="{{ object.get_absolute_url }}">
{% thumbnail object.primary_image "58x78" crop="center" as im %}
{% if lazy_load_images %}
<img src="{% static 'images/person-58x78.jpg' %}"
data-src="{{ im.url }}"
width="{{ im.width }}"
height="{{ im.height }}"
alt="{{ object.name }}"
loading="lazy">

<noscript><img src="{{ im.url }}" alt="{{ object.name }}" width="{{ im.width }}" height="{{ im.height }}" loading="lazy"/></noscript>
{% thumbnail object.primary_image "58x78" crop="center" convert="RGBA" as im %}
{% if im|safe_image_width %}
{% if lazy_load_images %}
<img src="{% static 'images/person-58x78.jpg' %}"
data-src="{{ im.url }}"
width="{{ im.width }}"
height="{{ im.height }}"
alt="{{ object.name }}"
loading="lazy">

<noscript><img src="{{ im.url }}" alt="{{ object.name }}" width="{{ im.width }}" height="{{ im.height }}" loading="lazy"/></noscript>
{% else %}
<img src="{{ im.url }}" alt="{{ object.name }}" width="{{ im.width }}" height="{{ im.height }}" loading="lazy"/>
{% endif %}
{% else %}
<img src="{{ im.url }}" alt="{{ object.name }}" width="{{ im.width }}" height="{{ im.height }}" loading="lazy"/>
<img src="{% static 'images/person-58x78.jpg' %}" height="58" width="58" loading="lazy"/>
{% endif %}
{% empty %}
<img src="{% static 'images/person-58x78.jpg' %}" height="58" width="58" loading="lazy"/>
Expand Down

0 comments on commit 8e5ca54

Please sign in to comment.