add search page, cf #19
authorymh <ymh.work@gmail.com>
Tue, 12 Jul 2011 18:24:30 +0200
changeset 96 e8a32d48da1b
parent 95 798d8a898237
child 97 0d0b23401d14
add search page, cf #19
web/hdabo/models.py
web/hdabo/static/hdabo/css/style.css
web/hdabo/templates/hdabo_base.html
web/hdabo/templates/search/search.html
--- a/web/hdabo/models.py	Tue Jul 12 14:46:39 2011 +0200
+++ b/web/hdabo/models.py	Tue Jul 12 18:24:30 2011 +0200
@@ -278,6 +278,12 @@
         
         return locals()
 
+    @models.permalink
+    def get_absolute_url(self):
+        return ('display_datasheet', (), {
+                    'ds_id': self.hda_id
+                })
+
 
 class TaggedSheet(models.Model):
     datasheet = models.ForeignKey(Datasheet)
--- a/web/hdabo/static/hdabo/css/style.css	Tue Jul 12 14:46:39 2011 +0200
+++ b/web/hdabo/static/hdabo/css/style.css	Tue Jul 12 18:24:30 2011 +0200
@@ -400,4 +400,20 @@
 
 #login_fields_list, #submitcontent-buttons-login {
 	margin: 10px 0px;
+}
+
+#search_results {
+	margin-left: 10px;
+}
+
+.result_counter {
+	color: #C6C6C6;
+}
+
+#search_prev_next {
+	margin-top: 20px;
+}
+
+#page_number {
+	text-align: right;
 }
\ No newline at end of file
--- a/web/hdabo/templates/hdabo_base.html	Tue Jul 12 14:46:39 2011 +0200
+++ b/web/hdabo/templates/hdabo_base.html	Tue Jul 12 18:24:30 2011 +0200
@@ -58,6 +58,7 @@
     {% if user.is_authenticated %}
     <ul><li><a href="{% url hdabo.views.home %}">Home</a></li>
     <li><a href="{% url hdabo.views.all_tags %}">Tous les tags</a></li>
+    <li><a href="{% url haystack_search %}">Recherche</a></li>
     <li><span style="float:right;">{{user.username}}&nbsp;|&nbsp;<a href="{% url django.contrib.auth.views.logout_then_login %}" >Se déconnecter</a>{% if user.is_staff %}&nbsp;|&nbsp;<a href="{{BASE_URL}}admin" >admin</a>{% endif %}</span></li>
     </ul>
     {% endif %}
--- a/web/hdabo/templates/search/search.html	Tue Jul 12 14:46:39 2011 +0200
+++ b/web/hdabo/templates/search/search.html	Tue Jul 12 18:24:30 2011 +0200
@@ -1,39 +1,50 @@
 {% extends 'hdabo_base.html' %}
 
 {% block content %}
-    <h2>Search</h2>
-
+    <h2>Recherche</h2>
+    
+    <div id="search_form">
     <form method="get" action=".">
         <table>
-            {{ form.as_table }}
+            <tr>
+                <th><label for="id_q">Recherche&nbsp:</label></th>
+                <td><input type="text" name="q" id="id_q" value="{{query}}"></td>
+            </tr>            
             <tr>
                 <td>&nbsp;</td>
                 <td>
-                    <input type="submit" value="Search">
+                    <input type="submit" value="Rechercher">
                 </td>
             </tr>
         </table>
-
+     </form>
+     </div>
+    <div id="search_results">
         {% if query %}
-            <h3>Results</h3>
-
+            <h3>Résultats</h3>
+            <div id="page_number">Page {{page.number}}/{{paginator.num_pages}}</div>
+            <table id="search_result">
             {% for result in page.object_list %}
-                <p>
-                    <a href="{{ result.object.get_absolute_url }}">{{ result.object.title }}</a>
-                </p>
+                <tr>
+                    <th class="result_counter">{{forloop.counter0|add:page.start_index}}.</th>
+	                <td>
+	                    <a href="{{ result.object.get_absolute_url }}" class="result_link" >{{ result.object.title }}</a>
+	                </td>
+                </tr>
+            
             {% empty %}
-                <p>No results found.</p>
+                <tr><td>Pas de résultats.</td></tr>
             {% endfor %}
+            </table>
 
             {% if page.has_previous or page.has_next %}
-                <div>
-                    {% if page.has_previous %}<a href="?q={{ query }}&amp;page={{ page.previous_page_number }}">{% endif %}&laquo; Previous{% if page.has_previous %}</a>{% endif %}
+                <div id="search_prev_next">                    
+                    {% if page.has_previous %}<a href="?q={{ query }}&amp;page={{ page.previous_page_number }}">{% endif %}&laquo; Prec.{% if page.has_previous %}</a>{% endif %}
                     |
-                    {% if page.has_next %}<a href="?q={{ query }}&amp;page={{ page.next_page_number }}">{% endif %}Next &raquo;{% if page.has_next %}</a>{% endif %}
+                    {% if page.has_next %}<a href="?q={{ query }}&amp;page={{ page.next_page_number }}">{% endif %}Suiv. &raquo;{% if page.has_next %}</a>{% endif %}
                 </div>
             {% endif %}
-        {% else %}
-            {# Show some example queries to run, maybe query syntax, something else? #}
         {% endif %}
-    </form>
+    </div>
+
 {% endblock %}
\ No newline at end of file