Add alphabetical sort on tag list.
authorcavaliet
Fri, 08 Jul 2011 11:55:25 +0200
changeset 71 579ac2e2789a
parent 70 c86fa4a358d7
child 73 83695a58e4d6
Add alphabetical sort on tag list.
web/hdabo/static/hdabo/js/hdabo.js
web/hdabo/templates/all_tags.html
web/hdabo/templates/partial/all_tags_table.html
web/hdabo/urls.py
web/hdabo/views.py
--- a/web/hdabo/static/hdabo/js/hdabo.js	Fri Jul 08 03:23:20 2011 +0200
+++ b/web/hdabo/static/hdabo/js/hdabo.js	Fri Jul 08 11:55:25 2011 +0200
@@ -35,6 +35,7 @@
             datasheet_id:$('#datasheet_id').val(),
             num_page:$('#num_page').val(),
             nb_by_page:$('#nb_by_page').val(),
+            alpha:$('#alpha').val(),
             searched:$('#searched_str').val()
         },
     	callback  : function(value, settings) {
@@ -90,6 +91,7 @@
             datasheet_id:$('#datasheet_id').val(),
             num_page:$('#num_page').val(),
             nb_by_page:$('#nb_by_page').val(),
+            alpha:$('#alpha').val(),
             searched:$('#searched_str').val()
         },
     	callback  : function(value, settings) {
@@ -111,6 +113,7 @@
             datasheet_id:$('#datasheet_id').val(),
             num_page:$('#num_page').val(),
             nb_by_page:$('#nb_by_page').val(),
+            alpha:$('#alpha').val(),
             searched:$('#searched_str').val()
         },
     	callback  : function(value, settings) {
@@ -245,6 +248,7 @@
                datasheet_id:$('#datasheet_id').val(),
                num_page:$('#num_page').val(),
                nb_by_page:$('#nb_by_page').val(),
+               alpha:$('#alpha').val(),
                searched:$('#searched_str').val(),
                tag_id:id_tag,
                activated:new_checked
--- a/web/hdabo/templates/all_tags.html	Fri Jul 08 03:23:20 2011 +0200
+++ b/web/hdabo/templates/all_tags.html	Fri Jul 08 11:55:25 2011 +0200
@@ -56,45 +56,46 @@
     {% csrf_token %}
     <p>Chercher : 
     {% for s in search_def %}
-    <a href="{% url hdabo.views.all_tags num_page=1, nb_by_page=nb_by_page, searched=s.1 %}">{{s.0}}</a>
+    <a href="{% url hdabo.views.all_tags num_page=1, nb_by_page=nb_by_page, alpha=alpha, searched=s.1 %}">{{s.0}}</a>
     {% endfor %}
     <input type="text" name="searched" value="{% if searched %}{{searched}}{% endif %}" id="searched" />
     </p>
     <p>Tags {{ current_page.start_index }} à {{ current_page.end_index }} sur {{ nb_total }}</p>
     <div id="count_nav_top"><p>
         {% if searched and searched != "" %}
-            <a href="{% url hdabo.views.all_tags num_page=1, nb_by_page=nb_by_page, searched=searched %}">&lt;&lt;</a>&nbsp;&nbsp;
-            <a href="{% url hdabo.views.all_tags num_page=prev_page, nb_by_page=nb_by_page, searched=searched %}">&lt;</a>&nbsp;&nbsp;
+            <a href="{% url hdabo.views.all_tags num_page=1, nb_by_page=nb_by_page, alpha=alpha, searched=searched %}">&lt;&lt;</a>&nbsp;&nbsp;
+            <a href="{% url hdabo.views.all_tags num_page=prev_page, nb_by_page=nb_by_page, alpha=alpha, searched=searched %}">&lt;</a>&nbsp;&nbsp;
             {{ num_page }}/{{ last_page }}&nbsp;&nbsp;
-            <a href="{% url hdabo.views.all_tags num_page=next_page, nb_by_page=nb_by_page, searched=searched %}">&gt;</a>&nbsp;&nbsp;
-            <a href="{% url hdabo.views.all_tags num_page=last_page, nb_by_page=nb_by_page, searched=searched %}">&gt;&gt;</a></p>
+            <a href="{% url hdabo.views.all_tags num_page=next_page, nb_by_page=nb_by_page, alpha=alpha, searched=searched %}">&gt;</a>&nbsp;&nbsp;
+            <a href="{% url hdabo.views.all_tags num_page=last_page, nb_by_page=nb_by_page, alpha=alpha, searched=searched %}">&gt;&gt;</a></p>
         {% else %}
-            <a href="{% url hdabo.views.all_tags num_page=1, nb_by_page=nb_by_page %}">&lt;&lt;</a>&nbsp;&nbsp;
-            <a href="{% url hdabo.views.all_tags num_page=prev_page, nb_by_page=nb_by_page %}">&lt;</a>&nbsp;&nbsp;
+            <a href="{% url hdabo.views.all_tags num_page=1, nb_by_page=nb_by_page, alpha=alpha %}">&lt;&lt;</a>&nbsp;&nbsp;
+            <a href="{% url hdabo.views.all_tags num_page=prev_page, nb_by_page=nb_by_page, alpha=alpha %}">&lt;</a>&nbsp;&nbsp;
             {{ num_page }}/{{ last_page }}&nbsp;&nbsp;
-            <a href="{% url hdabo.views.all_tags num_page=next_page, nb_by_page=nb_by_page %}">&gt;</a>&nbsp;&nbsp;
-            <a href="{% url hdabo.views.all_tags num_page=last_page, nb_by_page=nb_by_page %}">&gt;&gt;</a>
+            <a href="{% url hdabo.views.all_tags num_page=next_page, nb_by_page=nb_by_page, alpha=alpha %}">&gt;</a>&nbsp;&nbsp;
+            <a href="{% url hdabo.views.all_tags num_page=last_page, nb_by_page=nb_by_page, alpha=alpha %}">&gt;&gt;</a>
         {% endif %}</p>
     </div>
     <input type="hidden" name="num_page" value="{{num_page}}" id="num_page" />
     <input type="hidden" name="nb_by_page" value="{{nb_by_page}}" id="nb_by_page" />
     <input type="hidden" name="searched_str" value="{% if searched %}{{searched}}{% endif %}" id="searched_str" />
+    <input type="hidden" name="alpha" value="{% if alpha %}{{alpha}}{% endif %}" id="alpha" />
     <div id="tag_table_container">
     {% include "partial/all_tags_table.html" %}
     </div>
     <div id="count_nav_bottom"><p>
         {% if searched and searched != "" %}
-            <a href="{% url hdabo.views.all_tags num_page=1, nb_by_page=nb_by_page, searched=searched %}">&lt;&lt;</a>&nbsp;&nbsp;
-            <a href="{% url hdabo.views.all_tags num_page=prev_page, nb_by_page=nb_by_page, searched=searched %}">&lt;</a>&nbsp;&nbsp;
+            <a href="{% url hdabo.views.all_tags num_page=1, nb_by_page=nb_by_page, alpha=alpha, searched=searched %}">&lt;&lt;</a>&nbsp;&nbsp;
+            <a href="{% url hdabo.views.all_tags num_page=prev_page, nb_by_page=nb_by_page, alpha=alpha, searched=searched %}">&lt;</a>&nbsp;&nbsp;
             {{ num_page }}/{{ last_page }}&nbsp;&nbsp;
-            <a href="{% url hdabo.views.all_tags num_page=next_page, nb_by_page=nb_by_page, searched=searched %}">&gt;</a>&nbsp;&nbsp;
-            <a href="{% url hdabo.views.all_tags num_page=last_page, nb_by_page=nb_by_page, searched=searched %}">&gt;&gt;</a></p>
+            <a href="{% url hdabo.views.all_tags num_page=next_page, nb_by_page=nb_by_page, alpha=alpha, searched=searched %}">&gt;</a>&nbsp;&nbsp;
+            <a href="{% url hdabo.views.all_tags num_page=last_page, nb_by_page=nb_by_page, alpha=alpha, searched=searched %}">&gt;&gt;</a></p>
         {% else %}
-            <a href="{% url hdabo.views.all_tags num_page=1, nb_by_page=nb_by_page %}">&lt;&lt;</a>&nbsp;&nbsp;
-            <a href="{% url hdabo.views.all_tags num_page=prev_page, nb_by_page=nb_by_page %}">&lt;</a>&nbsp;&nbsp;
+            <a href="{% url hdabo.views.all_tags num_page=1, nb_by_page=nb_by_page, alpha=alpha %}">&lt;&lt;</a>&nbsp;&nbsp;
+            <a href="{% url hdabo.views.all_tags num_page=prev_page, nb_by_page=nb_by_page, alpha=alpha %}">&lt;</a>&nbsp;&nbsp;
             {{ num_page }}/{{ last_page }}&nbsp;&nbsp;
-            <a href="{% url hdabo.views.all_tags num_page=next_page, nb_by_page=nb_by_page %}">&gt;</a>&nbsp;&nbsp;
-            <a href="{% url hdabo.views.all_tags num_page=last_page, nb_by_page=nb_by_page %}">&gt;&gt;</a>
+            <a href="{% url hdabo.views.all_tags num_page=next_page, nb_by_page=nb_by_page, alpha=alpha %}">&gt;</a>&nbsp;&nbsp;
+            <a href="{% url hdabo.views.all_tags num_page=last_page, nb_by_page=nb_by_page, alpha=alpha %}">&gt;&gt;</a>
         {% endif %}</p>
     </div>
     {% endblock %}
--- a/web/hdabo/templates/partial/all_tags_table.html	Fri Jul 08 03:23:20 2011 +0200
+++ b/web/hdabo/templates/partial/all_tags_table.html	Fri Jul 08 11:55:25 2011 +0200
@@ -1,7 +1,15 @@
 {% block tag_table %}
 	<table id="all_tags_table">
     <tr><th>id</th>
-        <th>label</th>
+        <th>
+        {% if alpha != "true" and alpha != "1" %}
+ 	        {% if searched and searched != "" %}
+	            <a href="{% url hdabo.views.all_tags num_page='1', nb_by_page=nb_by_page, alpha='true', searched=searched %}">label</a>
+	        {% else %}
+	            <a href="{% url hdabo.views.all_tags num_page='1', nb_by_page=nb_by_page, alpha='true' %}">label</a>
+	        {% endif %}
+        {% else %}label{% endif %}
+        </th>
         {% comment %}<th>original_label</th>{% endcomment %}
         <th class="text_centered">Lien W</th>
         <th class="text_centered">Lien D</th>
@@ -9,7 +17,15 @@
         <th class="large_25 text_centered">Supprimer<br/>le lien W</th>
         <th>Alias</th>
         <th class="text_centered">Nb de<br/>fiches</th>
-        <th>Popularité</th></tr>
+        <th>
+        {% if alpha == "true" or alpha == "1" %}
+ 	        {% if searched and searched != "" %}
+	            <a href="{% url hdabo.views.all_tags num_page='1', nb_by_page=nb_by_page, alpha='false', searched=searched %}">Popularité</a>
+	        {% else %}
+	            <a href="{% url hdabo.views.all_tags num_page='1', nb_by_page=nb_by_page, alpha='false' %}">Popularité</a>
+	        {% endif %}
+        {% else %}Popularité{% endif %}
+        </th></tr>
     {% for tag in tags %}
     <tr class="imageline {% cycle 'hdabooddline' 'hdaboevenline' %}">
         <td class="reset_wp_info">{{tag.id}}</td>
--- a/web/hdabo/urls.py	Fri Jul 08 03:23:20 2011 +0200
+++ b/web/hdabo/urls.py	Fri Jul 08 11:55:25 2011 +0200
@@ -36,7 +36,8 @@
     url(r'^alltags$', 'hdabo.views.all_tags'),
     url(r'^alltags/(?P<num_page>[\w-]+)$', 'hdabo.views.all_tags'),
     url(r'^alltags/(?P<num_page>[\w-]+)/(?P<nb_by_page>[\w-]+)/$', 'hdabo.views.all_tags'),
-    url(r'^alltags/(?P<num_page>[\w-]+)/(?P<nb_by_page>[\w-]+)/(?P<searched>.+)/$', 'hdabo.views.all_tags'),
+    url(r'^alltags/(?P<num_page>[\w-]+)/(?P<nb_by_page>[\w-]+)/(?P<alpha>[\w-]+)/$', 'hdabo.views.all_tags'),
+    url(r'^alltags/(?P<num_page>[\w-]+)/(?P<nb_by_page>[\w-]+)/(?P<alpha>[\w-]+)/(?P<searched>.+)/$', 'hdabo.views.all_tags'),
     url(r'^validatedatasheet$', 'hdabo.views.validate_datasheet'),
     url(r'^validatedatasheet/(?P<ds_id>[\w-]+)$', 'hdabo.views.validate_datasheet'),
     url(r'^validatedatasheet/(?P<ds_id>[\w-]+)/(?P<valid>[\w-]+)/$', 'hdabo.views.validate_datasheet'),
--- a/web/hdabo/views.py	Fri Jul 08 03:23:20 2011 +0200
+++ b/web/hdabo/views.py	Fri Jul 08 11:55:25 2011 +0200
@@ -184,7 +184,7 @@
 
 
 @login_required
-def all_tags(request, num_page=None, nb_by_page=None, searched=None):
+def all_tags(request, num_page=None, nb_by_page=None, alpha="false", searched=None):
     
     # If the view is asked after a form sent with post vars, it means that searched is a post var.
     if u"searched" in request.POST :
@@ -193,7 +193,7 @@
         num_page = 1
     
     # Get paginator and current page 
-    current_page, p, num_page, nb_by_page = get_current_page(num_page, nb_by_page, searched)
+    current_page, p, num_page, nb_by_page = get_current_page(num_page, nb_by_page, alpha, searched)
     
     prev_page = max(num_page - 1, 1)
     next_page = min(num_page + 1, p.num_pages)
@@ -219,7 +219,7 @@
                                'prev_page':prev_page, 'next_page':next_page, 'last_page':last_page,
                                'num_page':num_page, 'nb_by_page':nb_by_page, 'searched':searched,
                                'categories':json.dumps(get_categories()),
-                               'search_def':search_def, 'searched':searched},
+                               'search_def':search_def, 'alpha':alpha},
                               context_instance=RequestContext(request))
     
 
@@ -268,16 +268,16 @@
 
 
 @login_required
-def get_all_tags_table(request, num_page=None, nb_by_page=None, searched=None):
+def get_all_tags_table(request, num_page=None, nb_by_page=None, alpha="false", searched=None):
     
-    current_page, p, num_page, nb_by_page = get_current_page(num_page, nb_by_page, searched) #@UnusedVariable
+    current_page, p, num_page, nb_by_page = get_current_page(num_page, nb_by_page, alpha, searched) #@UnusedVariable
     
     return render_to_response("partial/all_tags_table.html",
-                              {'tags':current_page.object_list},
+                              {'tags':current_page.object_list, 'nb_by_page':nb_by_page, 'searched':searched},
                               context_instance=RequestContext(request))
 
 
-def get_current_page(num_page=None, nb_by_page=None, searched=None):
+def get_current_page(num_page=None, nb_by_page=None, alpha="false", searched=None):
     
     base_queryset = Tag.objects
     
@@ -285,8 +285,10 @@
         searched = searched.strip()
         regex = "^%s$" % (re.escape(searched).replace(re.escape(settings.SEARCH_STAR_CHARACTER),".*"))
         base_queryset = base_queryset.filter(label__iregex=regex)
-
-    alltags = base_queryset.annotate(num_ds=Count('datasheet')).order_by('-popularity','-num_ds','label')
+    if alpha and (alpha=="true" or alpha=="1") :
+        alltags = base_queryset.annotate(num_ds=Count('datasheet')).order_by('label')
+    else :
+        alltags = base_queryset.annotate(num_ds=Count('datasheet')).order_by('-popularity','-num_ds','label')
     #alltags = alltags.order_by('-popularity','label')
     
     # We build the paginator for the requested list
@@ -361,7 +363,7 @@
         if old_pageid != pageid:
             TaggedSheet.objects.filter(tag=tag).update(wikipedia_revision_id=revision_id)
     
-    return get_all_tags_table(request=request, num_page=request.POST["num_page"], nb_by_page=request.POST["nb_by_page"], searched=request.POST["searched"])
+    return get_all_tags_table(request=request, num_page=request.POST["num_page"], nb_by_page=request.POST["nb_by_page"], alpha=request.POST["alpha"], searched=request.POST["searched"])
 
 
 @login_required
@@ -422,7 +424,7 @@
     if u"datasheet_id" in request.POST :
         return get_tag_table(request=request, ds_id=request.POST["datasheet_id"], valid=0)
     else :
-        return get_all_tags_table(request=request, num_page=request.POST["num_page"], nb_by_page=request.POST["nb_by_page"], searched=request.POST["searched"])
+        return get_all_tags_table(request=request, num_page=request.POST["num_page"], nb_by_page=request.POST["nb_by_page"], alpha=request.POST["alpha"], searched=request.POST["searched"])
 
 
 @login_required
@@ -479,7 +481,7 @@
     if u"datasheet_id" in request.POST :
         return get_tag_table(request=request, ds_id=request.POST["datasheet_id"], valid=0)
     else :
-        return get_all_tags_table(request=request, num_page=request.POST["num_page"], nb_by_page=request.POST["nb_by_page"], searched=request.POST["searched"])
+        return get_all_tags_table(request=request, num_page=request.POST["num_page"], nb_by_page=request.POST["nb_by_page"], alpha=request.POST["alpha"], searched=request.POST["searched"])
 
 
 @login_required
@@ -525,7 +527,7 @@
     if u"datasheet_id" in request.POST :
         return get_tag_table(request=request, ds_id=request.POST["datasheet_id"], valid=0)
     else :
-        return get_all_tags_table(request=request, num_page=request.POST["num_page"], nb_by_page=request.POST["nb_by_page"], searched=request.POST["searched"])
+        return get_all_tags_table(request=request, num_page=request.POST["num_page"], nb_by_page=request.POST["nb_by_page"], alpha=request.POST["alpha"], searched=request.POST["searched"])
     
 
 def get_categories():
@@ -551,6 +553,6 @@
     if u"datasheet_id" in request.POST :
         return get_tag_table(request=request, ds_id=request.POST["datasheet_id"], valid=0)
     else :
-        return get_all_tags_table(request=request, num_page=request.POST["num_page"], nb_by_page=request.POST["nb_by_page"], searched=request.POST["searched"])
+        return get_all_tags_table(request=request, num_page=request.POST["num_page"], nb_by_page=request.POST["nb_by_page"], alpha=request.POST["alpha"], searched=request.POST["searched"])