+ if request.POST.has_key('message'):
+ msg = u"$USER$ " + request.POST['message']
+ else:
+ msg = u"$AUTO$ XML content update."
+
+ if request.POST.has_key('contents'):
+ data = request.POST['contents']
+ else:
+ if not request.POST.has_key('chunks'):
+ # bad request
+ return response.BadRequest().django_response({'reason': 'invalid-arguments',
+ 'message': 'No contents nor chunks specified.'})
+
+ # TODO: validate
+ parts = json.loads(request.POST['chunks'])
+ xdoc = parser.WLDocument.from_string(current.data('xml'))
+
+ errors = xdoc.merge_chunks(parts)
+
+ if len(errors):
+ return response.EntityConflict().django_response({
+ "reason": "invalid-chunks",
+ "message": "Unable to merge following parts into the document: %s " % ",".join(errors)
+ })
+
+ data = xdoc.serialize()
+