- document = storage.get(name, revision = int(version))
- except DocumentNotFound:
- raise Http404
-
- poster.streaminghttp.register_openers()
-
- # send request to WL
- http = httplib2.Http()
- http.add_credentials("test", "test")
- http.follow_all_redirects = True
- datagen, headers = poster.encode.multipart_encode({name: document.plain_text})
-
- for key, value in headers.items():
- headers[key] = unicode(value)
-
- try:
- resp, data = http.request("http://localhost:8000/api/books.json",
- method = "POST", body = ''.join(datagen), headers = headers)
-
- print resp, data
-
- if resp.status == 201: # success
- result = {"success": True}
- else:
- result = {"success": False, "errno": resp.status, "reason": resp.reason}
- except Exception, e:
- result = {"success": False, "errno": 500, "reason": unicode(e)}
-
- return HttpResponse( json.dumps(result), mimetype='application/json')
\ No newline at end of file
+ return JSONResponse({"result": api.publish_book(document)})
+ except wlapi.APICallException, e:
+ return JSONServerError({"message": str(e)})