- return HttpResponse(json.dumps(images))
- except (IndexError, OSError), exc:
- import traceback
- traceback.print_exc()
-
- raise Http404
-
-def document_diff(request, name, revA, revB):
- differ = difflib.HtmlDiff(wrapcolumn=60)
-
- docA = storage.get(name, int(revA))
- docB = storage.get(name, int(revB))
-
- return HttpResponse(differ.make_table(
- docA.plain_text.splitlines(),
- docB.plain_text.splitlines() ) )
-
-
-def document_history(reuqest, name):
- return HttpResponse( json.dumps(storage.history(name), cls=DateTimeEncoder), mimetype='application/json')
+ return JSONResponse(images)
+ except (IndexError, OSError) as e:
+ logger.exception("Unable to fetch gallery")
+ raise http.Http404
+
+
+@never_cache
+@normalized_name
+def diff(request, name):
+ storage = getstorage()
+
+ revA = int(request.GET.get('from', 0))
+ revB = int(request.GET.get('to', 0))
+
+ if revA > revB:
+ revA, revB = revB, revA
+
+ if revB == 0:
+ revB = None
+
+ docA = storage.get_or_404(name, int(revA))
+ docB = storage.get_or_404(name, int(revB))
+
+ return http.HttpResponse(nice_diff.html_diff_table(docA.plain_text.splitlines(),
+ docB.plain_text.splitlines(), context=3))
+
+
+@never_cache
+@normalized_name
+def history(request, name):
+ storage = getstorage()
+
+ # TODO: pagination
+ changesets = list(storage.history(name))
+
+ return JSONResponse(changesets)
+
+
+@require_POST
+@ajax_require_permission('wiki.can_change_tags')
+def add_tag(request, name):
+ name = normalize_name(name)
+ storage = getstorage()
+
+ form = DocumentTagForm(request.POST, prefix="addtag")
+ if form.is_valid():
+ doc = storage.get_or_404(form.cleaned_data['id'])
+ doc.add_tag(tag=form.cleaned_data['tag'],
+ revision=form.cleaned_data['revision'],
+ author=request.user.username)
+ return JSONResponse({"message": _("Tag added")})
+ else:
+ return JSONFormInvalid(form)
+
+
+@require_POST
+@ajax_require_permission('wiki.can_publish')
+def publish(request, name):
+ name = normalize_name(name)
+
+ storage = getstorage()
+ document = storage.get_by_tag(name, "ready_to_publish")
+
+ api = wlapi.WLAPI(**settings.WL_API_CONFIG)
+
+ try:
+ return JSONResponse({"result": api.publish_book(document)})
+ except wlapi.APICallException, e:
+ return JSONServerError({"message": str(e)})
+
+@login_required
+def status_report(request):
+ pass
+