# HG changeset patch # User verrierj # Date 1320921495 -3600 # Node ID a413a997a5e245ddbe86a1008a8404b8bd0621e3 # Parent fff164d7d6ad1235c75a259306c1e7e13f075d9b# Parent d2e1bc8cf3905e24122accc0fca406032287f13e Merge with d2e1bc8cf3905e24122accc0fca406032287f13e diff -r d2e1bc8cf390 -r a413a997a5e2 src/ldt/ldt/api/ldt/handlers.py --- a/src/ldt/ldt/api/ldt/handlers.py Mon Nov 07 13:04:54 2011 +0100 +++ b/src/ldt/ldt/api/ldt/handlers.py Thu Nov 10 11:38:15 2011 +0100 @@ -29,9 +29,10 @@ If the submitted file is not valid or refers to a media that is not contained in the project, a 500 ("Bad Request") error will be returned. If the "type" field of an annotation matches an already existing cutting, it will be added to that cutting. Otherwise, a new cutting will be added (as well as a new ensemble if needed). New cuttings are added to the view - "View at the last recording" if it exists, or the the view "Init view" else. If none of those views exist, the server will + "View at the last recording" if it exists, or to the view "Init view" else. If none of those views exist, the server will not add the cutting to a view. Several annotations can be added at the same time if the submitted file contains multiple - annotations. The server returns a 201 ("Created") code if annotations have been added successfully. + annotations. The server returns the file submitted if all annotations have been added successfully, and adds to this file + IDs of created annotations to the file with a 200("OK") error code. If no content-type header is set, the file submitted must be a valid XML file and will replace entirely the ldt field of the project without any verifications. @@ -77,7 +78,39 @@ If we send a PUT request with curl : $curl -X PUT http://localhost/api/ldt/projects/a0593b58-f258-11df-80e1-00145ea4a2be.json -d @example.JSON -H "content-type:application/json" A new cutting titled "New cutting name" will be created with the first annotation inside, and the annotation "Annotation about Salieri" - will be added to the Salieri cutting. + will be added to the Salieri cutting. The returned file is : + + { + "annotations": [ + { + "id": "6d8baf01-ffb1-11e0-810c-001485352c9a", + "type": "New cutting name", + "media": "milosforman_amadeus", + "begin": 50000, + "end": 900000, + "content": { + "data": "new annotation" + }, + "tags": [ "json" ] + }, + { + "id": "6d8baf00-ffb1-11e0-8097-001485352c9a", + "type": "Salieri", + "media": "milosforman_amadeus", + "begin": 700000, + "end": 1200000, + "content": { + "data": "Annotation about Salieri" + }, + "tags": [ "xml", "test", "blop" ] + } + ], + + "meta": { + "creator": "John Doe", + "created": "2011-09-10T09:12:58" + } + } """ @@ -98,10 +131,12 @@ for a in new_annotations: dur = str(a['end'] - a['begin']) begin = str(a['begin']) - if not adder.add(a['media'], a['type'], a['content']['data'], '', a['tags'], begin, dur, author, date): + new_id = adder.add(a['media'], a['type'], a['content']['data'], '', a['tags'], begin, dur, author, date) + if not new_id: return rc.BAD_REQUEST - - return rc.ALL_OK + a['id'] = new_id + + return request.data else: logging.debug("request " + repr(request)) diff -r d2e1bc8cf390 -r a413a997a5e2 src/ldt/ldt/ldt_utils/middleware/userprofile.py --- a/src/ldt/ldt/ldt_utils/middleware/userprofile.py Mon Nov 07 13:04:54 2011 +0100 +++ b/src/ldt/ldt/ldt_utils/middleware/userprofile.py Thu Nov 10 11:38:15 2011 +0100 @@ -1,12 +1,16 @@ from django.utils import translation +from django.conf import settings class LanguageMiddleware(object): def process_request(self, request): if request.user.is_authenticated(): language = request.user.get_profile().language - translation.activate(language) - request.LANGUAGE_CODE = translation.get_language() + else: + language = settings.LANGUAGE_CODE[:2] + + translation.activate(language) + request.LANGUAGE_CODE = translation.get_language() \ No newline at end of file diff -r d2e1bc8cf390 -r a413a997a5e2 src/ldt/ldt/ldt_utils/models.py --- a/src/ldt/ldt/ldt_utils/models.py Mon Nov 07 13:04:54 2011 +0100 +++ b/src/ldt/ldt/ldt_utils/models.py Thu Nov 10 11:38:15 2011 +0100 @@ -383,6 +383,29 @@ else: return False + def save(self): + doc = lxml.etree.fromstring(self.ldt) + self.contents.clear() + medias = doc.xpath('/iri/medias/media') + + # Remove html tags added by flash if necessary + begin_str = "KERNING=\"0\">" + description = self.get_description(doc) + begin = description.find(begin_str) + len(begin_str) + end = description.find(" 0 and end > 0: + description = description[begin:end] + desc_node = doc.xpath('/iri/project')[0] + desc_node.set('abstract', description) + self.ldt = lxml.etree.tostring(doc, pretty_print=True) + + for media in medias: + iri_id = media.get('id') + c = Content.objects.get(iri_id=iri_id) + self.contents.add(c) + + super(Project, self).save() class Segment(models.Model): diff -r d2e1bc8cf390 -r a413a997a5e2 src/ldt/ldt/ldt_utils/tests.py --- a/src/ldt/ldt/ldt_utils/tests.py Mon Nov 07 13:04:54 2011 +0100 +++ b/src/ldt/ldt/ldt_utils/tests.py Thu Nov 10 11:38:15 2011 +0100 @@ -81,10 +81,9 @@ self.cont4.save() self.project.contents.add(self.cont3, self.cont4) - ldoc = self.LU.generate_init(None, None) + ldoc = self.LU.generate_init(['all', 'foo'], 'ldt.ldt_utils.views.search_ldt') self.assertEqual(ldoc.xpath("/iri/files/init")[0].tag, "init") self.assertEqual(ldoc.xpath("/iri/files/library")[0].tag, "library") - self.assertEqual(ldoc.xpath("/iri/files/init/file")[0].get("video"), settings.STREAM_URL) def test_create_ldt(self): self.cont5 = Content(iriurl="id5/iriurl1") diff -r d2e1bc8cf390 -r a413a997a5e2 src/ldt/ldt/ldt_utils/utils.py --- a/src/ldt/ldt/ldt_utils/utils.py Mon Nov 07 13:04:54 2011 +0100 +++ b/src/ldt/ldt/ldt_utils/utils.py Thu Nov 10 11:38:15 2011 +0100 @@ -231,7 +231,8 @@ dec.set('tagsSelect', '') element = lxml.etree.SubElement(decoupage_elements[0], 'element') - element.set('id', 's_' + generate_uuid()) + id_annotation = generate_uuid() + element.set('id', 's_' + id_annotation) element.set('begin', begin) element.set('dur', dur) element.set('author', author) @@ -249,7 +250,7 @@ tag_node = lxml.etree.SubElement(tags, 'tag') tag_node.text = tag - return True + return id_annotation def save(self): if self.to_add: diff -r d2e1bc8cf390 -r a413a997a5e2 src/ldt/ldt/ldt_utils/views.py --- a/src/ldt/ldt/ldt_utils/views.py Mon Nov 07 13:04:54 2011 +0100 +++ b/src/ldt/ldt/ldt_utils/views.py Thu Nov 10 11:38:15 2011 +0100 @@ -42,7 +42,7 @@ @login_required def workspace(request): - + # list of contents content_list = Content.objects.all() #@UndefinedVariable @@ -231,7 +231,7 @@ desc = content.description complete_results.append({'list' : segments, 'score' : score, 'content_title' : content.title, 'content_id' : content.iri_id, 'content_description' : desc }) complete_results.sort(key=lambda k: k['score']) - + request.session['complete_results'] = complete_results request.session['search'] = search request.session['field'] = field @@ -251,12 +251,11 @@ else: return HttpResponseRedirect(reverse('ldt.ldt_utils.views.published_project')) - +@login_required def search_listing(request): - if not request.session.__contains__('complete_results'): - msg = _("Please enter valid keywords.") - return render_to_response('ldt/ldt_utils/search_results.html', {'msg' : msg}, context_instance=RequestContext(request)) - + if not request.session.has_key('complete_results'): + return HttpResponseRedirect(reverse('ldt.ldt_utils.views.published_project')) + complete_results = request.session.get('complete_results') search = request.session.get('search') field = request.session.get('field') @@ -500,7 +499,8 @@ return resp # ldtgen. - + +@login_required def index_project(request, id, full=False): urlStr = settings.WEB_URL + reverse("space_ldt_init", args=['ldt_project', id]) @@ -525,6 +525,17 @@ ldtgen = LdtUtils() doc = ldtgen.generate_init([url], 'ldt.ldt_utils.views.' + method, None) + + library = doc.xpath('/iri/files/library')[0] + for c in Content.objects.all(): + elem = lxml.etree.SubElement(library, 'file') + elem.set('src', c.iri_url()) + elem.set('video', c.videopath) + elem.set('title', c.title) + elem.set('author', '') + elem.set('category', '') + elem.set('pict', '') + elem.set('img', '') resp = HttpResponse(mimetype="text/xml") resp['Cache-Control'] = 'no-cache, must-revalidate' @@ -767,7 +778,7 @@ def update_project(request, ldt_id): project = get_object_or_404(Project, ldt_id=ldt_id) - contents = project.contents.all() + contents = project.contents.all() if request.method == "POST" : submit_action = request.REQUEST.get("submit_button", False) if submit_action == "prepare_delete": diff -r d2e1bc8cf390 -r a413a997a5e2 src/ldt/ldt/static/ldt/img/clipboard.png Binary file src/ldt/ldt/static/ldt/img/clipboard.png has changed