--- a/src/spel/management/commands/generate_demonstrateur_data.py Tue Nov 04 18:05:43 2014 +0100
+++ b/src/spel/management/commands/generate_demonstrateur_data.py Wed Nov 05 17:54:12 2014 +0100
@@ -90,10 +90,12 @@
if line[0]!="":
content_title = unicode(line[1].decode('utf-8'))
prefix = "[demo] "
+ tag = "demo"
if line[0]=="Duo Brick et Maggy en introduction\n[7-1 à 9-5]":
- prefix = "[demo1] "
+ tag = "demo1"
elif line[0]=="51-13 à 56.15":
- prefix = "[demo2] "
+ tag = "demo2"
+ prefix = "[" + tag + "] "
content_id = line[1]
pre_annot_id = line[2]
pre_annot_tcin_hms = line[3]
@@ -145,7 +147,7 @@
# tc_end = post_annot_tcout_ms
# data to create new data
- ctt_title = prefix + content_title + (u" 0" if count_content<10 else u" ") + unicode(count_content)
+ ctt_title = prefix + content_title + u" : extrait " + (u"0" if count_content<10 else u"") + unicode(count_content)
media_src = "/data/demonstrateur/"+content_id+"/" + created_ctt_id + ".mp4"
if hasattr(settings, "DEMONSTRATEUR_DOMAIN") and len(settings.DEMONSTRATEUR_DOMAIN)>0:
media_src = settings.DEMONSTRATEUR_DOMAIN + media_src
@@ -158,7 +160,7 @@
duration = created_ctt_dur)
content.is_public = True
update_stat_content(content)
- content.tags.add("demo_theatre")
+ content.tags.add(tag + "_theatre")
# Get content front projet
proj = content.front_project
ps = ProjectJsonSerializer(proj)
--- a/src/spel/templates/spel_demonstrateur.html Tue Nov 04 18:05:43 2014 +0100
+++ b/src/spel/templates/spel_demonstrateur.html Wed Nov 05 17:54:12 2014 +0100
@@ -4,18 +4,35 @@
{% block page_title %}Corpus{% endblock %}
{% block spel_content %}
- <section style="width: 1070px; margin: 0 auto">
- <h1>Démonstrateur</h1>
- <select onchange="this.options[this.selectedIndex].value && (window.location = this.options[this.selectedIndex].value);">
- <option value="">Sélectionner...</option>
- {% for c in contents %}
- <option value="?p={{ c.front_project.ldt_id }}" {% if current_ctt_id == c.front_project.ldt_id %}selected{% endif %}>{{ c.title }}</option>
- {% endfor %}
- </select>
- <ul>
- </ul>
- <div id="LdtPlayer"></div>
- <div id="AnnotationsListContainer"></div>
+ <section style="width: 1070px; margin: 0 auto">
+ <div class="row">
+ <div class="col-md-7">
+ {% if current_ctt_id != '' %}
+ <h3>{{ demo_title }}</h3>
+ <p><strong>{{ proj_title }}</strong></p>
+ <p>{% if proj1_ldt_id %}<a href="?tag={{ tag }}&p={{ proj1_ldt_id }}">Extrait précédent</a>{% endif %}
+ {% if proj1_ldt_id and proj2_ldt_id %} - {% endif %}
+ {% if proj2_ldt_id %}<a href="?tag={{ tag }}&p={{ proj2_ldt_id }}">Extrait suivant</a>{% endif %}</p>
+ <p>{{ annot_title }}</p>
+ <p>{{ annot_description }}</p>
+ <p>{{ annot_tags|safe }}</p>
+ <select onchange="this.options[this.selectedIndex].value && (window.location = this.options[this.selectedIndex].value);">
+ <option value="">Sélectionner...</option>
+ {% for c in contents %}
+ <option value="?tag={{ tag }}&p={{ c.front_project.ldt_id }}" {% if current_ctt_id == c.front_project.ldt_id %}selected{% endif %}>{{ c.title }}</option>
+ {% endfor %}
+ </select>
+ {% else %}
+ <h2>Démonstrateur : choisissez une scène</h2>
+ <p><a href="?tag=demo1_theatre&p={{ proj1_ldt_id }}">Scène d'introduction - Duo Brick et Maggy [répliques 7-1 à 9-5]</a></p>
+ <p><a href="?tag=demo2_theatre&p={{ proj2_ldt_id }}">Scène duo Brick et Grand Pa [répliques 51-13 à 56-15]</a></p>
+ {% endif %}
+ </div>
+ <div class="col-md-5">À venir
+ </div>
+ </div>
+ <div id="LdtPlayer"></div>
+ <div id="AnnotationsListContainer"></div>
</section>
{% if current_ctt_id != '' %}
<script type="text/javascript" src="{% static 'spel/lib/jquery.min.js' %}"></script>
--- a/src/spel/views.py Tue Nov 04 18:05:43 2014 +0100
+++ b/src/spel/views.py Wed Nov 05 17:54:12 2014 +0100
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
'''
Created on 2014-02-21
@@ -20,6 +21,7 @@
from ldt.ldt_utils.views.workspace import get_search_results
from operator import itemgetter
from taggit.models import Tag, TaggedItem
+from .templatetags.spel_tags import get_tags
import json
import re
import time
@@ -138,15 +140,15 @@
# That's many requests (with the orm) but it seems the only thing possible with tagging
s = []
for rt in ref_text:
- current_tags = list(tags)
- current_tags.append(rt)
- #s += list(TaggedItem.objects.get_by_model(seg_queryset, current_tags))
+ annot_tags = list(tags)
+ annot_tags.append(rt)
+ #s += list(TaggedItem.objects.get_by_model(seg_queryset, annot_tags))
seg_ids = list(TaggedItem.objects\
.values_list("object_id", flat=True)\
.filter(content_type=ContentType.objects.get_for_model(Segment))\
- .filter(tag__in=current_tags)\
+ .filter(tag__in=annot_tags)\
.annotate(count_status=Count('object_id'))\
- .filter(count_status=len(current_tags)))
+ .filter(count_status=len(annot_tags)))
s += list(seg_queryset.filter(pk__in=seg_ids))
else:
# Get segments from tagged items
@@ -447,15 +449,15 @@
# That's many requests (with the orm) but it seems the only thing possible with tagging
s = []
for m in mesure:
- current_tags = list(tags)
- current_tags.append(m)
- #s += list(TaggedItem.objects.get_by_model(seg_queryset, current_tags))
+ annot_tags = list(tags)
+ annot_tags.append(m)
+ #s += list(TaggedItem.objects.get_by_model(seg_queryset, annot_tags))
seg_ids = list(TaggedItem.objects\
.values_list("object_id", flat=True)\
.filter(content_type=ContentType.objects.get_for_model(Segment))\
- .filter(tag__in=current_tags)\
+ .filter(tag__in=annot_tags)\
.annotate(count_status=Count('object_id'))\
- .filter(count_status=len(current_tags)))
+ .filter(count_status=len(annot_tags)))
s += list(seg_queryset.filter(pk__in=seg_ids))
else:
# Get segments from tagged items
@@ -522,8 +524,60 @@
template_name = "spel_demonstrateur.html"
def get(self, request):
# Get start and end for date bounds (earliest is available only on django 1.6)
- contents = Content.objects.filter(tags__name__in=["demo_theatre"]).select_related("front_project__ldt_id").order_by("creation_date")
- context = { "contents": contents, "current_ctt_id": request.GET.get("p", "") }
+ tag = request.GET.get("tag", "demo_theatre")
+ contents = Content.objects.filter(tags__name__in=[tag]).select_related("front_project__ldt_id").order_by("creation_date")
+ # Get current project data
+ p = request.GET.get("p", "")
+ demo_title = None
+ proj_title = None
+ annot_title = None
+ annot_description = None
+ annot_tags = None
+ proj1_ldt_id = None
+ proj2_ldt_id = None
+ if p and p!="":
+ project = get_object_or_404(Project, ldt_id=p)
+ ps = ProjectJsonSerializer(project)
+ project_dict = ps.serialize_to_cinelab()
+ # In this code, we know that a project only contains one annotation with type "performance"
+ proj_title = project.title[16:]# remove "front project : "
+ demo_title = ""
+ if proj_title[:7]=="[demo1]":
+ demo_title = u"Scène d'introduction - Duo Brick et Maggy [répliques 7-1 à 9-5]"
+ elif proj_title[:7]=="[demo2]":
+ demo_title = u"Scène duo Brick et Grand Pa [répliques 51-13 à 56-15]"
+ proj_title = proj_title[7:]
+ for a in project_dict["annotations"]:
+ if a["meta"]["id-ref"]=="performance":
+ annot_title = a["content"]["title"]
+ annot_description = a["content"]["description"]
+ tag_refs = [t["id-ref"] for t in a["tags"]]
+ tag_list = filter(None, [ t["meta"]["dc:title"] if t["id"] in tag_refs else None for t in project_dict["tags"] ] )
+ annot_tags = get_tags(tag_list, "group")
+ break
+ # check the position of the current project in the list of all project
+
+ project_ids = [ c.front_project.ldt_id for c in contents ]
+ project_index = project_ids.index(p)
+ if project_index > 0:
+ proj1_ldt_id = project_ids[project_index-1]
+ if project_index < (len(project_ids) - 1):
+ proj2_ldt_id = project_ids[project_index+1]
+ else:
+ c = Content.objects.filter(tags__name__in=["demo1_theatre"]).select_related("front_project__ldt_id").order_by("creation_date")[0]
+ proj1_ldt_id = c.front_project.ldt_id
+ c = Content.objects.filter(tags__name__in=["demo2_theatre"]).select_related("front_project__ldt_id").order_by("creation_date")[0]
+ proj2_ldt_id = c.front_project.ldt_id
+ context = { "contents": contents,
+ "tag": tag,
+ "proj1_ldt_id": proj1_ldt_id,
+ "proj2_ldt_id": proj2_ldt_id,
+ "current_ctt_id": request.GET.get("p", ""),
+ "demo_title": demo_title,
+ "proj_title": proj_title,
+ "annot_title": annot_title,
+ "annot_description": annot_description,
+ "annot_tags": annot_tags }
return self.render_to_response(context)
\ No newline at end of file