Poprawienie serializacji
[redakcja.git] / apps / explorer / views.py
index 7f866a3..71493c6 100755 (executable)
@@ -8,15 +8,16 @@ from django.conf import settings
 from django.contrib.auth.decorators import login_required, permission_required
 
 from django.core.urlresolvers import reverse
-from django.http import HttpResponse
+from django.http import HttpResponse, Http404
 from django.utils import simplejson as json
 from django.views.generic.simple import direct_to_template
 from django.shortcuts import render_to_response
 from django.template import RequestContext
 from django.contrib.auth.decorators import login_required
 
-from explorer import forms
-from api.models import PullRequest
+from explorer import forms, models
+import os
+# from api.models import PullRequest
 from bookthemes.models import Theme
 
 def ajax_login_required(view):
@@ -39,7 +40,7 @@ def display_editor(request, path):
         dictionary = {
             'fileid': path,
             'euser': user,
-            'gallery_from': gallery_form,
+            'gallery_form': gallery_form,
             'available_themes': ({'first_letter': t.name[0].upper(), 'name': t.name} for t in Theme.objects.order_by('name')),
         }, context_instance=RequestContext(request))
 
@@ -47,18 +48,17 @@ def display_editor(request, path):
 # View all files
 #
 def file_list(request):   
-    import api.forms
-    from api.resources import library_resource
-
-    bookform = api.forms.DocumentUploadForm()
+    from wiki.views import document_list
 
     # short-circut the api document list
-    doctree = library_resource.handler.read(request)
+    doctree = library_resource.handler.read(request)
     # print "DOCTREE:", doctree['documents']
         
-    return direct_to_template(request, 'explorer/file_list.html', extra_context={
-        'filetree': doctree['documents'], 'bookform': bookform,
-    })
+    return document_list(request, 'explorer/file_list.html')
+    
+    # return direct_to_template(request, 'explorer/file_list.html', extra_context={
+    #     'files': files, 'bookform': bookform,
+    # })
 
 @permission_required('api.document.can_add')
 def file_upload(request):
@@ -132,3 +132,13 @@ def pull_requests(request):
 def renderer_test(request):
     return direct_to_template(request, 'renderer.html', mimetype="text/html",
         extra_context = {} )
+
+
+def document_gallery(request, document):
+    assocs = models.GalleryForDocument.objects.filter(document=document)
+    directory = assocs[0].subpath
+    try:
+        images = ['/media/%s/%s' % (directory, f) for f in os.listdir(os.path.join(settings.MEDIA_ROOT, directory)) if f.lower().endswith('.jpg')]
+        return HttpResponse(json.dumps(images))
+    except IndexError:
+        raise Http404