# HG changeset patch # User ymh # Date 1310430859 -7200 # Node ID 417938cf46016a0c940d9e362bc113150ba0013f # Parent 2ff78b3ac007dab65f54d3a07a9e58118f657a5f improve sort and add reverse order diff -r 2ff78b3ac007 -r 417938cf4601 web/hdabo/static/hdabo/img/sort-asc.png Binary file web/hdabo/static/hdabo/img/sort-asc.png has changed diff -r 2ff78b3ac007 -r 417938cf4601 web/hdabo/static/hdabo/img/sort-desc.png Binary file web/hdabo/static/hdabo/img/sort-desc.png has changed diff -r 2ff78b3ac007 -r 417938cf4601 web/hdabo/templates/all_tags.html --- a/web/hdabo/templates/all_tags.html Mon Jul 11 18:19:45 2011 +0200 +++ b/web/hdabo/templates/all_tags.html Tue Jul 12 02:34:19 2011 +0200 @@ -56,46 +56,46 @@ {% csrf_token %}

Chercher : {% for s in search_def %} - {{s.0}} + {{s.0}} {% endfor %}

Tags {{ current_page.start_index }} à {{ current_page.end_index }} sur {{ nb_total }}

{% if searched and searched != "" %} - <<   - <   + <<   + <   {{ num_page }}/{{ last_page }}   - >   - >>

+ >   + >>

{% else %} - <<   - <   + <<   + <   {{ num_page }}/{{ last_page }}   - >   - >> + >   + >> {% endif %}

- +
{% include "partial/all_tags_table.html" %}

{% if searched and searched != "" %} - <<   - <   + <<   + <   {{ num_page }}/{{ last_page }}   - >   - >>

+ >   + >>

{% else %} - <<   - <   + <<   + <   {{ num_page }}/{{ last_page }}   - >   - >> + >   + >> {% endif %}

{% endblock %} diff -r 2ff78b3ac007 -r 417938cf4601 web/hdabo/templates/partial/all_tags_table.html --- a/web/hdabo/templates/partial/all_tags_table.html Mon Jul 11 18:19:45 2011 +0200 +++ b/web/hdabo/templates/partial/all_tags_table.html Tue Jul 12 02:34:19 2011 +0200 @@ -2,13 +2,13 @@ @@ -18,13 +18,13 @@ {% for tag in tags %} diff -r 2ff78b3ac007 -r 417938cf4601 web/hdabo/urls.py --- a/web/hdabo/urls.py Mon Jul 11 18:19:45 2011 +0200 +++ b/web/hdabo/urls.py Tue Jul 12 02:34:19 2011 +0200 @@ -36,8 +36,8 @@ url(r'^alltags$', 'hdabo.views.all_tags'), url(r'^alltags/(?P[\w-]+)$', 'hdabo.views.all_tags'), url(r'^alltags/(?P[\w-]+)/(?P[\w-]+)/$', 'hdabo.views.all_tags'), - url(r'^alltags/(?P[\w-]+)/(?P[\w-]+)/(?P[\w-]+)/$', 'hdabo.views.all_tags'), - url(r'^alltags/(?P[\w-]+)/(?P[\w-]+)/(?P[\w-]+)/(?P.+)/$', 'hdabo.views.all_tags'), + url(r'^alltags/(?P[\w-]+)/(?P[\w-]+)/(?P[+-][\w]+)/$', 'hdabo.views.all_tags'), + url(r'^alltags/(?P[\w-]+)/(?P[\w-]+)/(?P[+-][\w]+)/(?P.+)/$', 'hdabo.views.all_tags'), url(r'^validatedatasheet$', 'hdabo.views.validate_datasheet'), url(r'^validatedatasheet/(?P[\w-]+)$', 'hdabo.views.validate_datasheet'), url(r'^validatedatasheet/(?P[\w-]+)/(?P[\w-]+)/$', 'hdabo.views.validate_datasheet'), diff -r 2ff78b3ac007 -r 417938cf4601 web/hdabo/views.py --- a/web/hdabo/views.py Mon Jul 11 18:19:45 2011 +0200 +++ b/web/hdabo/views.py Tue Jul 12 02:34:19 2011 +0200 @@ -183,7 +183,7 @@ @login_required -def all_tags(request, num_page=None, nb_by_page=None, alpha="false", searched=None): +def all_tags(request, num_page=None, nb_by_page=None, sort="+pop", 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 : @@ -192,7 +192,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, alpha, searched) + current_page, p, num_page, nb_by_page = get_current_page(num_page, nb_by_page, sort, searched) prev_page = max(num_page - 1, 1) next_page = min(num_page + 1, p.num_pages) @@ -212,13 +212,14 @@ cursor.close() search_def = tuple([(c, urlquote(c + settings.SEARCH_STAR_CHARACTER)) for c in fl_list]) + reverse_sort = ("-" if sort[0] == "+" else "+") + sort[1:] return render_to_response("all_tags.html", {'nb_total':p.count, 'tags':current_page.object_list, 'current_page':current_page, '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, 'alpha':alpha}, + 'search_def':search_def, 'sort':sort, 'reverse_sort': reverse_sort}, context_instance=RequestContext(request)) @@ -267,16 +268,17 @@ @login_required -def get_all_tags_table(request, num_page=None, nb_by_page=None, alpha="false", searched=None): +def get_all_tags_table(request, num_page=None, nb_by_page=None, sort="+pop", searched=None): - current_page, p, num_page, nb_by_page = get_current_page(num_page, nb_by_page, alpha, searched) #@UnusedVariable + current_page, p, num_page, nb_by_page = get_current_page(num_page, nb_by_page, sort, searched) #@UnusedVariable + reverse_sort = ("-" if sort[0] == "+" else "+") + sort[1:] return render_to_response("partial/all_tags_table.html", - {'tags':current_page.object_list, 'nb_by_page':nb_by_page, 'searched':searched}, + {'tags':current_page.object_list, 'nb_by_page':nb_by_page, 'searched':searched, 'sort': sort, 'reverse_sort': reverse_sort}, context_instance=RequestContext(request)) -def get_current_page(num_page=None, nb_by_page=None, alpha="false", searched=None): +def get_current_page(num_page=None, nb_by_page=None, sort="+pop", searched=None): base_queryset = Tag.objects @@ -286,11 +288,14 @@ base_queryset = base_queryset.filter(normalized_label__iregex=regex) alltags = base_queryset.annotate(num_ds=Count('datasheet')) - if alpha and (alpha == "true" or alpha == "1") : - alltags = alltags.order_by('normalized_label', 'label') - else : - alltags = alltags.order_by('-popularity', '-num_ds', 'normalized_label', 'label') - #alltags = alltags.order_by('-popularity','label') + + alltags = { + "+lab" : alltags.order_by('normalized_label', 'label'), + "-lab" : alltags.order_by('-normalized_label', '-label'), + "+pop" : alltags.order_by('-popularity', '-num_ds', 'normalized_label', 'label'), + "-pop" : alltags.order_by('+popularity', '+num_ds', '-normalized_label', '-label'), + }.get(sort, alltags.order_by('-popularity', '-num_ds', 'normalized_label', 'label')) + # We build the paginator for the requested list if nb_by_page : @@ -367,7 +372,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"], alpha=request.POST["alpha"], 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"], sort=request.POST["sort"], searched=request.POST["searched"]) @login_required @@ -431,7 +436,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"], alpha=request.POST["alpha"], 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"], sort=request.POST["sort"], searched=request.POST["searched"]) @login_required @@ -491,7 +496,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"], alpha=request.POST["alpha"], 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"], sort=request.POST["sort"], searched=request.POST["searched"]) @login_required @@ -537,7 +542,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"], alpha=request.POST["alpha"], 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"], sort=request.POST["sort"], searched=request.POST["searched"]) def get_categories():
id - {% if alpha != "true" and alpha != "1" %} + {% if sort|slice:"1:" != "lab" %} {% if searched and searched != "" %} - label + label {% else %} - label + label {% endif %} - {% else %}label{% endif %} + {% else %}label{% endif %}  original_label Lien WAlias Nb de
fiches
- {% if alpha == "true" or alpha == "1" %} + {% if sort|slice:"1:" != "pop" %} {% if searched and searched != "" %} - Popularité + Popularité {% else %} - Popularité + Popularité {% endif %} - {% else %}Popularité{% endif %} + {% else %}Popularité{% endif %}