# HG changeset patch # User cavaliet # Date 1361287793 -3600 # Node ID 4c0838a3a8b6ea9eea49037b7a60b7e56d83113c # Parent 962c6986211558ab8c39e06f34bfad917ed7fa8d add limit 600px height limit in template. Create templatetag to get image ratio. diff -r 962c69862115 -r 4c0838a3a8b6 src/egonomy/templates/egonomy_annotate_picture.html --- a/src/egonomy/templates/egonomy_annotate_picture.html Tue Feb 19 15:46:37 2013 +0100 +++ b/src/egonomy/templates/egonomy_annotate_picture.html Tue Feb 19 16:29:53 2013 +0100 @@ -2,6 +2,7 @@ {% load static %} {% load i18n %} {% load thumbnail %} +{% load egonomy_thumbnail %} {% block title %}{% trans "Annotate a picture" %}{% endblock %} @@ -9,13 +10,21 @@

{% if img.metadata.titre %}{{ img.metadata.titre }}{% else %}({% trans "No title" %}){% endif %}

-
+
{% with img.info.image_file as image %} - {% thumbnail image "476" format="PNG" crop="center" as im %} + {% if image|ratio > 0.8 %} + {% thumbnail image "476" format="PNG" crop="center" as im %} - {% empty %} + {% empty %} - {% endthumbnail %} + {% endthumbnail %} + {% else %} + {% thumbnail image "x600" format="PNG" crop="center" as im %} + + {% empty %} + + {% endthumbnail %} + {% endif %} {% endwith %}
diff -r 962c69862115 -r 4c0838a3a8b6 src/egonomy/templates/egonomy_create_fragment.html --- a/src/egonomy/templates/egonomy_create_fragment.html Tue Feb 19 15:46:37 2013 +0100 +++ b/src/egonomy/templates/egonomy_create_fragment.html Tue Feb 19 16:29:53 2013 +0100 @@ -2,6 +2,7 @@ {% load static %} {% load i18n %} {% load thumbnail %} +{% load egonomy_thumbnail %} {% block title %}{% trans "Create or edit a fragment" %}{% endblock %} @@ -18,15 +19,25 @@ ×

{% trans 'New fragment' %} :

-
- {% with img.info.image_file as image %} - {% thumbnail image "476" format="PNG" crop="center" as im %} - - {% empty %} - - {% endthumbnail %} - {% endwith %} -
+
+
+ {% with img.info.image_file as image %} + {% if image|ratio > 0.8 %} + {% thumbnail image "476" format="PNG" crop="center" as im %} + + {% empty %} + + {% endthumbnail %} + {% else %} + {% thumbnail image "x600" format="PNG" crop="center" as im %} + + {% empty %} + + {% endthumbnail %} + {% endif %} + {% endwith %} +
+
diff -r 962c69862115 -r 4c0838a3a8b6 src/egonomy/templates/egonomy_view_fragment.html --- a/src/egonomy/templates/egonomy_view_fragment.html Tue Feb 19 15:46:37 2013 +0100 +++ b/src/egonomy/templates/egonomy_view_fragment.html Tue Feb 19 16:29:53 2013 +0100 @@ -2,6 +2,7 @@ {% load static %} {% load i18n %} {% load thumbnail %} +{% load egonomy_thumbnail %} {% block title %}{% trans "View a fragment" %}{% endblock %} @@ -9,18 +10,28 @@

{{ fragment.title }}

-
- {% with fragment.image.info.image_file as image %} - {% thumbnail image "476" format="PNG" crop="center" as im %} - - {% empty %} - - {% endthumbnail %} - {% endwith %} - - - -
+
+
+ {% with fragment.image.info.image_file as image %} + {% if image|ratio > 0.8 %} + {% thumbnail image "476" format="PNG" crop="center" as im %} + + {% empty %} + + {% endthumbnail %} + {% else %} + {% thumbnail image "x600" format="PNG" crop="center" as im %} + + {% empty %} + + {% endthumbnail %} + {% endif %} + {% endwith %} + + + +
+
diff -r 962c69862115 -r 4c0838a3a8b6 src/egonomy/templatetags/egonomy_thumbnail.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/egonomy/templatetags/egonomy_thumbnail.py Tue Feb 19 16:29:53 2013 +0100 @@ -0,0 +1,19 @@ +from django.template import Library +from sorl.thumbnail import default +from sorl.thumbnail.images import ImageFile +from sorl.thumbnail.templatetags.thumbnail import safe_filter + + +register = Library() + + +@safe_filter(error_output=False) +@register.filter +def ratio(file_): + """ + A very handy filter to determine if an image is portrait or landscape. + """ + if not file_: + return False + image_file = default.kvstore.get_or_set(ImageFile(file_)) + return image_file.ratio