Merge with 29f990eb014488f105d54164324c7faa4a271119
authorverrierj
Wed, 25 Jan 2012 17:59:42 +0100
changeset 453 a6ea89e72f41
parent 452 8e9494006e7b (diff)
parent 450 29f990eb0144 (current diff)
child 454 958e8d29293c
Merge with 29f990eb014488f105d54164324c7faa4a271119
src/ldt/ldt/ldt_utils/templates/front/front_search_results.html
--- a/src/ldt/ldt/indexation/__init__.py	Wed Jan 25 17:55:21 2012 +0100
+++ b/src/ldt/ldt/indexation/__init__.py	Wed Jan 25 17:59:42 2012 +0100
@@ -46,30 +46,30 @@
     
     return hits.scoreDocs
 
-def highlight_documents(doc_list, query, field):
+def highlight_documents(results_list, query, field):
     searcher = get_searcher()
     analyzer = lucene.FrenchAnalyzer(lucene.Version.LUCENE_CURRENT)
     formatter = lucene.SimpleHTMLFormatter('<span class="highlight">', '</span>')
     query = get_query_parser(field).parse(query)
     highlighter = lucene.Highlighter(formatter, lucene.QueryScorer (query))
     
-    for project in doc_list:
+    for project in results_list:
         for segment in project['list']:
-            lucene_doc = searcher.doc(segment['lucene_id'])
-            segment['context'] = get_highlighted_text(lucene_doc, analyzer, highlighter, 'abstract')
+            lucene_doc = searcher.doc(segment.lucene_id)
+            segment.context = get_highlighted_text(lucene_doc, analyzer, highlighter, 'abstract')
             tags = get_highlighted_text(lucene_doc, analyzer, highlighter, 'tags')
-            segment['title'] = get_highlighted_text(lucene_doc, analyzer, highlighter, 'title')
+            segment.title = get_highlighted_text(lucene_doc, analyzer, highlighter, 'title')
             
-            if segment['context'] == u'':
-                segment['context'] = lucene_doc.getField('abstract').stringValue()
+            if segment.context == u'':
+                segment.context = lucene_doc.getField('abstract').stringValue()
             if tags == u'':
                 tags = lucene_doc.getField('tags').stringValue()
-            if segment['title'] == u'':
-                segment['title'] = lucene_doc.getField('title').stringValue() 
+            if segment.title == u'':
+                segment.title = lucene_doc.getField('title').stringValue() 
                 
-            segment['tags'] = tags[tags.find(';')+1:]          
+            segment.context_tags = tags[tags.find(';')+1:]          
             
-    return doc_list    
+    return results_list    
 
 def get_highlighted_text(doc, analyzer, highlighter, field):
     res = doc.getField(field).stringValue()
--- a/src/ldt/ldt/ldt_utils/templates/front/front_search_results.html	Wed Jan 25 17:55:21 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/templates/front/front_search_results.html	Wed Jan 25 17:59:42 2012 +0100
@@ -26,11 +26,9 @@
             "segments" : [ {% for segment in res.list %}
                 {
                     "id" : '{{segment.element_id}}',
-                    "begin" : {{segment.begin}},
+                    "begin" : {{segment.start_ts}},
                     "duration" : {{segment.duration}},
-                    "cutting_id" : '{{segment.decoupage_id}}',
-                    "project_id" : '{{segment.project_id}}',
-                    "ensemble_id" : '{{segment.ensemble_id}}',
+                    "cutting_id" : '{{segment.cutting_id}}',
                 },{% endfor %}
             ],
             "stats" : [{{ res.content.stat_annotation }}],
@@ -38,7 +36,8 @@
     ];
     
     var global_csrf_token = "{{ csrf_token }}";
-    var annot_preview_url = "{% url ldt.ldt_utils.views.front.annotation_preview project_id='__PROJECT_ID__' content_id='__CONTENT_ID__' ensemble_id='__ENSEMBLE_ID__' cutting_id='__CUTTING_ID__' segment_id='__SEGMENT_ID__' %}";
+
+    
 </script>
 <script src="{{LDT_MEDIA_PREFIX}}js/Ldt_front_search_results.js" type="text/javascript"></script>
 
@@ -74,16 +73,16 @@
             <li class="li_result_media">
                 <div class="titre_result_media">
                     <div class="h3_result_media">
-                        <h3>{% if res.content_title|length > 20 %}{{res.content_title|capfirst|slice:"20"}}...{% else %}{{res.content_title}}{% endif %}</h3>
+                        <h3>{% if res.content.title|length > 20 %}{{res.content.title|capfirst|slice:"20"}}...{% else %}{{res.content.title}}{% endif %}</h3>
                     </div>
                     <div class="duree_result_media">
-                        <p>{{res.content.duration|str_duration:"::"}}</p>
+                        <p>{{res.content.duration|str_duration:"::" }}</p>  
                     </div>
                     <div class="graphe_result_media">
                     	<span id="{{ res.content.iri_id }}" class="graph_annotation" title="{% trans 'annotation distribution' %}">
                     	</span>
                     </div>
-                </div>
+                </div>        
         
             <!-- Segments du média -->
                 <ul class="floatlist list_segments">
@@ -91,13 +90,12 @@
                     <li class="li_segment" id="li_{{segment.element_id}}">
                         <div class="left_segment">
                             <div class="color_zone"></div>
-                            <a href="{% url ldt.ldt_utils.views.front.annot_content segment.iri_id segment.project_id segment.decoupage_id %}#id={{segment.element_id}}"><img src="{{LDT_MEDIA_PREFIX}}img/annot_icon_80x45.png" width="80" height="45" alt="" /></a>
+                            <a href="{% url ldt.ldt_utils.views.front.annot_content segment.iri_id segment.project_id segment.cutting_id %}#id={{segment.element_id}}"><img src="{{LDT_MEDIA_PREFIX}}img/annot_icon_80x45.png" width="80" height="45" alt="" /></a>
                             <!--p class="duree_segment">{{ segment.duration|str_duration:"::" }}</p-->
                         </div>
-                        <h4 class="title_segment"><a class="blue under" href="{% url ldt.ldt_utils.views.front.annot_content segment.iri_id segment.project_id segment.decoupage_id %}#id={{segment.element_id}}" title="{% trans 'view this annotation in the player' %}">
+                        <h4 class="title_segment"><a class="blue under" href="{% url ldt.ldt_utils.views.front.annot_content segment.iri_id segment.project_id segment.cutting_id %}#id={{segment.element_id}}" title="{% trans 'view this annotation in the player' %}">
                           {% if segment.title %}{{ segment.title }}{% else %}{% trans "No title" %}{% endif %}</a></h4>
-                        <p class="text_segment">{% if segment.context %}{{ segment.context }}{% endif %}<br/>{% trans "Begin" %} : {{ segment.begin|str_duration:"::" }} - {% trans "duration" %} : {{ segment.duration|str_duration:"::" }}</p>
-                        <p>{{ segment.abstract }}</p>
+                        <p class="text_segment">{% if segment.context %}{{ segment.context }}{% endif %}<br/>{% trans "Begin" %} : {{ segment.start_ts|str_duration:"::" }} - {% trans "duration" %} : {{ segment.duration|str_duration:"::" }}</h4>
                     </li>
                 {% endfor %}
                 </ul>
@@ -122,14 +120,13 @@
 	                <a class="blue under" href="{% url ldt.ldt_utils.views.front.search_listing %}?page={{i|add:'1'}}">{{i|add:'1'}}</a>
 	                {% endif %}
 	                {% if i|add:'1' < results.paginator.num_pages and 1 < results.paginator.num_pages %}
-	                .
                     {% endif %}
 	            </span>
 	            {% endfor %}
 	        </span>
 	        {% endif %}
 	        {% if results.has_next %}
-	            .
+	           
 	            <a class="blue under" href="{% url ldt.ldt_utils.views.front.search_listing %}?page={{ results.next_page_number }}" title="{% trans 'next' %}">{% trans "next" %}</a>
 	        {% endif %}
             </p>
--- a/src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/partial/ldt_div.html	Wed Jan 25 17:55:21 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/partial/ldt_div.html	Wed Jan 25 17:59:42 2012 +0100
@@ -27,8 +27,9 @@
 		{% else %}
 		readOnly:'true',
 		{% endifequal %}
-		segmentPassMask:'',
-		simplePlayerPassMask:''
+		segmentPassMask:"{{WEB_URL}}{% url ldt.ldt_utils.views.lignesdetemps.index_segment '{4}' '{0}' '{1}' '{2}' '{3}' %}",
+		simplePlayerPassMask:"{{WEB_URL}}{% url ldt.ldt_utils.views.front.annot_content '{0}' '{4}' '{2}' %}"
+		
 	};
 
 	var attributes = {  id: "ldtInitSwf",  name: "ldtInitSwf"};
--- a/src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/search_results.html	Wed Jan 25 17:55:21 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/search_results.html	Wed Jan 25 17:59:42 2012 +0100
@@ -67,13 +67,13 @@
 	<ul>
 	{% for res in results.object_list %}
 		<li>		
-			<span class="titleresults">{{res.content_title|capfirst}}</span><br />
-			{% ifnotequal res.content_description 'None' %}
-			<span class="descresults">{{ res.content_description }}</span><br />
-			{% endifnotequal %}		
+			<span class="titleresults">{{res.content.title|capfirst}}</span><br />
+			
+			<span class="descresults">{{ res.content.description }}</span><br />
+			
 			<ul class="listsegments">
 			{% for segment in res.list %}
-				<li class="segmentinfos" ><span  class="" title="{% trans 'open ldt' %}"><a class="ldt_link_open_ldt" href="{% url ldt.ldt_utils.views.lignesdetemps.index_segment segment.project_id segment.iri_id segment.ensemble_id segment.decoupage_id segment.element_id %}">
+				<li class="segmentinfos" ><span  class="" title="{% trans 'open ldt' %}"><a class="ldt_link_open_ldt" href="{% url ldt.ldt_utils.views.lignesdetemps.index_segment segment.project_id segment.iri_id segment.ensemble_id segment.cutting_id segment.element_id %}">
 				{% if segment.title %}
 					{{ segment.title }}
 				{% else %}
@@ -83,8 +83,8 @@
 				{% if segment.context %}
 				<br />{{ segment.context }}
 				{% endif %}
-				{% if segment.tags %}
-				<br /><b>{% trans "Tags"%}</b> : {{ segment.tags }}
+				{% if segment.context_tags %}
+				<br /><b>{% trans "Tags"%}</b> : {{ segment.context_tags }}
 				{% endif %}
 				</li>
 			{% endfor %}
--- a/src/ldt/ldt/ldt_utils/urls.py	Wed Jan 25 17:55:21 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/urls.py	Wed Jan 25 17:59:42 2012 +0100
@@ -48,7 +48,6 @@
     url(r'^front/search/$', 'views.front.search_index'),
     url(r'^front/searchListing', 'views.front.search_listing'),
     url(r'^front/medias', 'views.front.all_contents'),
-    url(r'^annotpreview/(?P<project_id>.*)/(?P<content_id>.*)/(?P<ensemble_id>.*)/(?P<cutting_id>.*)/(?P<segment_id>.*)/$', 'views.front.annotation_preview'),
 )
 
 urlpatterns += patterns('',
--- a/src/ldt/ldt/ldt_utils/views/front.py	Wed Jan 25 17:55:21 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/views/front.py	Wed Jan 25 17:59:42 2012 +0100
@@ -131,37 +131,3 @@
         return Tag.objects.cloud_for_model(Content, steps=steps)
     else :
         return Tag.objects.cloud_for_model(Content, steps=steps)[:limit]
-
-
-def annotation_preview(request, project_id, content_id, ensemble_id, cutting_id, segment_id):
-    
-    if project_id == '_':
-        project_id = ''
-    
-    s = get_object_or_404(Segment, iri_id=content_id, project_id=project_id, cutting_id=cutting_id, element_id=segment_id, ensemble_id=ensemble_id)
- 
-    annotation = {
-                  'project_id': s.project_id,
-                  'iri_id' : s.iri_id,
-                  'ensemble_id' : s.ensemble_id, 
-                  'cutting_id' : s.cutting_id,
-                  'element_id' : s.ensemble_id,
-                  'tags' : s.tags,
-                  'title': s.title,
-                  'duration': s.duration, 
-                  'start_ts': s.start_ts, 
-                  'author': s.author,
-                  'date': s.date, 
-                  'abstract': s.abstract                     
-                  }        
-    
-    mimetype = "application/json; charset=utf-8"
-    resp = HttpResponse(mimetype=mimetype)
-    resp['Cache-Control'] = 'no-cache, must-revalidate'
-    resp['Pragma'] = 'no-cache'
-    resp.write(simplejson.dumps(annotation, indent=settings.LDT_JSON_DEFAULT_INDENT))
-    
-    return resp
-
-
-    
--- a/src/ldt/ldt/ldt_utils/views/workspace.py	Wed Jan 25 17:55:21 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/views/workspace.py	Wed Jan 25 17:59:42 2012 +0100
@@ -12,7 +12,7 @@
 from django.utils.html import escape
 from django.utils.translation import ugettext as _
 from ldt.ldt_utils.forms import SearchForm
-from ldt.ldt_utils.models import Content, Project
+from ldt.ldt_utils.models import Content, Project, Segment
 from ldt.ldt_utils.utils import boolean_convert
 from ldt.security.utils import add_change_attr, get_userlist
 from lxml.html import fragment_fromstring
@@ -165,36 +165,51 @@
             url = settings.WEB_URL + django.core.urlresolvers.reverse("ldt.ldt_utils.views.lignesdetemps.search_init", args=[field, queryStr])
             return render_to_response('ldt/ldt_utils/init_ldt_full.html', {'LDT_MEDIA_PREFIX': settings.LDT_MEDIA_PREFIX, 'colorurl': settings.LDT_MEDIA_PREFIX + 'swf/ldt/pkg/color.xml', 'i18nurl': settings.LDT_MEDIA_PREFIX + 'swf/ldt/pkg/i18n', 'language': language_code, 'baseurl': settings.LDT_MEDIA_PREFIX + 'swf/ldt/', 'url': url}, context_instance=RequestContext(request))
         else:
-            results = get_results_with_context(field, search)     
-            complete_results = []
-            # the search is made only on the published project
-            proj_list = Project.safe_objects.filter(state=2)
+            results = get_results_with_context(field, search) 
+                
+            all_segments = Segment.safe_objects.filter(element_id__in=[e['element_id'] for e in results])
+            all_projects = Project.safe_objects.filter(ldt_id__in=[e['project_id'] for e in results], state=2)
+            all_contents = Content.safe_objects.filter(iri_id__in=[e['iri_id'] for e in results])
+            viewable_projects_id = [p.ldt_id for p in all_projects]
+            
+            complete_results = []           
             results.sort(key=lambda k: k['iri_id'])
-            for iri_id, item in groupby(results, itemgetter('iri_id')):                
-                try: 
-                    content = Content.objects.get(iri_id=iri_id)
-                except Content.DoesNotExist:
-                    continue
-                segments = list(item)
-                to_delete = []
-                for s in segments:
+            
+            for iri_id, item in groupby(results, itemgetter('iri_id')):
+                content = filter(lambda e: e.iri_id == iri_id, all_contents)[0]
+                if content.description is None:
+                    content.description = ''
+                    
+                all_related_segments = list(item)
+                
+                valid_segments = []
+                for s in all_related_segments:
+                    segment = filter(lambda e: e.element_id == s['element_id'] , all_segments)[0]
+                    
+                    segment.score = s['score']
+                    segment.lucene_id = s['lucene_id']
+                    segment.context = s['context']
+                    segment.context_tags = s['tags']
+                                        
                     if not s['project_id']:
                         s['project_id'] = '_'
-                    else:
-                        project = proj_list.filter(ldt_id=s['project_id'])
-                        if len(project) == 0:
-                            to_delete.append(s)
-                            
-                for e in to_delete:
-                    segments.remove(e)
-                    
-                if not segments:
-                    continue 
+                        valid_segments.append(segment)
+                    elif s['project_id'] in viewable_projects_id:
+                        valid_segments.append(segment)
+                
+                # If all segments found belong to unpublished projects or projects
+                # the current user is not allowed to see
+                if not valid_segments:
+                    continue
                 
-                score = sum([seg['score'] for seg in segments])
-                desc = content.description if content.description else ''
-                complete_results.append({'list' : segments, 'score' : score, 'content_title' : content.title, 'content_id' : content.iri_id, 'content_description' : desc, 'content':content })
-            
+                score = sum([seg.score for seg in valid_segments])
+                complete_results.append({
+                                         'list': valid_segments,
+                                         'score': score,
+                                         'content': content,                                         
+                                         })
+                
+      
             complete_results.sort(key=lambda k: k['score'])
                                 
             cache.set('complete_results_%s' % request.user.username, complete_results)
@@ -208,9 +223,8 @@
                 results = paginator.page(page)
             except (EmptyPage, InvalidPage):
                 results = paginator.page(paginator.num_pages)
-                
-            results.object_list = highlight_documents(results.object_list, search, field)
             
+            results.object_list = highlight_documents(results.object_list, search, field)            
             
             if front_template :
                 return render_to_response('front/front_search_results.html', {'results': results, 'nb_results' : paginator.count, 'search' : search, 'LDT_MEDIA_PREFIX': settings.LDT_MEDIA_PREFIX, 'colorurl': settings.LDT_MEDIA_PREFIX + 'swf/ldt/pkg/color.xml', 'i18nurl': settings.LDT_MEDIA_PREFIX + 'swf/ldt/pkg/i18n', 'language': language_code, 'baseurl': settings.LDT_MEDIA_PREFIX + 'swf/ldt/'}, context_instance=RequestContext(request))
--- a/src/ldt/ldt/user/models.py	Wed Jan 25 17:55:21 2012 +0100
+++ b/src/ldt/ldt/user/models.py	Wed Jan 25 17:59:42 2012 +0100
@@ -53,7 +53,9 @@
             profile = GroupProfile()
             profile.group_id = instance.id
             profile.save()
-            instance.user_set.add(User.objects.filter(is_superuser=True)[0])            
+            admins = User.objects.filter(is_superuser=True)
+            if admins:
+                instance.user_set.add(admins[0])            
             
 # To keep consistency with User.get_profile() method
 def get_profile(self):