- base_dir = os.path.join(settings.MEDIA_ROOT, settings.FILEBROWSER_DIRECTORY, directory)
- print base_dir
- images = ['%s%s%s/%s' % (settings.MEDIA_URL, settings.FILEBROWSER_DIRECTORY, directory, f) for f in os.listdir(base_dir) if os.path.splitext(f)[1].lower() in ('.jpg', '.jpeg', '.png')]
- return HttpResponse(json.dumps(images))
- except (IndexError, OSError), e:
- raise Http404
+ base_url = ''.join((
+ smart_unicode(settings.MEDIA_URL),
+ smart_unicode(settings.IMAGE_DIR),
+ smart_unicode(directory)))
+
+ base_dir = os.path.join(
+ smart_unicode(settings.MEDIA_ROOT),
+ smart_unicode(settings.IMAGE_DIR),
+ smart_unicode(directory))
+
+ def map_to_url(filename):
+ return urllib.quote("%s/%s" % (base_url, smart_unicode(filename)))
+
+ def is_image(filename):
+ return os.path.splitext(f)[1].lower() in (u'.jpg', u'.jpeg', u'.png')
+
+ images = [map_to_url(f) for f in map(smart_unicode, os.listdir(base_dir)) if is_image(f)]
+ images.sort()
+
+ return JSONResponse(images)
+ except (IndexError, OSError):
+ logger.exception("Unable to fetch gallery")
+ raise http.Http404
+
+
+@never_cache
+def diff(request, doc_id):
+ 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
+
+ # TODO: check if revisions in line.
+
+ doc = get_object_or_404(Document, pk=doc_id, deleted=False)
+
+ # allow diff from the beginning
+ if revA:
+ docA = Revision.objects.get(pk=revA).materialize()
+ else:
+ docA = ""
+ docB = Revision.objects.get(pk=revB).materialize()
+
+ return http.HttpResponse(nice_diff.html_diff_table(docA.splitlines(), docB.splitlines(), context=3))
+
+
+@never_cache
+def history(request, doc_id):
+ # TODO: pagination
+ doc = get_object_or_404(Document, pk=doc_id, deleted=False)
+
+ return JSONResponse(get_history(doc))