title filter on renkan lists (personal, public and admin).
authorcavaliet
Fri, 26 Sep 2014 12:55:35 +0200
changeset 342 a0fa17c48236
parent 341 9a854bb09f34
child 343 12b6fc19d78f
title filter on renkan lists (personal, public and admin).
src/hdalab/static/hdalab/css/profile.css
src/hdalab/templates/editorial/manage_renkans.html
src/hdalab/templates/profile_home.html
src/hdalab/templates/renkan_list.html
src/hdalab/views/profile.py
--- a/src/hdalab/static/hdalab/css/profile.css	Thu Sep 25 17:14:29 2014 +0200
+++ b/src/hdalab/static/hdalab/css/profile.css	Fri Sep 26 12:55:35 2014 +0200
@@ -19,19 +19,11 @@
 	float: left;
 	margin-right: 5px;
 }
-.ui-icon-eye { background-position: -160px -144px; }
-/* sortable */
-.header{
-    background-image:url('../img/bg.gif');
-    background-repeat: no-repeat;
-    background-position: right center;
-    cursor: pointer;
+.ui-icon-eye {
+	background-position: -160px -144px;
 }
-.headerSortUp{
-    background-image: url('../img/asc.gif');
-}
-.headerSortDown{
-    background-image:url('../img/desc.gif');
+.inline{
+	display: inline-block;
 }
 
 /* editorialisation part */
--- a/src/hdalab/templates/editorial/manage_renkans.html	Thu Sep 25 17:14:29 2014 +0200
+++ b/src/hdalab/templates/editorial/manage_renkans.html	Fri Sep 26 12:55:35 2014 +0200
@@ -14,19 +14,20 @@
 {% endblock %}
 
 {% block main_content %}
-    <p>{% if page.has_previous %}<a href="?page={{ page.previous_page_number }}&sort={{ sort_param }}&order={{ order_param }}" >{% trans 'Previous' %}</a>{% endif %}
-       {% if page.has_previous and page.has_next %} - {% endif %}{% if page.has_next %}<a href="?page={{ page.next_page_number }}&sort={{ sort_param }}&order={{ order_param }}">{% trans 'Next' %}</a>{% endif %}</p>
+    <p class="inline">{% if page.has_previous %}<a href="?page={{ page.previous_page_number }}&sort={{ sort_param }}&order={{ order_param }}{% if filter|length > 0 %}&filter={{ filter }}{% endif %}" >{% trans 'Previous' %}</a>{% endif %}
+       {% if page.has_previous and page.has_next %} - {% endif %}{% if page.has_next %}<a href="?page={{ page.next_page_number }}&sort={{ sort_param }}&order={{ order_param }}{% if filter|length > 0 %}&filter={{ filter }}{% endif %}">{% trans 'Next' %}</a>{% endif %}</p>
+    <form class="inline"><p>{% if page.has_previous or page.has_next %} - {% endif %}{% trans 'Filter' %} : <input type="text" name="filter" value="{{ filter }}"/></p></form>
     <table id="rk-table">
       <thead>
         <tr class="border_bottom">
-          <th><a class="" href="?sort=title&order={% if sort_param == 'title' %}{{ opposite }}{% else %}asc{% endif %}">{% trans 'Title' %}</a>
+          <th><a class="" href="?sort=title&order={% if sort_param == 'title' %}{{ opposite }}{% else %}asc{% endif %}{% if filter|length > 0 %}&filter={{ filter }}{% endif %}">{% trans 'Title' %}</a>
               {% if sort_param == 'title' %}<span class="ui-icon {% if opposite == 'asc' %}ui-icon-triangle-1-s{% else %}ui-icon-triangle-1-n{% endif %}"></span>{% endif %}</th>
-          <th><a href="?sort=user&order={% if sort_param == 'user' %}{{ opposite }}{% else %}desc{% endif %}">{% trans 'User' %}</a>
+          <th><a href="?sort=user&order={% if sort_param == 'user' %}{{ opposite }}{% else %}desc{% endif %}{% if filter|length > 0 %}&filter={{ filter }}{% endif %}">{% trans 'User' %}</a>
               {% if sort_param == 'user' %}<span class="ui-icon {% if opposite == 'asc' %}ui-icon-triangle-1-s{% else %}ui-icon-triangle-1-n{% endif %}"></span>{% endif %}</th>
-          <th><a href="?sort=date&order={% if sort_param == 'date' %}{{ opposite }}{% else %}desc{% endif %}">{% trans 'Modification date' %}</a>
+          <th><a href="?sort=date&order={% if sort_param == 'date' %}{{ opposite }}{% else %}desc{% endif %}{% if filter|length > 0 %}&filter={{ filter }}{% endif %}">{% trans 'Modification date' %}</a>
               {% if sort_param == 'date' %}<span class="ui-icon {% if opposite == 'asc' %}ui-icon-triangle-1-s{% else %}ui-icon-triangle-1-n{% endif %}"></span>{% endif %}</th>
           <th>{% trans 'Preview' %}</th>
-          <th><a href="?sort=state&order={% if sort_param == 'state' %}{{ opposite }}{% else %}asc{% endif %}">{% trans 'State' %}</a>
+          <th><a href="?sort=state&order={% if sort_param == 'state' %}{{ opposite }}{% else %}asc{% endif %}{% if filter|length > 0 %}&filter={{ filter }}{% endif %}">{% trans 'State' %}</a>
               {% if sort_param == 'state' %}<span class="ui-icon {% if opposite == 'asc' %}ui-icon-triangle-1-s{% else %}ui-icon-triangle-1-n{% endif %}"></span>{% endif %}</th>
           <th>{% trans 'Actions' %}</th>
         </tr>
@@ -51,6 +52,6 @@
       {% endfor %}
       </tbody>
     </table>
-    <p>{% if page.has_previous %}<a href="?page={{ page.previous_page_number }}&sort={{ sort_param }}&order={{ order_param }}" >{% trans 'Previous' %}</a>{% endif %}
-       {% if page.has_previous and page.has_next %} - {% endif %}{% if page.has_next %}<a href="?page={{ page.next_page_number }}&sort={{ sort_param }}&order={{ order_param }}">{% trans 'Next' %}</a>{% endif %}</p>
+    <p>{% if page.has_previous %}<a href="?page={{ page.previous_page_number }}&sort={{ sort_param }}&order={{ order_param }}{% if filter|length > 0 %}&filter={{ filter }}{% endif %}" >{% trans 'Previous' %}</a>{% endif %}
+       {% if page.has_previous and page.has_next %} - {% endif %}{% if page.has_next %}<a href="?page={{ page.next_page_number }}&sort={{ sort_param }}&order={{ order_param }}{% if filter|length > 0 %}&filter={{ filter }}{% endif %}">{% trans 'Next' %}</a>{% endif %}</p>
 {% endblock %}
\ No newline at end of file
--- a/src/hdalab/templates/profile_home.html	Thu Sep 25 17:14:29 2014 +0200
+++ b/src/hdalab/templates/profile_home.html	Fri Sep 26 12:55:35 2014 +0200
@@ -20,17 +20,18 @@
     <p><a href="{% url 'renkan_new' %}" >Nouveau Renkan</a> - <a href="{% url 'auth_password_change' %}">Modification du mot de passe</a></p>
     <p>&nbsp;</p>
     <p>Mes renkans : </p>
-    <p>{% if page.has_previous %}<a href="?page={{ page.previous_page_number }}&sort={{ sort_param }}&order={{ order_param }}" >{% trans 'Previous' %}</a>{% endif %}
-       {% if page.has_previous and page.has_next %} - {% endif %}{% if page.has_next %}<a href="?page={{ page.next_page_number }}&sort={{ sort_param }}&order={{ order_param }}">{% trans 'Next' %}</a>{% endif %}</p>
+    <p class="inline">{% if page.has_previous %}<a href="?page={{ page.previous_page_number }}&sort={{ sort_param }}&order={{ order_param }}{% if filter|length > 0 %}&filter={{ filter }}{% endif %}" >{% trans 'Previous' %}</a>{% endif %}
+       {% if page.has_previous and page.has_next %} - {% endif %}{% if page.has_next %}<a href="?page={{ page.next_page_number }}&sort={{ sort_param }}&order={{ order_param }}{% if filter|length > 0 %}&filter={{ filter }}{% endif %}">{% trans 'Next' %}</a>{% endif %}</p>
+    <form class="inline"><p>{% if page.has_previous or page.has_next %} - {% endif %}{% trans 'Filter' %} : <input type="text" name="filter" value="{{ filter }}"/></p></form>
     <table id="rk-table">
       <thead>
         <tr class="border_bottom">
-          <th><a href="?sort=title&order={% if sort_param == 'title' %}{{ opposite }}{% else %}asc{% endif %}">{% trans 'Title' %}</a>
+          <th><a href="?sort=title&order={% if sort_param == 'title' %}{{ opposite }}{% else %}asc{% endif %}{% if filter|length > 0 %}&filter={{ filter }}{% endif %}">{% trans 'Title' %}</a>
               {% if sort_param == 'title' %}<span class="ui-icon {% if opposite == 'asc' %}ui-icon-triangle-1-s{% else %}ui-icon-triangle-1-n{% endif %}"></span>{% endif %}</th>
-          <th><a href="?sort=date&order={% if sort_param == 'date' %}{{ opposite }}{% else %}desc{% endif %}">{% trans 'Modification date' %}</a>
+          <th><a href="?sort=date&order={% if sort_param == 'date' %}{{ opposite }}{% else %}desc{% endif %}{% if filter|length > 0 %}&filter={{ filter }}{% endif %}">{% trans 'Modification date' %}</a>
               {% if sort_param == 'date' %}<span class="ui-icon {% if opposite == 'asc' %}ui-icon-triangle-1-s{% else %}ui-icon-triangle-1-n{% endif %}"></span>{% endif %}</th>
           <th>{% trans 'Preview' %}</th>
-          <th><a href="?sort=state&order={% if sort_param == 'state' %}{{ opposite }}{% else %}asc{% endif %}">{% trans 'State' %}</a>
+          <th><a href="?sort=state&order={% if sort_param == 'state' %}{{ opposite }}{% else %}asc{% endif %}{% if filter|length > 0 %}&filter={{ filter }}{% endif %}">{% trans 'State' %}</a>
               {% if sort_param == 'state' %}<span class="ui-icon {% if opposite == 'asc' %}ui-icon-triangle-1-s{% else %}ui-icon-triangle-1-n{% endif %}"></span>{% endif %}</th>
           <th>{% trans 'Actions' %}</th>
         </tr>
@@ -57,6 +58,6 @@
       {% endfor %}
       </tbody>
     </table>
-    <p>{% if page.has_previous %}<a href="?page={{ page.previous_page_number }}&sort={{ sort_param }}&order={{ order_param }}" >{% trans 'Previous' %}</a>{% endif %}
-       {% if page.has_previous and page.has_next %} - {% endif %}{% if page.has_next %}<a href="?page={{ page.next_page_number }}&sort={{ sort_param }}&order={{ order_param }}">{% trans 'Next' %}</a>{% endif %}</p>
+    <p>{% if page.has_previous %}<a href="?page={{ page.previous_page_number }}&sort={{ sort_param }}&order={{ order_param }}{% if filter|length > 0 %}&filter={{ filter }}{% endif %}" >{% trans 'Previous' %}</a>{% endif %}
+       {% if page.has_previous and page.has_next %} - {% endif %}{% if page.has_next %}<a href="?page={{ page.next_page_number }}&sort={{ sort_param }}&order={{ order_param }}{% if filter|length > 0 %}&filter={{ filter }}{% endif %}">{% trans 'Next' %}</a>{% endif %}</p>
 {% endblock %}
\ No newline at end of file
--- a/src/hdalab/templates/renkan_list.html	Thu Sep 25 17:14:29 2014 +0200
+++ b/src/hdalab/templates/renkan_list.html	Fri Sep 26 12:55:35 2014 +0200
@@ -16,14 +16,15 @@
 
 {% block main_content %}
     <h2>Liste des renkans publiques</h2>
-    <p>{% if page.has_previous %}<a href="?page={{ page.previous_page_number }}&sort={{ sort_param }}&order={{ order_param }}" >{% trans 'Previous' %}</a>{% endif %}
-       {% if page.has_previous and page.has_next %} - {% endif %}{% if page.has_next %}<a href="?page={{ page.next_page_number }}&sort={{ sort_param }}&order={{ order_param }}">{% trans 'Next' %}</a>{% endif %}</p>
+    <p class="inline">{% if page.has_previous %}<a href="?page={{ page.previous_page_number }}&sort={{ sort_param }}&order={{ order_param }}{% if filter|length > 0 %}&filter={{ filter }}{% endif %}" >{% trans 'Previous' %}</a>{% endif %}
+       {% if page.has_previous and page.has_next %} - {% endif %}{% if page.has_next %}<a href="?page={{ page.next_page_number }}&sort={{ sort_param }}&order={{ order_param }}{% if filter|length > 0 %}&filter={{ filter }}{% endif %}">{% trans 'Next' %}</a>{% endif %}</p>
+    <form class="inline"><p>{% if page.has_previous or page.has_next %} - {% endif %}{% trans 'Filter' %} : <input type="text" name="filter" value="{{ filter }}"/></p></form>
     <table id="rk-table">
       <thead>
         <tr class="border_bottom">
-          <th><a class="" href="?sort=title&order={% if sort_param == 'title' %}{{ opposite }}{% else %}asc{% endif %}">{% trans 'Title' %}</a>
+          <th><a class="" href="?sort=title&order={% if sort_param == 'title' %}{{ opposite }}{% else %}asc{% endif %}{% if filter|length > 0 %}&filter={{ filter }}{% endif %}">{% trans 'Title' %}</a>
               {% if sort_param == 'title' %}<span class="ui-icon {% if opposite == 'asc' %}ui-icon-triangle-1-s{% else %}ui-icon-triangle-1-n{% endif %}"></span>{% endif %}</th>
-          <th><a href="?sort=date&order={% if sort_param == 'date' %}{{ opposite }}{% else %}desc{% endif %}">{% trans 'Modification date' %}</a>
+          <th><a href="?sort=date&order={% if sort_param == 'date' %}{{ opposite }}{% else %}desc{% endif %}{% if filter|length > 0 %}&filter={{ filter }}{% endif %}">{% trans 'Modification date' %}</a>
               {% if sort_param == 'date' %}<span class="ui-icon {% if opposite == 'asc' %}ui-icon-triangle-1-s{% else %}ui-icon-triangle-1-n{% endif %}"></span>{% endif %}</th>
           <th>Preview</th><th>Actions</th></tr>
       </thead>
@@ -43,6 +44,6 @@
       {% endfor %}
       </tbody>
     </table>
-    <p>{% if page.has_previous %}<a href="?page={{ page.previous_page_number }}&sort={{ sort_param }}&order={{ order_param }}" >{% trans 'Previous' %}</a>{% endif %}
-       {% if page.has_previous and page.has_next %} - {% endif %}{% if page.has_next %}<a href="?page={{ page.next_page_number }}&sort={{ sort_param }}&order={{ order_param }}">{% trans 'Next' %}</a>{% endif %}</p>
+    <p>{% if page.has_previous %}<a href="?page={{ page.previous_page_number }}&sort={{ sort_param }}&order={{ order_param }}{% if filter|length > 0 %}&filter={{ filter }}{% endif %}" >{% trans 'Previous' %}</a>{% endif %}
+       {% if page.has_previous and page.has_next %} - {% endif %}{% if page.has_next %}<a href="?page={{ page.next_page_number }}&sort={{ sort_param }}&order={{ order_param }}{% if filter|length > 0 %}&filter={{ filter }}{% endif %}">{% trans 'Next' %}</a>{% endif %}</p>
 {% endblock %}
\ No newline at end of file
--- a/src/hdalab/views/profile.py	Thu Sep 25 17:14:29 2014 +0200
+++ b/src/hdalab/views/profile.py	Fri Sep 26 12:55:35 2014 +0200
@@ -45,6 +45,10 @@
     
     def update_context(self, context, renkan_queryset):
         
+        filter_title = self.request.GET.get("filter", "")
+        if(len(filter_title)>0):
+            renkan_queryset = renkan_queryset.filter(renkan__title__icontains=filter_title)
+        
         sort_param = self.request.GET.get('sort', "date")
         order_param = self.request.GET.get('order', "desc")
         sort = {"date":"renkan__modification_date", "title":"renkan__title", "state":"state", "user":"renkan__owner__username"}.get(sort_param)
@@ -55,8 +59,8 @@
             order = ""
             opposite = "desc"
         
-        rl = renkan_queryset.order_by(order + sort)
-        p = Paginator(rl, settings.RENKANS_PER_PAGE)
+        renkan_queryset = renkan_queryset.order_by(order + sort)
+        p = Paginator(renkan_queryset, settings.RENKANS_PER_PAGE)
         page_nb = self.request.GET.get('page')
         try:
             page = p.page(page_nb)
@@ -65,7 +69,7 @@
         except EmptyPage:
             page = p.page(p.num_pages)
         
-        context.update({"page": page, "sort_param":sort_param, "order_param":order_param, "opposite":opposite})
+        context.update({"page": page, "sort_param":sort_param, "order_param":order_param, "opposite":opposite, "filter":filter_title})
         
         return context
 
@@ -76,7 +80,7 @@
     template_name = "profile_home.html"
     
     def get_context_data(self, **kwargs):
-        return self.update_context( super(ProfileHome, self).get_context_data(**kwargs), HdalabRenkan.objects.select_related("renkan").filter(renkan__owner=self.request.user) )
+        return self.update_context( super(ProfileHome, self).get_context_data(**kwargs), HdalabRenkan.objects.select_related("renkan").filter(renkan__owner=self.request.user))
 
 
 class RenkanPublicList(BaseRenkanList):