upgrade home template with thumbnail.
authorcavaliet
Tue, 29 Jan 2013 18:42:24 +0100
changeset 17 38611b2c2782
parent 16 984dd6395764
child 18 ffd106d9b8e1
upgrade home template with thumbnail.
.hgignore
src/egonomy/config.py.tmpl
src/egonomy/settings.py
src/egonomy/templates/egonomy_home.html
src/egonomy/urls.py
src/egonomy/views.py
web/static/media/.keepme
--- a/.hgignore	Tue Jan 29 12:53:18 2013 +0100
+++ b/.hgignore	Tue Jan 29 18:42:24 2013 +0100
@@ -10,4 +10,4 @@
 ^\.project$
 ^\.settings/org\.eclipse\.core\.resources\.prefs$
 ^\.settings/org\.eclipse\.core\.runtime\.prefs$
-
+^web/static/media/cache$
--- a/src/egonomy/config.py.tmpl	Tue Jan 29 12:53:18 2013 +0100
+++ b/src/egonomy/config.py.tmpl	Tue Jan 29 18:42:24 2013 +0100
@@ -34,15 +34,13 @@
 
 BASE_STATIC_ROOT = os.path.abspath(BASE_DIR + "../../web/static/").rstrip("/")+"/"
 MEDIA_ROOT = BASE_STATIC_ROOT + "media/"
+MEDIA_URL = BASE_URL + "static/media/"
 # Absolute path to the directory that static files (js, css, swf...)
 # DO NOT forget to do command line ./manage.py collectstatic to gather static media into the web/static folder
 STATIC_ROOT = BASE_STATIC_ROOT + "site/"
 
-
-# URL that handles the media served from MEDIA_ROOT. Make sure to use a
-# trailing slash.
-# Examples: "http://example.com/media/", "http://media.example.com/"
-MEDIA_URL = ''
+# Local path to rmn pictures
+RMN_PICT_ROOT = STATIC_ROOT + 'rmn/'
 
 
 # Make this unique, and don't share it with anybody.
--- a/src/egonomy/settings.py	Tue Jan 29 12:53:18 2013 +0100
+++ b/src/egonomy/settings.py	Tue Jan 29 18:42:24 2013 +0100
@@ -118,6 +118,7 @@
     'django.contrib.staticfiles',
     'django.contrib.admin',
     'django.contrib.admindocs',
+    'sorl.thumbnail',
     'egonomy',
 )
 
--- a/src/egonomy/templates/egonomy_home.html	Tue Jan 29 12:53:18 2013 +0100
+++ b/src/egonomy/templates/egonomy_home.html	Tue Jan 29 18:42:24 2013 +0100
@@ -1,6 +1,7 @@
 {% extends "egonomy_base.html" %}
 {% load static %}
 {% load i18n %}
+{% load thumbnail %}
 
 {% block title %}{% trans "Home" %}{% endblock %}
 
@@ -11,38 +12,32 @@
                     <div class="column column-half">
                         <h2>{% trans "Last annotated pictures" %}</h2>
                         <ul class="fullwidth">
+                          {% for img in img_list %}
                             <li class="subcol subcol-half-fourth">
                                 <a href="{% url 'annotate_picture' %}">
                                 <div class="center-image">
-                                    <img src="{% static 'egonomy/img/empty.gif' %}" width="110" height="82" class="placeholder" />
-                                </div>
-                                <h3>Titre de l'image</h3></a>
-                                <p>{% trans "Annotated by" %} <strong>Julien75</strong></p>
-                            </li>
-                            <li class="subcol subcol-half-fourth">
-                                <a href="{% url 'annotate_picture' %}">
-                                <div class="center-image">
-                                    <img src="{% static 'egonomy/img/empty.gif' %}" width="82" height="110" class="placeholder" />
+                                 {% if img %}
+                                  {% if img|is_portrait %}
+							 	    {% thumbnail img "x110" format="PNG" crop="center" as im %}
+	                                  <img src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}"/>
+	                                {% empty %}
+	                                  <img src="{% static 'egonomy/img/empty.gif' %}" width="110" height="110" class="placeholder" />
+	                                {% endthumbnail %}
+	                              {% else %}
+                                    {% thumbnail img "110" format="PNG" crop="center" as im %}
+                                      <img src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}"/>
+                                    {% empty %}
+                                      <img src="{% static 'egonomy/img/empty.gif' %}" width=110" height="110" class="placeholder" />
+                                    {% endthumbnail %}
+	                              {% endif %}
+	                              {% else %}
+	                                  <img src="{% static 'egonomy/img/empty.gif' %}" width=110" height="110" class="placeholder" />
+	                             {% endif %}
                                 </div>
                                 <h3>Titre de l'image</h3></a>
                                 <p>{% trans "Annotated by" %} <strong>Julien75</strong></p>
                             </li>
-                            <li class="subcol subcol-half-fourth">
-                                <a href="{% url 'annotate_picture' %}">
-                                <div class="center-image">
-                                    <img src="{% static 'egonomy/img/empty.gif' %}" width="110" height="82" class="placeholder" />
-                                </div>
-                                <h3>Titre de l'image</h3></a>
-                                <p>{% trans "Annotated by" %} <strong>Julien75</strong></p>
-                            </li>
-                            <li class="subcol subcol-half-fourth">
-                                <a href="{% url 'annotate_picture' %}">
-                                <div class="center-image">
-                                    <img src="{% static 'egonomy/img/empty.gif' %}" width="110" height="110" class="placeholder" />
-                                </div>
-                                <h3>Titre de l'image</h3></a>
-                                <p>{% trans "Annotated by" %} <strong>Julien75</strong></p>
-                            </li>
+                          {% endfor %}
                         </ul>
                     </div>
                     
--- a/src/egonomy/urls.py	Tue Jan 29 12:53:18 2013 +0100
+++ b/src/egonomy/urls.py	Tue Jan 29 18:42:24 2013 +0100
@@ -1,4 +1,6 @@
+from django.conf import settings
 from django.conf.urls import patterns, include, url
+from django.conf.urls.static import static
 from django.contrib.staticfiles.urls import staticfiles_urlpatterns
 
 # Uncomment the next two lines to enable the admin:
@@ -16,4 +18,5 @@
     # Uncomment the next line to enable the admin:
     url(r'^admin/', include(admin.site.urls)),
 )
-urlpatterns += staticfiles_urlpatterns()
\ No newline at end of file
+urlpatterns += staticfiles_urlpatterns()
+urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
\ No newline at end of file
--- a/src/egonomy/views.py	Tue Jan 29 12:53:18 2013 +0100
+++ b/src/egonomy/views.py	Tue Jan 29 18:42:24 2013 +0100
@@ -3,13 +3,22 @@
 #from django.core.paginator import Paginator, InvalidPage, EmptyPage
 from django.shortcuts import render_to_response
 from django.template import RequestContext
+from sorl.thumbnail.images import ImageFile
+from django.core.files.storage import FileSystemStorage
 
 
 
 def home(request):
     
+    
+    im1 = ImageFile(open(settings.RMN_PICT_ROOT+"0/00-004125.jpg", 'r'), FileSystemStorage(location=settings.RMN_PICT_ROOT))
+    im2 = ImageFile(open(settings.RMN_PICT_ROOT+"1/00-007590.jpg", 'r'), FileSystemStorage(location=settings.RMN_PICT_ROOT))
+    im3 = ImageFile(open(settings.RMN_PICT_ROOT+"2/00-001283.jpg", 'r'), FileSystemStorage(location=settings.RMN_PICT_ROOT))
+    im4 = ImageFile(open(settings.RMN_PICT_ROOT+"3/00-000023.jpg", 'r'), FileSystemStorage(location=settings.RMN_PICT_ROOT))
+    img_list = [im1,im2,im3,im4]
+    
     return render_to_response("egonomy_home.html",
-                              {'any_var': "coucou"},
+                              {'img_list': img_list},
                               context_instance=RequestContext(request))