# HG changeset patch # User verrierj # Date 1319619943 -7200 # Node ID 3dcd742acc13f448c683aba2ccc1674dc0bc545a # Parent 3b1ef78831023ad05c40f6af5ef452195d4240a8 API return ID of added annotations diff -r 3b1ef7883102 -r 3dcd742acc13 src/ldt/ldt/api/ldt/handlers.py --- a/src/ldt/ldt/api/ldt/handlers.py Tue Oct 25 16:34:01 2011 +0200 +++ b/src/ldt/ldt/api/ldt/handlers.py Wed Oct 26 11:05:43 2011 +0200 @@ -31,7 +31,8 @@ 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 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. 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 + a['id'] = new_id - return rc.ALL_OK + return request.data else: logging.debug("request " + repr(request)) diff -r 3b1ef7883102 -r 3dcd742acc13 src/ldt/ldt/ldt_utils/utils.py --- a/src/ldt/ldt/ldt_utils/utils.py Tue Oct 25 16:34:01 2011 +0200 +++ b/src/ldt/ldt/ldt_utils/utils.py Wed Oct 26 11:05:43 2011 +0200 @@ -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: