+def document_history(request, name):
+ return HttpResponse(
+ json.dumps(storage.history(name), cls=DateTimeEncoder),
+ mimetype='application/json')
+
+
+def document_publish(request, name, version):
+ # get the document
+ try:
+ 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