| changeset 10 | 000f3ca19eaa |
| parent 9 | 22ab430e9b64 |
| child 15 | 37e051f2264d |
| 9:22ab430e9b64 | 10:000f3ca19eaa |
|---|---|
98 |
98 |
99 ## Creates an annotation from a urlencoded xml content |
99 ## Creates an annotation from a urlencoded xml content |
100 ## Returns an xml-structured annotation |
100 ## Returns an xml-structured annotation |
101 #@login_required |
101 #@login_required |
102 def create_annotation(request, content): |
102 def create_annotation(request, content): |
103 cont = base64.urlsafe_b64decode(request.POST["content"]) |
103 cont = base64.urlsafe_b64decode(str(request.POST["content"])) |
104 doc = lxml.etree.fromstring(cont) |
104 doc = lxml.etree.fromstring(cont) |
105 |
105 |
106 id = unicode(doc.xpath("/iri/text-annotation/id/text()")[0]) |
106 id = unicode(doc.xpath("/iri/text-annotation/id/text()")[0]) |
107 if id is None: |
107 if id is None: |
108 id = generate_uuid() |
108 id = generate_uuid() |
126 try: |
126 try: |
127 annotation = Annotation.create_annotation(external_id=id, uri=uri, tags=tags, title=title, description=desc, text=text, color=color, creator=creator, contributor=contributor, creation_date=creation_date, update_date=update_date) |
127 annotation = Annotation.create_annotation(external_id=id, uri=uri, tags=tags, title=title, description=desc, text=text, color=color, creator=creator, contributor=contributor, creation_date=creation_date, update_date=update_date) |
128 annotation.save() |
128 annotation.save() |
129 return HttpResponse(lxml.etree.tostring(doc, pretty_print=True), mimetype="text/xml;charset=utf-8") |
129 return HttpResponse(lxml.etree.tostring(doc, pretty_print=True), mimetype="text/xml;charset=utf-8") |
130 #return doc |
130 #return doc |
131 except: |
131 except IntegrityError: |
132 #except Annotation.IntegrityError: |
132 #except Annotation.IntegrityError: |
133 #print 'This id is already used! Please choose another one!' |
133 #print 'This id is already used! Please choose another one!' |
134 raise CONFLICT |
134 return HttpResponse(status=409) |
135 |
135 |
136 |
136 |
137 |
137 |
138 ## Gets an annotation (from its id) |
138 ## Gets an annotation (from its id) |
139 ## Returns the xml-structured annotation |
139 ## Returns the xml-structured annotation |
209 annot = Annotation.objects.get(external_id=request.POST["id"]) |
209 annot = Annotation.objects.get(external_id=request.POST["id"]) |
210 #except Annotation.DoesNotExist: |
210 #except Annotation.DoesNotExist: |
211 except: |
211 except: |
212 raise Http404 |
212 raise Http404 |
213 |
213 |
214 cont = base64.urlsafe_b64decode(request.POST["content"]) |
214 cont = base64.urlsafe_b64decode(str(request.POST["content"])) |
215 doc = lxml.etree.fromstring(cont) |
215 doc = lxml.etree.fromstring(cont) |
216 |
216 |
217 uri = doc.xpath("/iri/text-annotation/uri/text()") |
217 uri = doc.xpath("/iri/text-annotation/uri/text()") |
218 if uri != [] and annot.uri != uri[0]: |
218 if uri != [] and annot.uri != uri[0]: |
219 annot.uri = unicode(uri[0]) |
219 annot.uri = unicode(uri[0]) |