search first step
authorcavaliet
Thu, 31 Jan 2013 18:01:44 +0100
changeset 20 8dd5b0f370fc
parent 19 e00c68158187
child 21 5f3e270580af
search first step
src/egonomy/templates/egonomy_base.html
src/egonomy/templates/egonomy_home.html
src/egonomy/views.py
--- a/src/egonomy/templates/egonomy_base.html	Wed Jan 30 18:02:15 2013 +0100
+++ b/src/egonomy/templates/egonomy_base.html	Thu Jan 31 18:01:44 2013 +0100
@@ -20,8 +20,9 @@
         <div class="header-wrap fullwidth">
             <header>
                 <h1 class="column column-third"><a href="{% url 'home' %}">TagItAll {% trans "by" %} eGonomy</a></h1>
-                <form class="column column-third">
-                    <input class="search-field" type="search" placeholder="{% trans 'Search' %}" />
+                <form class="column column-third" action="{% url 'home' %}" method="GET">
+                    <input class="search-field" type="search" placeholder="{% trans 'Search' %}" id="id_search" name="search"/>
+                    <input type="hidden" value="all" name="field">
                 </form>
                 <nav class="column column-third">
                     <a href="#">{% trans "Login" %}</a>
--- a/src/egonomy/templates/egonomy_home.html	Wed Jan 30 18:02:15 2013 +0100
+++ b/src/egonomy/templates/egonomy_home.html	Thu Jan 31 18:01:44 2013 +0100
@@ -6,11 +6,20 @@
 {% block title %}{% trans "Home" %}{% endblock %}
 
 {% block content %}
+            {% if search %}
+                <div class="fullwidth">
+                  {% ifequal nb_results 0 %}
+                    <h2>{% trans "No results for" %} &laquo;&nbsp;{{ search }}&nbsp;&raquo;&nbsp;</h2>
+                  {% else %}
+                    <h2>{% trans "Search results for" %} &laquo;&nbsp;{{ search }}&nbsp;&raquo;&nbsp;:</h2>
+                  {% endifequal %}
+                </div>
+            {% endif %}
                 <div class="fullwidth">
                 
                     <!-- Liste des dernières images annotées -->
                     <div class="column column-half">
-                        <h2>{% trans "Last annotated pictures" %}</h2>
+                        <h2>{% if search %}{% trans "Corresponding pictures" %}{% else %}{% trans "Last annotated pictures" %}{% endif %}</h2>
                         <ul class="fullwidth">
                           {% for img in img_list %}
                             <li class="subcol subcol-half-fourth">
@@ -34,7 +43,7 @@
 	                                  <img src="{% static 'egonomy/img/empty.gif' %}" width=110" height="110" class="placeholder" />
 	                             {% endif %}
                                 </div>
-                                <h3>{{ img.title }}</h3></a>
+                                <h3>{{ img.title|safe }}</h3></a>
                                 <p>{% trans "Annotated by" %} <strong>{{ img.author }}</strong></p>
                             </li>
                           {% endfor %}
@@ -43,7 +52,7 @@
                     
                     <!-- Liste des derniers fragments modifiés -->
                     <div class="column column-half">
-                        <h2>{% trans "Last created fragments" %}</h2>
+                        <h2>{% if search %}{% trans "Corresponding fragments" %}{% else %}{% trans "Last created fragments" %}{% endif %}</h2>
                         <ul class="fullwidth">
                           {% for frg in fragment_list %}
                             <li class="subcol subcol-half-fourth">
@@ -72,8 +81,8 @@
                                         </svg>
                                     </div>
                                 </div>
-                                <h3>{{ frg.title }}</h3></a>
-                                <h4>{% trans "Fragment from" %} <a href="{% url 'annotate_picture' %}">{{ frg.image.title }}</a></h4>
+                                <h3>{{ frg.title|safe }}</h3></a>
+                                <h4>{% trans "Fragment from" %} <a href="{% url 'annotate_picture' %}">{{ frg.image.title|safe }}</a></h4>
                                 <p>{% trans "Annotated by" %} <strong>{{ frg.author }}</strong></p>
                             </li>
                           {% endfor %}
--- a/src/egonomy/views.py	Wed Jan 30 18:02:15 2013 +0100
+++ b/src/egonomy/views.py	Thu Jan 31 18:01:44 2013 +0100
@@ -11,20 +11,36 @@
 
 def home(request):
     
+    # if the request has a "search" get parameter, we search this term
+    search = None
+    nb_results = 1
+    if "search" in request.GET:
+        search = request.GET["search"]
+        field = "all"
+        if "field" in request.GET:
+            field = request.GET["field"]
+        
+    
     im1 = {"image": ImageFile(open(settings.RMN_PICT_ROOT+"0/00-004125.jpg", 'r'),FileSystemStorage(location=settings.RMN_PICT_ROOT)), "title":"title im 1", "author":"juju"}
-    im2 = {"image": ImageFile(open(settings.RMN_PICT_ROOT+"0/00-004543.jpg", 'r'),FileSystemStorage(location=settings.RMN_PICT_ROOT)), "title":"title im 2", "author":"loulou"}
+    im2 = {"image": ImageFile(open(settings.RMN_PICT_ROOT+"0/00-004543.jpg", 'r'),FileSystemStorage(location=settings.RMN_PICT_ROOT)), "title":"<span class=\"highlight\">title</span> im 2", "author":"loulou"}
     im3 = {"image": ImageFile(open(settings.RMN_PICT_ROOT+"0/01-017513.jpg", 'r'),FileSystemStorage(location=settings.RMN_PICT_ROOT)), "title":"title im 3", "author":"juju"}
     im4 = {"image": ImageFile(open(settings.RMN_PICT_ROOT+"0/02-009258.jpg", 'r'),FileSystemStorage(location=settings.RMN_PICT_ROOT)), "title":"title im 4", "author":"loulou"}
-    img_list = [im1,im2,im3,im4,im3,im4,im1,im2]
+    if search:
+        img_list = [im1,im2,im3,im4]
+    else:
+        img_list = [im1,im2,im3,im4,im3,im4,im1,im2]
     
-    frg1 = {"image": im2, "path":"M 0 .5 L .5 0 L 1 .5 L .5 1 Z", "title":"Fragment X", "author":"juju"}
+    frg1 = {"image": im2, "path":"M 0 .5 L .5 0 L 1 .5 L .5 1 Z", "title":"<span class=\"highlight\">Fragment</span> X", "author":"juju"}
     frg2 = {"image": im3, "path":"M .1 .3 L .5 .1 L .8 .7 Z", "title":"Fragment Y", "author":"loulou"}
     frg3 = {"image": im4, "path":"M 0 .5 L .5 0 L 1 .5 L .5 1 Z", "title":"Fragment Z", "author":"juju"}
     frg4 = {"image": im1, "path":"M .2 .5 L .7 .2 L .8 .7 Z", "title":"Fragment W", "author":"loulou"}
-    frg_list = [frg1,frg2,frg3,frg4,frg3,frg4,frg1,frg2]
+    if search:
+        frg_list = [frg1,frg2,frg3,frg4]
+    else:
+        frg_list = [frg1,frg2,frg3,frg4,frg3,frg4,frg1,frg2]
     
     return render_to_response("egonomy_home.html",
-                              {'img_list': img_list, 'fragment_list': frg_list},
+                              {'img_list':img_list, 'fragment_list':frg_list, "search":search, "nb_results":nb_results},
                               context_instance=RequestContext(request))