replaced mimetype arg in HTTPResponse objects with content_type + fixed a url error from commit changing json to ldt_json + replaced md5 lib (deprecated) with hashlib.md5 for project id generation
--- a/src/ldt/ldt/api/ldt/serializers/cinelabserializer.py Thu Apr 09 12:58:31 2015 +0200
+++ b/src/ldt/ldt/api/ldt/serializers/cinelabserializer.py Tue Apr 21 15:05:22 2015 +0200
@@ -200,11 +200,11 @@
# New for metadatacomposer : we add meta informations about extra of different kinds :
# related video, audio, links and html code which are not the native annotation datas
# like title, description, etc.
- if "mimetype" in a["content"]:
+ if "content_type" in a["content"]:
# Video or audio bonus
- if a["content"]["mimetype"]=="application/x-ldt-video" or a["content"]["mimetype"]=="application/x-ldt-audio":
+ if a["content"]["content_type"]=="application/x-ldt-video" or a["content"]["content_type"]=="application/x-ldt-audio":
typeNode = lxml.etree.SubElement(metaNode, 'type')
- if a["content"]["mimetype"]=="application/x-ldt-video":
+ if a["content"]["content_type"]=="application/x-ldt-video":
typeNode.text = "video"
else:
typeNode.text = "audio"
@@ -213,7 +213,7 @@
embedcodeNode = lxml.etree.SubElement(metaNode, 'embedcode')
embedcodeNode.text = lxml.etree.CDATA(a["content"]["embedcode"])
# Text bonus
- elif a["content"]["mimetype"]=="application/x-ldt-text":
+ elif a["content"]["content_type"]=="application/x-ldt-text":
typeNode = lxml.etree.SubElement(metaNode, 'type')
typeNode.text = "text"
markupNode = lxml.etree.SubElement(metaNode, 'markup')
@@ -221,7 +221,7 @@
textNode = lxml.etree.SubElement(metaNode, 'text')
textNode.text = lxml.etree.CDATA(a["content"]["text"])
# Links bonus
- elif a["content"]["mimetype"]=="application/x-ldt-links":
+ elif a["content"]["content_type"]=="application/x-ldt-links":
typeNode = lxml.etree.SubElement(metaNode, 'type')
typeNode.text = "links"
linksNode = lxml.etree.SubElement(metaNode, 'links')
@@ -232,7 +232,7 @@
titleNode = lxml.etree.SubElement(linkNode, 'title')
titleNode.text = link["title"]
# Image slideshow bonus
- elif a["content"]["mimetype"]=="application/x-ldt-slideshow":
+ elif a["content"]["content_type"]=="application/x-ldt-slideshow":
typeNode = lxml.etree.SubElement(metaNode, 'type')
typeNode.text = "slideshow"
durationNode = lxml.etree.SubElement(metaNode, 'slideduration')
@@ -427,16 +427,16 @@
error_string += " Each annotation must have 'content/title' and 'content/description' fields."
do_break = True
# Test for metadatacomposer extra datas, type video, audio, text, links or slideshow
- if "mimetype" in a["content"]:
- if a["content"]["mimetype"]=="application/x-ldt-video" or a["content"]["mimetype"]=="application/x-ldt-audio":
+ if "content_type" in a["content"]:
+ if a["content"]["content_type"]=="application/x-ldt-video" or a["content"]["content_type"]=="application/x-ldt-audio":
if not "url" in a["content"] or not "embedcode" in a["content"]:
error_string += " A video or audio annotation must have 'content/url' and 'content/embedcode' fields."
do_break = True
- elif a["content"]["mimetype"]=="application/x-ldt-text":
+ elif a["content"]["content_type"]=="application/x-ldt-text":
if not "markup" in a["content"] or not "text" in a["content"]:
error_string += " A text annotation must have 'content/markup' and 'content/text' fields."
do_break = True
- elif a["content"]["mimetype"]=="application/x-ldt-links":
+ elif a["content"]["content_type"]=="application/x-ldt-links":
if not "links" in a["content"]:
error_string += " A links annotation must have 'content/links' field."
do_break = True
@@ -445,7 +445,7 @@
if not "url" in l or not "title" in l:
error_string += " Each link in links annotation must have 'url' and 'title' fields."
do_break = True
- elif a["content"]["mimetype"]=="application/x-ldt-slideshow":
+ elif a["content"]["content_type"]=="application/x-ldt-slideshow":
if not "slideduration" in a["content"] or not "autostart" in a["content"] or not "images" in a["content"]:
error_string += " A slideshow annotation must have 'content/slideduration' and 'content/autostart' and 'content/images' fields."
do_break = True
--- a/src/ldt/ldt/ldt_utils/admin.py Thu Apr 09 12:58:31 2015 +0200
+++ b/src/ldt/ldt/ldt_utils/admin.py Tue Apr 21 15:05:22 2015 +0200
@@ -118,7 +118,7 @@
content.seek(0)
out = content.getvalue()
content.close()
- res = HttpResponse(out, mimetype='application/json')
+ res = HttpResponse(out, content_type='application/json')
res["Content-Disposition"] = "attachment; filename=dumpdata_ldt.json"
return res
return render_to_response('admin/ldt_utils/content/dumpdata.html', {}, context_instance=RequestContext(request))
--- a/src/ldt/ldt/ldt_utils/projectserializer.py Thu Apr 09 12:58:31 2015 +0200
+++ b/src/ldt/ldt/ldt_utils/projectserializer.py Tue Apr 21 15:05:22 2015 +0200
@@ -2,7 +2,7 @@
from django.conf import settings
from django.contrib.auth import get_user_model
from django.contrib.contenttypes.models import ContentType
-from django.utils.datastructures import SortedDict
+from collections import OrderedDict
from ldt.ldt_utils.models import Content, Project
from ldt.ldt_utils.stat import get_string_from_buckets
from ldt.ldt_utils.utils import reduce_text_node
@@ -26,14 +26,14 @@
self.project = project
self.parsed = False
self.ldt_doc = None
- self.medias_dict = SortedDict()
- self.annotations_dict = SortedDict()
+ self.medias_dict = OrderedDict()
+ self.annotations_dict = OrderedDict()
self.annotations_by_annotation_types = {}
self.tags = {}
- self.tags_dict = SortedDict()
- self.annotation_types_dict = SortedDict()
- self.views_dict = SortedDict()
- self.lists_dict = SortedDict()
+ self.tags_dict = OrderedDict()
+ self.annotation_types_dict = OrderedDict()
+ self.views_dict = OrderedDict()
+ self.lists_dict = OrderedDict()
self.serialize_contents = from_contents
self.from_display = from_display
self.display_contents_list = []
@@ -198,7 +198,7 @@
if len(element_source_node_list) > 0:
element_source_node = element_source_node_list[0]
- element_source = {"mimetype" :element_source_node.get(u'mimetype'), "url":element_source_node.get(u'url'), "content":reduce_text_node(element_source_node)}
+ element_source = {"content_type" :element_source_node.get(u'content_type'), "url":element_source_node.get(u'url'), "content":reduce_text_node(element_source_node)}
else:
element_source = None
@@ -231,8 +231,8 @@
tag_date = datetime.utcnow().isoformat()
for tag_title in tags_list:
if tag_title not in self.tags:
- # hashlib instead of uuid to get an almost unicity
- tag_id = unicode(hashlib.new(tag_title.encode('utf-8')).hexdigest())
+ # md5 instead of uuid to get an almost unicity
+ tag_id = unicode(hashlib.md5(tag_title.encode('utf-8')).hexdigest())
new_tag = {
"id":tag_id,
"meta" : {
@@ -265,7 +265,7 @@
"media": element_media,
"color": element_color,
"content": {
- "mimetype": "application/x-ldt-structured",
+ "content_type": "application/x-ldt-structured",
"title": element_title,
"description": element_description,
#"color": element_color,
@@ -274,7 +274,7 @@
},
"audio": {
"src" : element_audio_src,
- "mimetype": "audio/mp3",
+ "content_type": "audio/mp3",
"href": element_audio_href
},
"polemics" :[pol_elem.text for pol_elem in element_node.xpath("meta/polemics/polemic")],
@@ -298,27 +298,27 @@
meta_type_node = element_node.xpath("meta/type")
if len(meta_type_node) > 0:
meta_type = reduce_text_node(meta_type_node[0], "text()")
- # Update mimetype and add datas
+ # Update content_type and add datas
if meta_type=="video":
- new_annotation["content"]["mimetype"] = "application/x-ldt-video"
+ new_annotation["content"]["content_type"] = "application/x-ldt-video"
new_annotation["content"]["url"] = reduce_text_node(element_node, "meta/url/text()")
new_annotation["content"]["embedcode"] = reduce_text_node(element_node, "meta/embedcode/text()")
elif meta_type=="audio":
- new_annotation["content"]["mimetype"] = "application/x-ldt-audio"
+ new_annotation["content"]["content_type"] = "application/x-ldt-audio"
new_annotation["content"]["url"] = reduce_text_node(element_node, "meta/url/text()")
new_annotation["content"]["embedcode"] = reduce_text_node(element_node, "meta/embedcode/text()")
elif meta_type=="text":
- new_annotation["content"]["mimetype"] = "application/x-ldt-text"
+ new_annotation["content"]["content_type"] = "application/x-ldt-text"
new_annotation["content"]["markup"] = reduce_text_node(element_node, "meta/markup/text()")
new_annotation["content"]["text"] = reduce_text_node(element_node, "meta/text/text()")
elif meta_type=="links":
- new_annotation["content"]["mimetype"] = "application/x-ldt-links"
+ new_annotation["content"]["content_type"] = "application/x-ldt-links"
new_annotation["content"]["links"] = []
link_nodes = element_node.xpath("meta/links/link")
for link in link_nodes:
new_annotation["content"]["links"].append({"url": reduce_text_node(link, "url/text()"), "title":reduce_text_node(link, "title/text()")})
elif meta_type=="slideshow":
- new_annotation["content"]["mimetype"] = "application/x-ldt-slideshow"
+ new_annotation["content"]["content_type"] = "application/x-ldt-slideshow"
new_annotation["content"]["slideduration"] = reduce_text_node(element_node, "meta/slideduration/text()")
new_annotation["content"]["autostart"] = {'true': True, 'false': False, "0": False, "1": True}.get(reduce_text_node(element_node, "meta/autostart/text()").lower())
new_annotation["content"]["images"] = []
@@ -398,8 +398,8 @@
#reorder annotations and annotation type from view
if self.from_display and len(self.views_dict) > 0:
- new_annotation_types_dict = SortedDict()
- new_annotations_dict = SortedDict()
+ new_annotation_types_dict = OrderedDict()
+ new_annotations_dict = OrderedDict()
for annotation_type in self.display_cuttings_list + [self.first_cutting]:
if annotation_type in self.annotation_types_dict:
new_annotation_types_dict[annotation_type] = self.annotation_types_dict[annotation_type]
@@ -544,7 +544,7 @@
project_main_media = ""
if len(self.medias_dict) > 0:
- project_main_media = self.medias_dict.value_for_index(0)["id"]
+ project_main_media = self.medias_dict.iteritems().next()[1]["id"]
res['meta'] = {
'id': self.project.ldt_id,
--- a/src/ldt/ldt/ldt_utils/segmentserializer.py Thu Apr 09 12:58:31 2015 +0200
+++ b/src/ldt/ldt/ldt_utils/segmentserializer.py Tue Apr 21 15:05:22 2015 +0200
@@ -161,7 +161,7 @@
'color': "%s" % self.default_color,
'media': self.content.iri_id,
'content': {
- 'mimetype': 'application/x-ldt-structured',
+ 'content_type': 'application/x-ldt-structured',
'description': seg.abstract,
'img': {
'src': ''
@@ -170,7 +170,7 @@
'color': self.default_color,
'polemics': [ ],
'audio': {
- 'mimetype': 'audio/mp3',
+ 'content_type': 'audio/mp3',
'src': seg.audio_src,
'href': seg.audio_href
}
--- a/src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/partial/projectslist.html Thu Apr 09 12:58:31 2015 +0200
+++ b/src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/partial/projectslist.html Tue Apr 21 15:05:22 2015 +0200
@@ -18,7 +18,7 @@
{% for project in projects %}
<tr class="imageline {% cycle 'projectscontentsoddline' 'projectscontentsevenline'%}" >
- {% url 'ldt.ldt_utils.views.json.project_json_id' id=project.ldt_id as json_url_id %}
+ {% url 'ldt.ldt_utils.views.ldt_json.project_json_id' id=project.ldt_id as json_url_id %}
{% if is_gecko %}
<td class="cellimg"><div class="cellimgdiv"><a href="{% url 'index_project_full' id=project.ldt_id %}">
{% if project.change or project.owner == user %}
@@ -47,7 +47,7 @@
<td class="cellimg"><div class="cellimgdiv"><img src='{% static "ldt/img/page_copy.png" %}' href="{% url 'ldt.ldt_utils.views.project.copy_project' ldt_id=project.ldt_id group_id=group_id %}" class="ldt_link_copy_project" alt="{% trans 'copy project' %}" title="{% trans 'copy project' %}"/></div></td>
<td class="cellimg">
- <div class="cellimgdiv">
+ <div class="cellimgdiv">
<a href="{% url 'embed_config_v2' %}?json_url={{WEB_URL}}{{json_url_id}}&player_id=player_project_{{project.ldt_id}}&ldt_id={{project.ldt_id}}">
<img src='{% static "ldt/img/plugin.png" %}' id="player_project_{{project.ldt_id}}" class="ldt_link_embed" alt="{% trans 'link json by id' %}" title="{% trans 'link json by id' %}"/>
</a>
--- a/src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/partial/publishedprojectslist.html Thu Apr 09 12:58:31 2015 +0200
+++ b/src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/partial/publishedprojectslist.html Tue Apr 21 15:05:22 2015 +0200
@@ -17,7 +17,7 @@
<tbody class="projectscontentsbody">
{% for project in projects %}
<tr class="imageline {% cycle 'projectscontentsoddline' 'projectscontentsevenline'%}" >
- {% url 'ldt.ldt_utils.views.json.project_json_id' id=project.ldt_id as json_url_id %}
+ {% url 'ldt.ldt_utils.views.ldt_json.project_json_id' id=project.ldt_id as json_url_id %}
{% if is_gecko %}
<td class="cellimg"><div class="cellimgdiv"><a href="{% url 'index_project_full' id=project.ldt_id %}"><img src='{% static "ldt/img/page_eye.png" %}' alt="{% trans 'open ldt' %}" title="{% trans 'open ldt' %}"/></a></div></td>
{% else %}
--- a/src/ldt/ldt/ldt_utils/views/content.py Thu Apr 09 12:58:31 2015 +0200
+++ b/src/ldt/ldt/ldt_utils/views/content.py Tue Apr 21 15:05:22 2015 +0200
@@ -483,16 +483,16 @@
destination_file.close()
# indicate that everything is OK for SWFUpload
- return HttpResponse("ok", mimetype="text/plain")
+ return HttpResponse("ok", content_type="text/plain")
else:
- return HttpResponse("notok", mimetype="text/plain")
+ return HttpResponse("notok", content_type="text/plain")
def remove_temp_file(request):
# The filename arrives with a GET var.
file_path = os.path.join(settings.STREAM_PATH, "tmp/" + request.COOKIES[settings.SESSION_COOKIE_NAME] + "/", ldt_utils_path.sanitize_filename(request.GET["filename"]))
if os.path.exists(file_path):
os.remove(file_path)
- return HttpResponse("remove ok", mimetype="text/plain")
+ return HttpResponse("remove ok", content_type="text/plain")
def get_duration(request):
try:
@@ -504,11 +504,11 @@
dur_arr = m.group(1).split(":")
td = datetime.timedelta(hours=int(dur_arr[0]), minutes=int(dur_arr[1]), seconds=float(dur_arr[2]))
str_duration = str((td.microseconds + (td.seconds + td.days * 24 * 3600) * 10 ** 6) / 10 ** 3)
- return HttpResponse(str_duration, mimetype="text/plain")
+ return HttpResponse(str_duration, content_type="text/plain")
else:
- return HttpResponse("", mimetype="text/plain")
+ return HttpResponse("", content_type="text/plain")
except Exception as inst:
- return HttpResponse(str(inst), mimetype="text/plain")
+ return HttpResponse(str(inst), content_type="text/plain")
@login_required
--- a/src/ldt/ldt/ldt_utils/views/embed/meta.py Thu Apr 09 12:58:31 2015 +0200
+++ b/src/ldt/ldt/ldt_utils/views/embed/meta.py Tue Apr 21 15:05:22 2015 +0200
@@ -27,6 +27,7 @@
iframe_base_url = ""
def get(self, request):
+ print(request.GET)
json_url = request.GET.get("json_url")
player_id = request.GET.get("player_id")
ldt_id = request.GET.get("ldt_id")
--- a/src/ldt/ldt/ldt_utils/views/embed/v2/views.py Thu Apr 09 12:58:31 2015 +0200
+++ b/src/ldt/ldt/ldt_utils/views/embed/v2/views.py Tue Apr 21 15:05:22 2015 +0200
@@ -33,8 +33,9 @@
project_id = project.ldt_id
if not project_id :
return HttpResponseForbidden(_("Parameters project_id or content_id must be given in the url"))
-
+
json_url = reverse("projectjson_id", kwargs={'id':project_id})
+ print(json_url)
player_id = "player_project_" + project_id
ldt_id = project_id
rend_dict = get_datas_for_embed(request, json_url, player_id, ldt_id, self.iframe_base_url)
--- a/src/ldt/ldt/ldt_utils/views/ldt_json.py Thu Apr 09 12:58:31 2015 +0200
+++ b/src/ldt/ldt/ldt_utils/views/ldt_json.py Tue Apr 21 15:05:22 2015 +0200
@@ -45,14 +45,14 @@
if not ldt_auth.check_access(request.user, project):
return HttpResponseForbidden(_("You can not access this project"))
- mimetype = request.REQUEST.get("mimetype")
- if mimetype is None:
- mimetype = "application/json; charset=utf-8"
+ content_type = request.REQUEST.get("content_type")
+ if content_type is None:
+ content_type = "application/json; charset=utf-8"
else:
- mimetype = mimetype.encode("utf-8")
- if "charset" not in mimetype:
- mimetype += "; charset=utf-8"
- resp = HttpResponse(mimetype=mimetype)
+ content_type = content_type.encode("utf-8")
+ if "charset" not in content_type:
+ content_type += "; charset=utf-8"
+ resp = HttpResponse(content_type=content_type)
resp['Cache-Control'] = 'no-cache, must-revalidate'
resp['Pragma'] = 'no-cache'
@@ -123,7 +123,7 @@
# Needed datas for jsonification
now = datetime.now()
project.modification_date = project.creation_date = now
- #return HttpResponse(lxml.etree.tostring(project_xml, pretty_print=True), mimetype="text/xml;charset=utf-8")
+ #return HttpResponse(lxml.etree.tostring(project_xml, pretty_print=True), content_type="text/xml;charset=utf-8")
logger.debug("mashup_by_tag : serialize_to_cinelab prepare")
ps = ProjectJsonSerializer(project, from_contents=False)
@@ -221,7 +221,7 @@
if callback is not None:
json_str = "%s(%s)" % (callback, json_str)
- resp = HttpResponse(mimetype="application/json; charset=utf-8")
+ resp = HttpResponse(content_type="application/json; charset=utf-8")
resp.write(json_str)
return resp
--- a/src/ldt/ldt/ldt_utils/views/lignesdetemps.py Thu Apr 09 12:58:31 2015 +0200
+++ b/src/ldt/ldt/ldt_utils/views/lignesdetemps.py Tue Apr 21 15:05:22 2015 +0200
@@ -40,14 +40,14 @@
doc = ldtgen.generate_init({'field':field, 'query':query}, 'ldt.ldt_utils.views.lignesdetemps.search_ldt', 'ldt.ldt_utils.views.lignesdetemps.search_segments')
- resp = HttpResponse(mimetype="text/xml;charset=utf-8")
+ resp = HttpResponse(content_type="text/xml;charset=utf-8")
resp.write(lxml.etree.tostring(doc, pretty_print=True, encoding="utf-8"))
return resp
def search_ldt(request, field, query, edition=None, return_project=False, query_encoded=True):
- resp = HttpResponse(mimetype="text/xml")
+ resp = HttpResponse(content_type="text/xml")
doc, _ = search_generate_ldt(request, field, query)
doc = absolute_src_xml(doc)
doc.write(resp, pretty_print=True)
@@ -85,7 +85,7 @@
#return doc
- return HttpResponse(lxml.etree.tostring(doc, pretty_print=True), mimetype="text/xml;charset=utf-8")
+ return HttpResponse(lxml.etree.tostring(doc, pretty_print=True), content_type="text/xml;charset=utf-8")
@@ -107,7 +107,7 @@
ldtgen = LdtUtils()
doc = ldtgen.generate_init({'project_id':project_id, 'content_id':content_id, 'ensemble_id':ensemble_id, 'cutting_id':cutting_id, 'segment_id':segment_id}, 'ldt.ldt_utils.views.lignesdetemps.ldt_segment', 'ldt.ldt_utils.views.lignesdetemps.highlight_segment')
- return HttpResponse(lxml.etree.tostring(lxml.etree.ElementTree(doc), pretty_print=True), mimetype="text/xml;charset=utf-8")
+ return HttpResponse(lxml.etree.tostring(lxml.etree.ElementTree(doc), pretty_print=True), content_type="text/xml;charset=utf-8")
def highlight_segment(request, project_id, content_id, ensemble_id, cutting_id, segment_id):
if project_id != u"_":
@@ -124,12 +124,12 @@
seg.set('idvue', "")
seg.set('crit', "")
- return HttpResponse(lxml.etree.tostring(doc, pretty_print=True), mimetype="text/xml;charset=utf-8")
+ return HttpResponse(lxml.etree.tostring(doc, pretty_print=True), content_type="text/xml;charset=utf-8")
def ldt_segment(request, project_id, content_id, ensemble_id, cutting_id, segment_id):
- resp = HttpResponse(mimetype="text/xml")
+ resp = HttpResponse(content_type="text/xml")
resp['Cache-Control'] = 'no-cache, must-revalidate'
resp['Pragma'] = 'no-cache'
@@ -268,7 +268,7 @@
elem.set('pict', '')
elem.set('img', '')
- resp = HttpResponse(mimetype="text/xml")
+ resp = HttpResponse(content_type="text/xml")
resp['Cache-Control'] = 'no-cache, must-revalidate'
resp['Pragma'] = 'no-cache'
@@ -277,7 +277,7 @@
@never_cache
def ldt_project(request, id): # @ReservedAssignment
- resp = HttpResponse(mimetype="text/xml")
+ resp = HttpResponse(content_type="text/xml")
resp['Cache-Control'] = 'no-cache, must-revalidate'
resp['Pragma'] = 'no-cache'
@@ -377,7 +377,7 @@
def ldt(request, url, startSegment=None):
- resp = HttpResponse(mimetype="text/xml; charset=utf-8")
+ resp = HttpResponse(content_type="text/xml; charset=utf-8")
resp['Cache-Control'] = 'no-cache'
contentList = Content.safe_objects.filter(iri_id=url) #@UndefinedVariable
--- a/src/ldt/ldt/ldt_utils/views/rdf.py Thu Apr 09 12:58:31 2015 +0200
+++ b/src/ldt/ldt/ldt_utils/views/rdf.py Tue Apr 21 15:05:22 2015 +0200
@@ -14,14 +14,14 @@
if not ldt_auth.check_access(request.user, project):
return HttpResponseForbidden(_("You can not access this project"))
- mimetype = request.REQUEST.get("mimetype")
- if mimetype is None:
- mimetype = "application/rdf+xml; charset=utf-8"
+ content_type = request.REQUEST.get("content_type")
+ if content_type is None:
+ content_type = "application/rdf+xml; charset=utf-8"
else:
- mimetype = mimetype.encode("utf-8")
- if "charset" not in mimetype:
- mimetype += "; charset=utf-8"
- resp = HttpResponse(mimetype=mimetype)
+ content_type = content_type.encode("utf-8")
+ if "charset" not in content_type:
+ content_type += "; charset=utf-8"
+ resp = HttpResponse(content_type=content_type)
resp['Cache-Control'] = 'no-cache, must-revalidate'
resp['Pragma'] = 'no-cache'