-def document_history(reuqest, name):
- return HttpResponse( json.dumps(storage.history(name), cls=DateTimeEncoder), mimetype='application/json')
+
+ opener = urllib2.build_opener(auth_handler)
+ rq = urllib2.Request("http://localhost:8000/api/books.json")
+ rq.add_data(json.dumps({"text": document.text, "compressed": False}))
+ rq.add_header("Content-Type", "application/json")
+
+ try:
+ response = opener.open(rq)
+ result = {"success": True, "message": response.read()}
+ except urllib2.HTTPError, e:
+ logger.exception("Failed to send")
+ if e.code == 500:
+ return HttpResponse(e.read(), mimetype='text/plain')
+ result = {"success": False, "reason": e.read(), "errno": e.code}
+
+ return HttpResponse( json.dumps(result), mimetype='application/json')
\ No newline at end of file