[damned-lies] Replace person.image snippet by a custom template filter



commit 22c9c67b9b3fafec94091af3d87234a123325649
Author: Claude Paroz <claude 2xlibre net>
Date:   Mon Mar 24 17:47:19 2014 +0100

    Replace person.image snippet by a custom template filter

 common/static/css/template.css          |    4 ++++
 people/templatetags/people.py           |   10 ++++++++++
 templates/people/person_list.html       |    8 ++------
 templates/people/person_overview.html   |   10 ++--------
 templates/vertimus/vertimus_detail.html |    8 ++------
 5 files changed, 20 insertions(+), 20 deletions(-)
---
diff --git a/common/static/css/template.css b/common/static/css/template.css
index 17fd8eb..0c56010 100644
--- a/common/static/css/template.css
+++ b/common/static/css/template.css
@@ -707,6 +707,10 @@ div.face_image {
        float: left;
        margin: 0 10px 0 0;
 }
+div.face_image img {
+       max-height: 50px;
+       max-width: 50px;
+}
 
 .right_actions {
        float: right;
diff --git a/people/templatetags/people.py b/people/templatetags/people.py
index 780d27f..ce363e6 100644
--- a/people/templatetags/people.py
+++ b/people/templatetags/people.py
@@ -1,4 +1,5 @@
 from django import template
+from django.conf import settings
 from django.utils.safestring import mark_safe
 from django.utils.translation import ugettext as _
 
@@ -13,3 +14,12 @@ def people_list(lst):
     result = _(", ").join('<a href="%s">%s</a>' % (pers.get_absolute_url(), pers.name)
                           for pers in lst)
     return mark_safe(result)
+
+
+ register filter
+def people_image(person):
+    if person.image:
+        tag = '<img src="%s" alt="%s">' % (person.image, person.name)
+    else:
+        tag = '<img src="%simg/nobody.png" alt="generic person icon">' % settings.STATIC_URL
+    return mark_safe(tag)
diff --git a/templates/people/person_list.html b/templates/people/person_list.html
index 1361d53..4aefb36 100644
--- a/templates/people/person_list.html
+++ b/templates/people/person_list.html
@@ -1,5 +1,5 @@
 {% extends "base.html" %}
-{% load i18n %}
+{% load i18n people %}
 
 {% block title %}{% trans "GNOME Contributors" %}{% endblock %}
 
@@ -16,11 +16,7 @@
     <div class="col3_column">
       {% for person in l %}
       <div class="person_list">
-        {% if person.image %}
-        <img src="{{ person.image }}" alt="{{ person.name }}" />
-        {% else %}
-        <img src="{{ STATIC_URL }}img/nobody.png" alt="" />
-        {% endif %}
+        {{ person|people_image }}
         <a class="name" href="{{ person.get_absolute_url }}">{{ person.name }}</a><br />
 
         {% if person.webpage_url %}
diff --git a/templates/people/person_overview.html b/templates/people/person_overview.html
index 8a09cf1..8e688a4 100644
--- a/templates/people/person_overview.html
+++ b/templates/people/person_overview.html
@@ -1,16 +1,10 @@
 {# Variables $person and $printroles must be defined prior to calling this template #}
 {# This template is included in person.html, team.html and language-release.html #}
 
-{% load i18n %}
+{% load i18n people %}
 
 <div class="person_detail">
-    <div class="image">
-    {% if person.image %}
-        <img src="{{ person.image }}" alt="{{ person.name }}" />
-    {% else %}
-        <img src="{{ STATIC_URL }}img/nobody.png" alt="" />
-    {% endif %}
-    </div>
+    <div class="image">{{ person|people_image }}</div>
 
     <div class="txt">
         <a class="name" href="{{ person.get_absolute_url }}">{{ person.name }}</a>
diff --git a/templates/vertimus/vertimus_detail.html b/templates/vertimus/vertimus_detail.html
index 0b3c137..02efc13 100644
--- a/templates/vertimus/vertimus_detail.html
+++ b/templates/vertimus/vertimus_detail.html
@@ -1,5 +1,5 @@
 {% extends "base.html" %}
-{% load i18n humanize stats_extras %}
+{% load i18n humanize people stats_extras %}
 {% load url from future %}
 
 {% block title %}
@@ -177,11 +177,7 @@ $(document).ready(function() {
       , <strong>{{ action.description }}</strong>, {{ action.created|date:_("Y-m-d g:i a O") }}
     </div>
     <div class="vertimus_action_content">
-               <div class="face_image">
-                       {% if action.person.image %}<img src="{{ action.person.image }}" alt="face" 
style="max-height: 50px;"/>
-                       {% else %}<img src="{{ STATIC_URL }}img/nobody.png" alt="Person"/>
-                       {% endif %}
-               </div>
+      <div class="face_image">{{ action.person|people_image }}</div>
       {% if action.file %}
       <div class="uploaded_file">
         <a href="{{ action.file.url }}" class="download_button">


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]