re-correct 0018327 and equivalence management 0018325.
authorcavaliet
Mon, 09 Dec 2013 11:28:04 +0100
changeset 217 f29941396ff7
parent 216 95cc78cce724
child 218 8c25233edf29
re-correct 0018327 and equivalence management 0018325.
src/jocondelab/static/jocondelab/js/front-common.js
src/jocondelab/views/front_office.py
--- a/src/jocondelab/static/jocondelab/js/front-common.js	Fri Dec 06 15:37:54 2013 +0100
+++ b/src/jocondelab/static/jocondelab/js/front-common.js	Mon Dec 09 11:28:04 2013 +0100
@@ -400,6 +400,8 @@
                 bindResultsMouseover();
                 $(".loading-please-wait").hide();
                 scrollLoad(query);
+                // timeout to force load more results if scroll not available
+                window.startTimeOut();
             }
         });
     }
--- a/src/jocondelab/views/front_office.py	Fri Dec 06 15:37:54 2013 +0100
+++ b/src/jocondelab/views/front_office.py	Mon Dec 09 11:28:04 2013 +0100
@@ -6,6 +6,7 @@
 '''
 
 from core.models import Notice, Term, TERM_WK_LINK_SEMANTIC_LEVEL_DICT
+from django.db.models import Q
 from django.conf import settings
 from django.core.cache import cache
 from django.core.paginator import Paginator
@@ -18,6 +19,7 @@
 import django.utils.simplejson as json
 import random
 
+
 import logging
 from core.models.term import Thesaurus
 logger = logging.getLogger(__name__)
@@ -26,7 +28,10 @@
     termsbythesaurus = {}
     for n in notices:
         termsbythesaurus[n.pk] = {}
-    for nt in Term.objects.select_related('thesaurus__label','notices__pk').filter(noticeterm__notice__in=notices, dbpedia_fields=None, link_semantic_level=TERM_WK_LINK_SEMANTIC_LEVEL_DICT["EE"]).order_by('label').distinct().values("thesaurus__label", "dbpedia_uri", "label", "notices__pk"):
+    for nt in Term.objects.select_related('thesaurus__label','notices__pk').filter(noticeterm__notice__in=notices,dbpedia_fields=None, validated=True).filter(
+                ( Q(thesaurus__label__in=["AUTR","DOMN","ECOL","LIEUX","REPR","SREP"]) & Q(link_semantic_level=TERM_WK_LINK_SEMANTIC_LEVEL_DICT["EE"]) ) | 
+                ( Q(thesaurus__label__in=["EPOQ","PERI"]) & Q(link_semantic_level__in=[TERM_WK_LINK_SEMANTIC_LEVEL_DICT["EE"], TERM_WK_LINK_SEMANTIC_LEVEL_DICT["BM"]]) ),
+                ).order_by('label').distinct().values("thesaurus__label", "dbpedia_uri", "label", "notices__pk"):
         term = {
             "thesaurus": nt["thesaurus__label"],
             "dbpedia_uri": nt["dbpedia_uri"],
@@ -36,7 +41,10 @@
         th = termsbythesaurus[nt["notices__pk"]].setdefault(term["thesaurus"], { "translated": [], "untranslated": [] })
         th["untranslated"].append(term)
     # We use "values" because it avoids an other db request for dbpedia_fields.get(language_code = lang).label
-    for nt in Term.objects.select_related('thesaurus__label','dbpedia_fields','notices__pk').filter(noticeterm__notice__in=notices, dbpedia_fields__language_code=lang, link_semantic_level=TERM_WK_LINK_SEMANTIC_LEVEL_DICT["EE"]).order_by('dbpedia_fields__label').distinct().values("thesaurus__label", "dbpedia_uri", "dbpedia_fields__label", "notices__pk"):
+    for nt in Term.objects.select_related('thesaurus__label','dbpedia_fields','notices__pk').filter(noticeterm__notice__in=notices, dbpedia_fields__language_code=lang, validated=True).filter(
+                ( Q(thesaurus__label__in=["AUTR","DOMN","ECOL","LIEUX","REPR","SREP"]) & Q(link_semantic_level=TERM_WK_LINK_SEMANTIC_LEVEL_DICT["EE"]) ) | 
+                ( Q(thesaurus__label__in=["EPOQ","PERI"]) & Q(link_semantic_level__in=[TERM_WK_LINK_SEMANTIC_LEVEL_DICT["EE"], TERM_WK_LINK_SEMANTIC_LEVEL_DICT["BM"]]) ),
+                ).order_by('dbpedia_fields__label').distinct().values("thesaurus__label", "dbpedia_uri", "dbpedia_fields__label", "notices__pk"):
         term = {
             "thesaurus": nt["thesaurus__label"],
             "dbpedia_uri": nt["dbpedia_uri"],
@@ -121,11 +129,18 @@
                     qs = qs.filter(noticeterm__term__in=fs, noticeterm__term__validated=True)
                     if thesaurus:
                         if thesaurus == 'REPR':
-                            qs = qs.filter(noticeterm__term__thesaurus__label__in=['REPR','SREP'])
+                            qs = qs.filter(noticeterm__term__thesaurus__label__in=['REPR','SREP'], noticeterm__term__link_semantic_level=TERM_WK_LINK_SEMANTIC_LEVEL_DICT["EE"])
                         elif thesaurus == 'LIEUX':
-                            qs = qs.filter(noticeterm__term__thesaurus__label__in=['LIEUX','ECOL','REPR'])
+                            qs = qs.filter(noticeterm__term__thesaurus__label__in=['LIEUX','ECOL','REPR'], noticeterm__term__link_semantic_level=TERM_WK_LINK_SEMANTIC_LEVEL_DICT["EE"])
+                        elif thesaurus == 'EPOQ' or thesaurus == 'PERI':
+                            qs = qs.filter(noticeterm__term__thesaurus__label=thesaurus, noticeterm__term__link_semantic_level__in=[TERM_WK_LINK_SEMANTIC_LEVEL_DICT["EE"], TERM_WK_LINK_SEMANTIC_LEVEL_DICT["BM"]])
                         else:
-                            qs = qs.filter(noticeterm__term__thesaurus__label=thesaurus)
+                            qs = qs.filter(noticeterm__term__thesaurus__label=thesaurus, noticeterm__term__link_semantic_level=TERM_WK_LINK_SEMANTIC_LEVEL_DICT["EE"])
+                    else:
+                        qs = qs.filter(
+                            ( Q(noticeterm__term__thesaurus__label__in=["AUTR","DOMN","ECOL","LIEUX","REPR","SREP"]) & Q(noticeterm__term__link_semantic_level=TERM_WK_LINK_SEMANTIC_LEVEL_DICT["EE"]) ) | 
+                            ( Q(noticeterm__term__thesaurus__label__in=["EPOQ","PERI"]) & Q(noticeterm__term__link_semantic_level__in=[TERM_WK_LINK_SEMANTIC_LEVEL_DICT["EE"], TERM_WK_LINK_SEMANTIC_LEVEL_DICT["BM"]]) ),
+                            )
             elif queryterms:
                 searchterms = queryterms
                 queryobj = {'q': querystr}
@@ -138,12 +153,18 @@
                             context["wkinfo"] = firstres
                     fs = fs.values('term_id').distinct()
                     qs = qs.filter(noticeterm__term__in=fs, noticeterm__term__validated=True)
+                    qs = qs.filter(
+                            ( Q(noticeterm__term__thesaurus__label__in=["AUTR","DOMN","ECOL","LIEUX","REPR","SREP"]) & Q(noticeterm__term__link_semantic_level=TERM_WK_LINK_SEMANTIC_LEVEL_DICT["EE"]) ) | 
+                            ( Q(noticeterm__term__thesaurus__label__in=["EPOQ","PERI"]) & Q(noticeterm__term__link_semantic_level__in=[TERM_WK_LINK_SEMANTIC_LEVEL_DICT["EE"], TERM_WK_LINK_SEMANTIC_LEVEL_DICT["BM"]]) ),
+                            )
             elif from_year:
                 queryobj = {'from_year': from_year, 'to_year': to_year}
                 searchterms = [u"%s – %s"%(from_year, to_year)]
                 qs = qs.filter(years__start_year__lte=to_year, years__end_year__gte=from_year, noticeterm__term__validated=True)
-            # add general filter : only exact equivalence terms :
-            qs = qs.filter(noticeterm__term__link_semantic_level=TERM_WK_LINK_SEMANTIC_LEVEL_DICT["EE"])
+                qs = qs.filter(
+                            ( Q(noticeterm__term__thesaurus__label__in=["AUTR","DOMN","ECOL","LIEUX","REPR","SREP"]) & Q(noticeterm__term__link_semantic_level=TERM_WK_LINK_SEMANTIC_LEVEL_DICT["EE"]) ) | 
+                            ( Q(noticeterm__term__thesaurus__label__in=["EPOQ","PERI"]) & Q(noticeterm__term__link_semantic_level__in=[TERM_WK_LINK_SEMANTIC_LEVEL_DICT["EE"], TERM_WK_LINK_SEMANTIC_LEVEL_DICT["BM"]]) ),
+                            )
             context["queryobj"] = json.dumps(queryobj)
             context["querystr"] = urlencode(queryobj)
             context["searchterms_label"] = ugettext(u" ET ").join(searchterms)
@@ -323,7 +344,7 @@
             context["current_letter"] = letter
             if (not alpha_sort) or (thesaurus == 'AUTR' and alphabet == latinalph and letter is not None):
                 # When ordering is not by translated label, we query the Term table
-                tqs = Term.objects.filter(dbpedia_fields__language_code=lang, nb_illustrated_notice__gt=0)
+                tqs = Term.objects.filter(dbpedia_fields__language_code=lang, nb_illustrated_notice__gt=0, validated=True)
                 if thesaurus == 'REPR':
                     tqs = tqs.filter(thesaurus__label__in=['REPR','SREP'])
                 else: