improve tag letter list
authorymh <ymh.work@gmail.com>
Fri, 24 Jun 2011 03:31:05 +0200
changeset 56 e70cbbc093cc
parent 55 e1098febb9d3
child 57 9eddefcafe8e
improve tag letter list
virtualenv/res/src/django-debug-toolbar.tar.gz
web/hdabo/settings.py
web/hdabo/static/hdabo/img/favicon.ico
web/hdabo/static/hdabo/js/hdabo.js
web/hdabo/templates/list_for_orga.html
web/hdabo/templates/partial/one_sheet.html
web/hdabo/utils.py
web/hdabo/views.py
Binary file virtualenv/res/src/django-debug-toolbar.tar.gz has changed
--- a/web/hdabo/settings.py	Thu Jun 23 16:00:38 2011 +0200
+++ b/web/hdabo/settings.py	Fri Jun 24 03:31:05 2011 +0200
@@ -111,16 +111,8 @@
     'django.middleware.csrf.CsrfViewMiddleware',
     'django.contrib.auth.middleware.AuthenticationMiddleware',
     'django.contrib.messages.middleware.MessageMiddleware',
-    #django-debug-toolbar
-    'debug_toolbar.middleware.DebugToolbarMiddleware',
 )
 
-#django-debug-toolbar
-INTERNAL_IPS = ('127.0.0.1','localhost',)
-DEBUG_TOOLBAR_CONFIG = { 
-    'SHOW_TOOLBAR_CALLBACK': lambda(req): True,
-} 
-
 
 ROOT_URLCONF = 'hdabo.urls'
 
@@ -141,8 +133,6 @@
     'django_extensions',
     'haystack',
     'hdabo',
-    #django-debug-toolbar
-    'debug_toolbar',
 )
 
 # A sample logging configuration. The only tangible logging
Binary file web/hdabo/static/hdabo/img/favicon.ico has changed
--- a/web/hdabo/static/hdabo/js/hdabo.js	Thu Jun 23 16:00:38 2011 +0200
+++ b/web/hdabo/static/hdabo/js/hdabo.js	Fri Jun 24 03:31:05 2011 +0200
@@ -123,7 +123,7 @@
         onDragClass: "dragged_row",
         onDrop: function(table, row){
             old_order = row.id;
-            $($(row).children()[1]).html("<img src='"+static_url+"hdabo/img/indicator.gif'>");
+            $($(row).children()[1]).html("<img src='"+static_url+"hdabo/img/indicator.gif'/>");
             rows = table.tBodies[0].rows;
             nb_rows = rows.length;
             for(var i=1; i<nb_rows; i++){
--- a/web/hdabo/templates/list_for_orga.html	Thu Jun 23 16:00:38 2011 +0200
+++ b/web/hdabo/templates/list_for_orga.html	Fri Jun 24 03:31:05 2011 +0200
@@ -3,9 +3,9 @@
 
     {% block js_import %}
     {{block.super}}
+    <script type="text/javascript" src="{{STATIC_URL}}hdabo/js/jquery.tablednd_0_5.js"></script>
     <script type="text/javascript" src="{{STATIC_URL}}hdabo/js/jquery-ui.min.js"></script>
     <script type="text/javascript" src="{{STATIC_URL}}hdabo/js/jquery.jeditable.js"></script>
-    <script type="text/javascript" src="{{STATIC_URL}}hdabo/js/jquery.tablednd_0_5.js"></script>
     {% endblock %}
     
     {% block js_declaration %}
--- a/web/hdabo/templates/partial/one_sheet.html	Thu Jun 23 16:00:38 2011 +0200
+++ b/web/hdabo/templates/partial/one_sheet.html	Fri Jun 24 03:31:05 2011 +0200
@@ -22,10 +22,10 @@
         <p><input type="radio" name="gr_validated{{ds.hda_id}}" id="not_validated" value="not_validated" {% if not ds.validated %}checked{% endif %} />En cours
         <input type="radio" name="gr_validated{{ds.hda_id}}" id="validated" value="validated" {% if ds.validated %}checked{% endif %} />Validé
         {% if ds.validated %}
-        &nbsp;&nbsp; par {{ds.validator}} le {{ds.validation_date|date:"d/m/Y"}}
+        &nbsp;&nbsp; par {{ds.validator.username}} le {{ds.validation_date|date:"d/m/Y"}}
         {% endif %}
         {% if valid != "2" %}
-        <span style="float:right;">Ajouter un tag : <input type="text" name="wp_search" id="wp_search" /> <span id="ok_search" class="hand_cursor"/><b>OK</b></span></span>
+        <span style="float:right;">Ajouter un tag : <input type="text" name="wp_search" id="wp_search" /> <span id="ok_search" class="hand_cursor"><b>OK</b></span></span>
         {% endif %}
         </p>
         {% csrf_token %}
--- a/web/hdabo/utils.py	Thu Jun 23 16:00:38 2011 +0200
+++ b/web/hdabo/utils.py	Fri Jun 24 03:31:05 2011 +0200
@@ -1,5 +1,6 @@
 # -*- coding: utf-8 -*-
 import collections
+import unicodedata
 
 
 ###
@@ -318,7 +319,7 @@
 
         '''
         if isinstance(other, OrderedDict):
-            return len(self)==len(other) and self.items() == other.items()
+            return len(self) == len(other) and self.items() == other.items()
         return dict.__eq__(self, other)
 
     def __ne__(self, other):
@@ -339,3 +340,6 @@
         return ItemsView(self)
 ## end of http://code.activestate.com/recipes/576693/ }}}
 
+def remove_accents(str):
+    nkfd_form = unicodedata.normalize('NFKD', unicode(str))
+    return u"".join([c for c in nkfd_form if not unicodedata.combining(c)])
--- a/web/hdabo/views.py	Thu Jun 23 16:00:38 2011 +0200
+++ b/web/hdabo/views.py	Fri Jun 24 03:31:05 2011 +0200
@@ -3,6 +3,7 @@
 from django.conf import settings
 from django.contrib.auth.decorators import login_required #@UnusedImport
 from django.core.paginator import Paginator
+from django.db import connection
 from django.db.models import Max, Count
 from django.http import HttpResponseBadRequest
 from django.shortcuts import render_to_response, redirect
@@ -10,7 +11,7 @@
 from django.utils.http import urlquote
 from haystack.constants import DJANGO_ID
 from haystack.query import SearchQuerySet
-from hdabo.utils import OrderedDict
+from hdabo.utils import OrderedDict, remove_accents
 from hdabo.wp_utils import (normalize_tag, query_wikipedia_title, 
     get_or_create_tag, process_tag)
 from models import Datasheet, Organisation, Tag, TagCategory, TaggedSheet
@@ -23,22 +24,17 @@
 #@login_required
 def home(request):
     
-    # Get all organizations
-    #ds_queryset = Datasheet.objects.filter(organisation="hdabo_organisation.id")
-    
-    orgas = Organisation.objects.all()\
-        .order_by('name').annotate(nb_all=Count("datasheet"))\
-        .extra(select={
-            'nb_val':"SELECT COUNT(*) FROM hdabo_datasheet WHERE hdabo_datasheet.validated=true and hdabo_datasheet.organisation_id=hdabo_organisation.id",
-            'nb_unval':"SELECT COUNT(*) FROM hdabo_datasheet WHERE hdabo_datasheet.validated=false and hdabo_datasheet.organisation_id=hdabo_organisation.id",
-        })
-    # Count all validated, unvalidated sheets for each organisation
+    orgas = Organisation.objects.all().order_by('name')
+
     org_list = []
+    all_ds_mapping = dict([(res['organisation'],res['nb_all']) for res in Datasheet.objects.values("organisation").annotate(nb_all=Count("organisation"))])
+    validated_ds_mapping = dict([(res['organisation'],res['nb_val']) for res in Datasheet.objects.filter(validated=True).values("organisation").annotate(nb_val=Count("organisation"))])
+    unvalidated_ds_mapping = dict([(res['organisation'],res['nb_unval']) for res in Datasheet.objects.filter(validated=False).values("organisation").annotate(nb_unval=Count("organisation"))])
+
     for orga in orgas :
-        #all_datasheets = Datasheet.objects.filter(organisation=orga)
-        nb_all = orga.nb_all#len(all_datasheets)
-        nb_val = orga.nb_val#len(all_datasheets.filter(validated=True))
-        nb_unval = orga.nb_unval#len(all_datasheets.filter(validated=False))
+        nb_all = all_ds_mapping.get(orga.id,0)
+        nb_val = validated_ds_mapping.get(orga.id,0)
+        nb_unval = unvalidated_ds_mapping.get(orga.id,0)
         org_list.append({'organisation':orga, 'nb_all':nb_all, 'nb_val':nb_val, 'nb_unval':nb_unval})
     
     return render_to_response("organisation_list.html",
@@ -115,8 +111,21 @@
     prev_page = max(num_page - 1, 1)
     next_page = min(num_page + 1, p.num_pages)
     last_page = p.num_pages
-        
-    search_def = tuple([(c,urlquote(c + settings.SEARCH_STAR_CHARACTER)) for c in '01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ'])
+    
+    
+    cursor = connection.cursor() #@UndefinedVariable
+    fl_list = []
+    try:
+        cursor.execute("select upper(substring(label from 1 for 1)) as fl from hdabo_tag group by fl order by fl;")
+    
+        for row in cursor:
+            new_char = remove_accents(row[0])
+            if new_char not in fl_list:
+                fl_list.append(new_char)
+    finally:
+        cursor.close()
+    
+    search_def = tuple([(c,urlquote(c + settings.SEARCH_STAR_CHARACTER)) for c in fl_list])
         
     return render_to_response("all_tags.html",
                               {'nb_total':p.count, 'tags':current_page.object_list, 'current_page':current_page,