Skip to content

Commit

Permalink
[Fixes #1007] Added default partner logo.
Browse files Browse the repository at this point in the history
  • Loading branch information
kardan committed Jul 9, 2015
1 parent 0c02134 commit 70fdabc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
Binary file added akvo/rsr/static/images/default-org-logo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 15 additions & 11 deletions akvo/rsr/templatetags/rsr_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from __future__ import absolute_import, print_function

from django import template
from django.conf import settings
from django.contrib.auth import get_user_model
from akvo.rsr.models import Keyword, PartnerSite, Project, ProjectUpdate, Organisation
register = template.Library()
Expand All @@ -16,30 +17,33 @@
@register.inclusion_tag('rsr_utils/img.html', takes_context=True)
def img(context, obj, width, height, alt):
"""Standard way to show image."""
geometry = '{}x{}'.format(width, height)
img = ""
geometry = "{}x{}".format(width, height)
default_img = "//placehold.it/{}".format(geometry)

# Based on type get image
img = obj
if isinstance(obj, Project):
img = obj.current_image
elif isinstance(obj, ProjectUpdate):
img = obj.photo
elif isinstance(obj, Organisation):
img = obj.logo
if obj.logo:
img = obj.logo
else:
default_img = "//{}{}{}".format(
context["request"].get_host(),
getattr(settings, "STATIC_URL"),
"images/default-org-logo.jpg")
elif isinstance(obj, get_user_model()):
img = obj.avatar
elif isinstance(obj, PartnerSite):
img = obj.logo
elif isinstance(obj, Keyword):
img = obj.logo

height = '{}.px'.format(height)

return {'alt': alt,
'height': height,
'img': img,
'geometry': geometry,
'width': width}
return {"default_img": default_img,
"geometry": geometry,
"img": img,
"alt": alt}


@register.inclusion_tag('rsr_utils/vid_img.html', takes_context=True)
Expand Down
8 changes: 4 additions & 4 deletions akvo/templates/rsr_utils/img.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

{% if img %}
{% thumbnail img geometry format="PNG" upscale=True as im %}
<img src="{{im.url}}" />
<img src="{{im.url}}" alt="{{alt}}"/>
{% endthumbnail %}
{% else %}
{% with url='//placehold.it/'|add:geometry %}
<img src="{{url}}" alt="" />
{% endwith %}
{% with url=default_img %}
<img src="{{url}}" alt="{{alt}}" />
{% endwith %}
{% endif %}

0 comments on commit 70fdabc

Please sign in to comment.