# HG changeset patch # User cavaliet # Date 1343728284 -7200 # Node ID a25d344cb446a82c64ca6c9cc311e903d3afb90c # Parent 202fb1255d8b7b4281c161bb914dc3dd6a44279b second step for mashup json (works fine but does not sort mashup by weight). diff -r 202fb1255d8b -r a25d344cb446 src/ldt/ldt/ldt_utils/utils.py --- a/src/ldt/ldt/ldt_utils/utils.py Mon Jul 30 18:23:34 2012 +0200 +++ b/src/ldt/ldt/ldt_utils/utils.py Tue Jul 31 11:51:24 2012 +0200 @@ -46,7 +46,7 @@ res = [] for hit in hits: doc = indexSearcher.doc(hit.doc) - res.append({"iri_id":doc.get("iri_id"), "ensemble_id":doc.get("ensemble_id"), "decoupage_id":doc.get("decoupage_id"), "element_id":doc.get("element_id"), "project_id":doc.get("project_id")}) + res.append({"iri_id":doc.get("iri_id"), "ensemble_id":doc.get("ensemble_id"), "decoupage_id":doc.get("decoupage_id"), "element_id":doc.get("element_id"), "project_id":doc.get("project_id"), "begin":doc.get("begin"), "duration":doc.get("duration")}) indexSearcher.close() return res diff -r 202fb1255d8b -r a25d344cb446 src/ldt/ldt/ldt_utils/views/json.py --- a/src/ldt/ldt/ldt_utils/views/json.py Mon Jul 30 18:23:34 2012 +0200 +++ b/src/ldt/ldt/ldt_utils/views/json.py Tue Jul 31 11:51:24 2012 +0200 @@ -81,12 +81,6 @@ def mashup_by_tag(request): - mashup_dict = { - "id": u"display_ïd", - "contents": u"contenté_list", - "annotation_types": u"çùttings_list", - } - # do we indent ? indent = request.REQUEST.get("indent") if indent is None: @@ -99,49 +93,57 @@ if escape_str: escape_bool = {'true': True, 'false': False, "0": False, "1": True}.get(escape_str.lower()) - mashup_dict["escape_bool"] = escape_bool - mashup_dict["indent"] = indent - # We search s = request.REQUEST.get("tag") if s: - #results = get_results_with_context("tags", s) - # We get the projects with all the segments - project_xml = search_ldt(request, "tags", s, None, True, False) + project_xml, results = search_ldt(request, "tags", s, None, True, False) project = Project() project.ldt = lxml.etree.tostring(project_xml, pretty_print=True) - # Useful datas - project.modification_date = project.creation_date = datetime.now() + # 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") ps = ProjectSerializer(project, from_contents=False) - #project_dict = ps.serialize_to_cinelab() mashup_dict = ps.serialize_to_cinelab() - - - -# tc_in = 0 -# if request.REQUEST.get("in") : -# tc_in = float(request.REQUEST.get("in")) -# tc_out = float('inf') -# if request.REQUEST.get("out") : -# tc_out = float(request.REQUEST.get("out")) -# # Since the timecodes are saved as strings, we filter after calculating float in and out. Timecodes have to be in milliseconds -# filtered_results = [] -# for res in results: -# cur_in = float(res["begin"]) -# cur_out = cur_in + float(res["duration"]) -# if tc_in<=cur_in and cur_out<=tc_out: -# filtered_results.append(res) -# mashup_dict["results"] = filtered_results + # Now we build the mashup with the good segments (the ones between in and out) + if results: + tc_in = 0 + if request.REQUEST.get("in") : + tc_in = float(request.REQUEST.get("in")) + tc_out = float('inf') + if request.REQUEST.get("out") : + tc_out = float(request.REQUEST.get("out")) + # Since the timecodes are saved as strings, we filter after calculating float in and out. Timecodes are in milliseconds + mashup_list = { + "items": [], + "meta": { + "dc:contributor": "IRI", + "dc:creator": "IRI", + "dc:title": "Generated mashup with tag '"+s+"'", + "dc:modified": now.isoformat(), + "dc:created": now.isoformat(), + "listtype": "mashup", + "dc:description": "" + }, + "id": "generated_mashup_list" + } + #filtered_results = [] + for res in results: + cur_in = float(res["begin"]) + cur_out = cur_in + float(res["duration"]) + if tc_in<=cur_in and cur_out<=tc_out: + #filtered_results.append(res) + mashup_list["items"].append(res["element_id"]) + mashup_dict["lists"].append(mashup_list) - + #mashup_dict["escape_bool"] = escape_bool + #mashup_dict["indent"] = indent json_str = simplejson.dumps(mashup_dict, ensure_ascii=False, indent=indent) if escape_bool: json_str = escape(json_str) - resp = HttpResponse(mimetype="application/json; charset=utf-8") resp['Cache-Control'] = 'no-cache, must-revalidate' resp['Pragma'] = 'no-cache' diff -r 202fb1255d8b -r a25d344cb446 src/ldt/ldt/ldt_utils/views/lignesdetemps.py --- a/src/ldt/ldt/ldt_utils/views/lignesdetemps.py Mon Jul 30 18:23:34 2012 +0200 +++ b/src/ldt/ldt/ldt_utils/views/lignesdetemps.py Tue Jul 31 11:51:24 2012 +0200 @@ -45,8 +45,8 @@ ids = {} projIds = {} typesIds = {} - - for result in searcher.query(field, queryStr): + results = searcher.query(field, queryStr) + for result in results: ids[result["iri_id"]] = "" projIds[result["project_id"]] = "" typesIds[result["decoupage_id"]] = "" @@ -67,7 +67,7 @@ doc = ldtgen.generate_ldt(contentList, title=u"Recherche : " + queryStr, projects=projectList, types_id_list=typesId_list) doc = set_forbidden_stream(doc, request.user) if return_project: - return doc + return doc, results doc.write(resp, pretty_print=True) return resp