-def document_publish(request, name, version):
- # get the document
- try:
- document = storage.get(name, revision = int(version))
- except DocumentNotFound:
- raise Http404
-
- auth_handler = urllib2.HTTPDigestAuthHandler();
- auth_handler.add_password(
- realm="localhost:8000",
- uri="http://localhost:8000/api/",
- user="test", passwd="test")
-
-
- 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
+def history(request, chunk_id):
+ # TODO: pagination
+ doc = get_object_or_404(Chunk, pk=chunk_id)
+ if not doc.book.accessible(request):
+ return HttpResponseForbidden("Not authorized.")
+
+ changes = []
+ for change in doc.history().reverse():
+ changes.append({
+ "version": change.revision,
+ "description": change.description,
+ "author": change.author_str(),
+ "date": localize(change.created_at),
+ "publishable": _("Publishable") + "\n" if change.publishable else "",
+ "tag": ',\n'.join(unicode(tag) for tag in change.tags.all()),
+ })
+ return JSONResponse(changes)
+
+
+@require_POST
+@ajax_require_permission('catalogue.can_pubmark')
+def pubmark(request, chunk_id):
+ form = forms.DocumentPubmarkForm(request.POST, prefix="pubmark")
+ if form.is_valid():
+ doc = get_object_or_404(Chunk, pk=chunk_id)
+ if not doc.book.accessible(request):
+ return HttpResponseForbidden("Not authorized.")
+
+ revision = form.cleaned_data['revision']
+ publishable = form.cleaned_data['publishable']
+ change = doc.at_revision(revision)
+ if publishable != change.publishable:
+ change.set_publishable(publishable)
+ return JSONResponse({"message": _("Revision marked")})
+ else:
+ return JSONResponse({"message": _("Nothing changed")})
+ else:
+ return JSONFormInvalid(form)
+
+
+def themes(request):
+ prefix = request.GET.get('q', '')
+ return http.HttpResponse('\n'.join([str(t) for t in Theme.objects.filter(name__istartswith=prefix)]))