# HG changeset patch # User cavaliet # Date 1401181654 -7200 # Node ID ef4095059d92ebf4e7947c71f2079e149a3fce9f # Parent ef00f69d74ad16dcbbadb51eea7f2093492bc359 v0.5.18 query on abstract diff -r ef00f69d74ad -r ef4095059d92 src/spel/__init__.py --- a/src/spel/__init__.py Fri May 23 16:23:27 2014 +0200 +++ b/src/spel/__init__.py Tue May 27 11:07:34 2014 +0200 @@ -1,4 +1,4 @@ -VERSION = (0, 5, 17, "final", 0) +VERSION = (0, 5, 18, "final", 0) VERSION_STR = unicode(".".join(map(lambda i:"%02d" % (i,), VERSION[:2]))) diff -r ef00f69d74ad -r ef4095059d92 src/spel/static/spel/js/opera.js --- a/src/spel/static/spel/js/opera.js Fri May 23 16:23:27 2014 +0200 +++ b/src/spel/static/spel/js/opera.js Tue May 27 11:07:34 2014 +0200 @@ -12,6 +12,12 @@ filter_enabled = true; } } + if(!filter_enabled){ + // check search input + if($("#search-input").val().trim()!=""){ + filter_enabled = true; + } + } if(filter_enabled){ $("#btn-filter-chapters").removeAttr('disabled'); } @@ -79,14 +85,9 @@ $("#mulsel4").multiselect('dataprovider', data4); $("#mulsel4").multiselect('enable'); }); - $(document).on('input', "#search-input", function(){ - if($(this).val()!=""){ - $("#btn-search-annotations").removeAttr('disabled'); - } - else{ - $("#btn-search-annotations").attr('disabled','disabled'); - } - }); + + // on change + $(document).on('input', "#search-input", enabledFilter ); // Data 5 : Actes $.ajax({ @@ -169,7 +170,14 @@ enabledFilter(); }); - + $(document).on('input', "#search-input", function(){ + if($(this).val()!=""){ + $("#btn-search-annotations").removeAttr('disabled'); + } + else{ + $("#btn-search-annotations").attr('disabled','disabled'); + } + }); function buildChapterTable(html){ $(".chapter-results").removeClass("loader"); @@ -190,7 +198,7 @@ // Search chapters management $("#btn-filter-chapters").click(function(e){ - if($("#mulsel1").val()==null && $("#mulsel2").val()==null && $("#mulsel3").val()==null && $("#mulsel4").val()==null && $("#mulsel5").val()==null && $("#mulsel6").val()==null && !((typeof $("#end-mesure").attr('disabled'))==="undefined" || $("#start-mesure").val()!="start")){ + if($("#mulsel1").val()==null && $("#mulsel2").val()==null && $("#mulsel3").val()==null && $("#mulsel4").val()==null && $("#mulsel5").val()==null && $("#mulsel6").val()==null && !((typeof $("#end-mesure").attr('disabled'))==="undefined" || $("#start-mesure").val()!="start") && $("#search-input").val().trim()==""){ $(".chapter-results").html("

Vous devez sélectionner au moins un filtre

"); return false; } @@ -205,6 +213,7 @@ modalites_sceniques: ( ($("#mulsel2").val()==null) ? [] : $("#mulsel2").val() ).join(","), personnages: ( ($("#mulsel3").val()==null) ? [] : $("#mulsel3").val() ).join(","), type_travail: ( ($("#mulsel4").val()==null) ? [] : $("#mulsel4").val() ).join(","), + q: $("#search-input").val(), acte: ( ($("#mulsel5").val()==null) ? [] : $("#mulsel5").val() ).join(","), scene: ( ($("#mulsel6").val()==null) ? [] : $("#mulsel6").val() ).join(","), start_mesure: $("#start-mesure").val(), @@ -224,7 +233,10 @@ // click-to-remove-tag management for chapter $(".chapter-results").on("click", ".chapter-tag-list .glyphicon-remove", function(){ - if($(this).parent().hasClass("type")){ + if($(this).parent().children().first().hasClass("glyphicon-search")){ + $("#search-input").val(""); + } + else if($(this).parent().hasClass("type")){ $("#mulsel1").multiselect('deselect', $(this).parent().text().trim()); } else if($(this).parent().hasClass("modscen")){ diff -r ef00f69d74ad -r ef4095059d92 src/spel/templates/partial/spel_opera_annotations.html --- a/src/spel/templates/partial/spel_opera_annotations.html Fri May 23 16:23:27 2014 +0200 +++ b/src/spel/templates/partial/spel_opera_annotations.html Tue May 27 11:07:34 2014 +0200 @@ -19,6 +19,7 @@ {% else %} {% for t in mesure %}
  • mesure: {{ t }}
  • {% endfor %} {% endif %} + {% if q != "" %}
  • : {{ q }}
  • {% endif %}

    {{ segments|length }} segment(s) trouvé(s)

    @@ -39,8 +40,8 @@ {{ s.tags|get_tags:"opera_scene"|join:', ' }} {{ s.tags|get_tags:"opera_mesure"|join:', ' }} - + diff -r ef00f69d74ad -r ef4095059d92 src/spel/templates/spel_opera.html --- a/src/spel/templates/spel_opera.html Fri May 23 16:23:27 2014 +0200 +++ b/src/spel/templates/spel_opera.html Tue May 27 11:07:34 2014 +0200 @@ -37,7 +37,7 @@
    - +
    diff -r ef00f69d74ad -r ef4095059d92 src/spel/views.py --- a/src/spel/views.py Fri May 23 16:23:27 2014 +0200 +++ b/src/spel/views.py Tue May 27 11:07:34 2014 +0200 @@ -3,24 +3,26 @@ @author: tcavalie ''' + +from django.conf import settings +from django.contrib.contenttypes.models import ContentType +from django.db.models import Q +from django.db.models.aggregates import Count +from django.db.models.query import RawQuerySet +from django.http.response import HttpResponse +from django.views.generic import TemplateView +from itertools import groupby +from ldt.indexation import get_results_with_context +from ldt.ldt_utils.models import Segment, Content +from ldt.ldt_utils.views.workspace import get_search_results +from operator import itemgetter +from taggit.models import Tag, TaggedItem import json import re import time -from django.db.models import Q -from django.conf import settings -from django.views.generic import TemplateView -from itertools import groupby -from operator import itemgetter -from taggit.models import Tag, TaggedItem -from ldt.ldt_utils.models import Segment, Content import logging -from ldt.ldt_utils.views.workspace import get_search_results -from django.http.response import HttpResponse -from django.db.models.query import RawQuerySet -from django.contrib.contenttypes.models import ContentType -from django.db.models.aggregates import Count logger = logging.getLogger(__name__) @@ -350,12 +352,20 @@ end_date_param = request.GET.get("end_date", "") if end_date_param!="": content_qs = content_qs.filter(content_creation_date__lt=end_date_param + " 23:59:59") - iri_ids = content_qs.values_list("iri_id", flat=True) - #logger.debug("iri_ids") - #logger.debug(iri_ids) - # Filter segment if necessary + + # Query on abstract management + q = request.GET.get("q", "").strip() + if q!="": + # Query case : we get segments by the search engine + field = "abstract" + results = get_results_with_context(Segment, field, q, content_qs) + seg_queryset = Segment.objects.filter(pk__in=[e['indexation_id'] for e in results]).select_related("content__title") + else: + # Filter segment if necessary + iri_ids = content_qs.values_list("iri_id", flat=True) + seg_queryset = Segment.objects.filter(iri_id__in=iri_ids).select_related("content__title") + annot_types_param = request.GET.get("annotation_types", "") - seg_queryset = Segment.objects.filter(iri_id__in=iri_ids).select_related("content__title") annot_types = [] if annot_types_param!="": annot_types = annot_types_param.split(",") @@ -383,6 +393,7 @@ if scene_param!="": scene = scene_param.split(",") + # Mesure management start_mesure = request.GET.get("start_mesure", "") end_mesure = request.GET.get("end_mesure", "") mesure = None @@ -446,18 +457,20 @@ # Get segments from tagged items #s = TaggedItem.objects.get_by_model(seg_queryset, tags) tags = list(tags) - seg_ids = list(TaggedItem.objects\ - .values_list("object_id", flat=True)\ - .filter(content_type=ContentType.objects.get_for_model(Segment))\ - .filter(tag__in=tags)\ - .annotate(count_status=Count('object_id'))\ - .filter(count_status=len(tags))) - s = list(seg_queryset.filter(pk__in=seg_ids)) - + if len(tags)>0: + seg_ids = list(TaggedItem.objects\ + .values_list("object_id", flat=True)\ + .filter(content_type=ContentType.objects.get_for_model(Segment))\ + .filter(tag__in=tags)\ + .annotate(count_status=Count('object_id'))\ + .filter(count_status=len(tags))) + s = list(seg_queryset.filter(pk__in=seg_ids)) + else: + s = list(seg_queryset) context = {"annot_types":annot_types, "start_date":start_date_param, "end_date":end_date_param, "mod_scen":mod_scen, "perso":perso, "type_travail":type_travail, "acte":acte, - "scene":scene, "mesure":mesure_int, "segments": s} + "scene":scene, "mesure":mesure_int, "q":q, "segments": s} return self.render_to_response(context)