# HG changeset patch # User verrierj # Date 1318348320 -7200 # Node ID 3d919c59b46f43ecd12a2bba5af4ec8a1de6394e # Parent 202107fff250747e0e78d6b4247c271bee6c2608 Fixed view bug in annotation handler diff -r 202107fff250 -r 3d919c59b46f src/ldt/ldt/api/ldt/handlers.py --- a/src/ldt/ldt/api/ldt/handlers.py Tue Oct 11 14:46:40 2011 +0200 +++ b/src/ldt/ldt/api/ldt/handlers.py Tue Oct 11 17:52:00 2011 +0200 @@ -21,12 +21,12 @@ """ This method is called when a PUT request is sent to http:///api/ldt/projects/.format. The request should contain a content-type header whose value can be either "application/json" or "text/xml" and a valid utf-8 - encoded JSON Cinelab or LDT XML file. + encoded JSON or XML file. is the ldt_id field of the project. If does not match any project on the platform, a 410 ("Gone") error will be returned. is the format of the data sent back by the server. It can be 'json', 'yaml', 'xml' or 'pickle'. - If the submitted file is not valid or if the file refers to a media that is not contained in the project, a 500 ("Bad Request") + 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). 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 diff -r 202107fff250 -r 3d919c59b46f src/ldt/ldt/ldt_utils/utils.py --- a/src/ldt/ldt/ldt_utils/utils.py Tue Oct 11 14:46:40 2011 +0200 +++ b/src/ldt/ldt/ldt_utils/utils.py Tue Oct 11 17:52:00 2011 +0200 @@ -169,7 +169,7 @@ self.ldtdoc = lxml.etree.parse(StringIO(project.ldt.encode("utf-8")), self.parser) self.to_add = True - def add(self, media, cutting, title, text, tags_list, begin, dur, author, date, color="16776960"): + def add(self, media, cutting, title, text, tags_list, begin, dur, author, date, view="View at the last recording", color="16776960"): """ Add an annotation to a project. begin and dur must be strings. Default color is yellow. """ @@ -180,6 +180,11 @@ self.to_add = False return False + path_view = self.ldtdoc.xpath('/iri/displays/display[@title="%s"]' % view) + if len(path_view) == 0: + self.to_add = False, + return False + path_annotations = self.ldtdoc.xpath('/iri/annotations')[0] path_content = path_annotations.xpath('content[@id="%s"]' % media) @@ -199,16 +204,31 @@ path_ensemble.set('author', 'undefined') path_ensemble = [path_ensemble] + ensemble_id = path_ensemble[0].get('id') decoupage_elements = path_ensemble[0].xpath('decoupage[title="%s"]/elements' % cutting) if len(decoupage_elements) == 0: decoupage = lxml.etree.SubElement(path_ensemble[0], 'decoupage') - decoupage.set('id', 'c_' + generate_uuid()) + cutting_id = 'c_' + generate_uuid() + decoupage.set('id', cutting_id) decoupage.set('author', author) decoupage_title = lxml.etree.SubElement(decoupage, 'title') decoupage_title.text = cutting lxml.etree.SubElement(decoupage, 'abstract') decoupage_elements = lxml.etree.SubElement(decoupage, 'elements') - decoupage_elements = [decoupage_elements] + decoupage_elements = [decoupage_elements] + else: + cutting_id = decoupage_elements[0].get('id') + + content_display = path_view[0].xpath('content[@id="%s"]' % media) + if len(content_display) == 0: + content_display = lxml.etree.SubElement(path_view[0], 'content') + content_display.set('id', media) + content_display = [content_display] + + dec = lxml.etree.SubElement(content_display[0], 'decoupage') + dec.set('idens', ensemble_id) + dec.set('id', cutting_id) + dec.set('tagsSelect', '') element = lxml.etree.SubElement(decoupage_elements[0], 'element') element.set('id', 's_' + generate_uuid())