def test_get_icon(self): # Folder self.assertEqual(icons.get_icon(None), "/static/mimetypes/64x64/folder.png") # Regular self.assertEqual( icons.get_icon("application/pdf"), "/static/mimetypes/64x64/application-pdf.png", ) # Mimetype fallback self.assertEqual( icons.get_icon("application/rtf"), "/static/mimetypes/64x64/x-office-document.png", ) # Main part fallback self.assertEqual(icons.get_icon("image/jpeg"), "/static/mimetypes/64x64/image-x-generic.png") # Unknown self.assertEqual( icons.get_icon("foo/bar"), "/static/mimetypes/64x64/application-x-executable.png", )
def test_get_icon(self): # Folder self.assertEqual(icons.get_icon(None), "/static/mimetypes/64x64/folder.png") # Regular self.assertEqual(icons.get_icon("application/pdf"), "/static/mimetypes/64x64/application-pdf.png") # Mimetype fallback self.assertEqual(icons.get_icon("application/rtf"), "/static/mimetypes/64x64/x-office-document.png") # Main part fallback self.assertEqual(icons.get_icon("image/jpeg"), "/static/mimetypes/64x64/image-x-generic.png") # Unknown self.assertEqual(icons.get_icon("foo/bar"), "/static/mimetypes/64x64/application-x-executable.png")
def jsonRoot(request): '''geta a json object containing a list of the root filesystems''' fs = Filesystem.objects.all().values_list('name', flat=True) files = [{ 'file': f, 'isDir': True, 'type': 'folder', 'icon': get_icon("folder", ICON_SIZE) } for f in fs] result = {'path': '', 'contents': files} return HttpResponse(json.dumps(result), mimetype='application/json')
def getJson(request, filesystem_name, path): '''get a json object containing a list with the contents of the path along with information about whether or not it is a directory and the mime type''' try: fs = Filesystem.objects.get(name=filesystem_name) if fs.isdir(path): files = [{'file':f,'isDir':d,'type':t, 'icon':get_icon(t,ICON_SIZE)} for (f,d,t) in fs.files(path) ] result = {'path':filesystem_name + '/' + path,'contents':files} return HttpResponse(json.dumps(result),mimetype='application/json') else: raise Http404 # for now no support for individual files except ValueError: raise Http404 except Filesystem.DoesNotExist: raise Http404 except IOError: raise Http404
def getJson(request, filesystem_name, path): '''get a json object containing a list with the contents of the path along with information about whether or not it is a directory and the mime type''' try: fs = Filesystem.objects.get(name=filesystem_name) if fs.isdir(path): files = [{ 'file': f, 'isDir': d, 'type': t, 'icon': get_icon(t, ICON_SIZE) } for (f, d, t) in fs.files(path)] result = {'path': filesystem_name + '/' + path, 'contents': files} return HttpResponse(json.dumps(result), mimetype='application/json') else: raise Http404 # for now no support for individual files except ValueError: raise Http404 except Filesystem.DoesNotExist: raise Http404 except IOError: raise Http404
def jsonRoot(request): '''geta a json object containing a list of the root filesystems''' fs = Filesystem.objects.all().values_list('name',flat=True) files = [ {'file': f, 'isDir': True, 'type':'folder','icon': get_icon("folder",ICON_SIZE)} for f in fs] result = {'path':'', 'contents': files } return HttpResponse(json.dumps(result),mimetype='application/json')