diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2009-12-16 17:09:14 +0100 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2009-12-16 17:09:14 +0100 |
commit | fe85f003f3adfb568c8b1a650035128c183a739d (patch) | |
tree | 3abde88d3554831e0a41e3fd2d5d4092fd677a1f /module/web/ajax/views.py | |
parent | re-added progressbar (diff) | |
download | pyload-fe85f003f3adfb568c8b1a650035128c183a739d.tar.xz |
some Webinterface Json Code
Diffstat (limited to 'module/web/ajax/views.py')
-rw-r--r-- | module/web/ajax/views.py | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/module/web/ajax/views.py b/module/web/ajax/views.py index 60f00ef0e..d883376e7 100644 --- a/module/web/ajax/views.py +++ b/module/web/ajax/views.py @@ -1 +1,70 @@ # Create your views here. +from django.http import HttpResponse +from django.http import HttpResponseForbidden +from django.http import HttpResponseServerError +from django.conf import settings +from django.shortcuts import render_to_response +from django.utils import simplejson +from django.core.serializers import json + +def check_server(function): + def _dec(view_func): + def _view(request, *args, **kwargs): + try: + version = settings.PYLOAD.get_server_version() + return view_func(request, *args, **kwargs) + except Exception, e: + return HttpResponseServerError() + + _view.__name__ = view_func.__name__ + _view.__dict__ = view_func.__dict__ + _view.__doc__ = view_func.__doc__ + + return _view + + if function is None: + return _dec + else: + return _dec(function) + +def permission(perm): + def _dec(view_func): + def _view(request, *args, **kwargs): + if request.user.has_perm(perm) and request.user.is_authenticated: + return view_func(request, *args, **kwargs) + else: + return HttpResponseForbidden() + + _view.__name__ = view_func.__name__ + _view.__dict__ = view_func.__dict__ + _view.__doc__ = view_func.__doc__ + + return _view + + return _dec + +class JsonResponse(HttpResponse): + def __init__(self, object): + content = simplejson.dumps( + object, indent=2, cls=json.DjangoJSONEncoder, + ensure_ascii=False) + super(JsonResponse, self).__init__( + content)#, content_type='application/json') + self['Cache-Control'] = 'no-cache, must-revalidate' + + + +def add_package(request): + a = {'b' : [1,2,3], 'dsfsd' : "sadd"} + return JsonResponse(a) + +# @TODO: Auth + Auth + +def status(request): + return JsonResponse(settings.PYLOAD.status_server()) + +def links(request): + return JsonResponse(settings.PYLOAD.status_downloads()) + +def queue(request): + return JsonResponse(settings.PYLOAD.get_queue())
\ No newline at end of file |