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 | |
parent | re-added progressbar (diff) | |
download | pyload-fe85f003f3adfb568c8b1a650035128c183a739d.tar.xz |
some Webinterface Json Code
Diffstat (limited to 'module/web/ajax')
-rw-r--r-- | module/web/ajax/urls.py | 19 | ||||
-rw-r--r-- | module/web/ajax/views.py | 69 |
2 files changed, 88 insertions, 0 deletions
diff --git a/module/web/ajax/urls.py b/module/web/ajax/urls.py index e69de29bb..0db240578 100644 --- a/module/web/ajax/urls.py +++ b/module/web/ajax/urls.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from django.conf.urls.defaults import * +from django.conf import settings + + +urlpatterns = patterns('ajax', + # Example: + # (r'^pyload/', include('pyload.foo.urls')), + + # Uncomment the admin/doc line below and add 'django.contrib.admindocs' + # to INSTALLED_APPS to enable admin documentation: + # (r'^admin/doc/', include('django.contrib.admindocs.urls')), + + # Uncomment the next line to enable the admin: + (r'^add_package$', 'views.add_package'), + (r'^status$', 'views.status'), + (r'^links$', 'views.links'), + (r'^queue$', 'views.queue'), + )
\ No newline at end of file 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 |