- return HttpResponse(json.dumps(images))
- except (IndexError, OSError), exc:
- import traceback
- traceback.print_exc()
-
- raise Http404
-
-def document_diff(request, name, revA, revB):
- docA = storage.get(name, int(revA))
- docB = storage.get(name, int(revB))
-
-
- return HttpResponse(nice_diff.html_diff_table(docA.plain_text.splitlines(),
- docB.plain_text.splitlines()) )
-
-
-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)
-
+ 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)
+