From 95d09b338ac7aed2b387bf143a5cfd1c4b29f612 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Tue, 15 Dec 2009 17:48:30 +0100 Subject: new Django webinterface(in development), small fixes --- module/web/ajax/__init__.py | 0 module/web/ajax/models.py | 3 +++ module/web/ajax/tests.py | 23 +++++++++++++++++++++++ module/web/ajax/urls.py | 0 module/web/ajax/views.py | 1 + 5 files changed, 27 insertions(+) create mode 100644 module/web/ajax/__init__.py create mode 100644 module/web/ajax/models.py create mode 100644 module/web/ajax/tests.py create mode 100644 module/web/ajax/urls.py create mode 100644 module/web/ajax/views.py (limited to 'module/web/ajax') diff --git a/module/web/ajax/__init__.py b/module/web/ajax/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/module/web/ajax/models.py b/module/web/ajax/models.py new file mode 100644 index 000000000..71a836239 --- /dev/null +++ b/module/web/ajax/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/module/web/ajax/tests.py b/module/web/ajax/tests.py new file mode 100644 index 000000000..2247054b3 --- /dev/null +++ b/module/web/ajax/tests.py @@ -0,0 +1,23 @@ +""" +This file demonstrates two different styles of tests (one doctest and one +unittest). These will both pass when you run "manage.py test". + +Replace these with more appropriate tests for your application. +""" + +from django.test import TestCase + +class SimpleTest(TestCase): + def test_basic_addition(self): + """ + Tests that 1 + 1 always equals 2. + """ + self.failUnlessEqual(1 + 1, 2) + +__test__ = {"doctest": """ +Another way to test that 1 + 1 is equal to 2. + +>>> 1 + 1 == 2 +True +"""} + diff --git a/module/web/ajax/urls.py b/module/web/ajax/urls.py new file mode 100644 index 000000000..e69de29bb diff --git a/module/web/ajax/views.py b/module/web/ajax/views.py new file mode 100644 index 000000000..60f00ef0e --- /dev/null +++ b/module/web/ajax/views.py @@ -0,0 +1 @@ +# Create your views here. -- cgit v1.2.3 From fe85f003f3adfb568c8b1a650035128c183a739d Mon Sep 17 00:00:00 2001 From: RaNaN Date: Wed, 16 Dec 2009 17:09:14 +0100 Subject: some Webinterface Json Code --- module/web/ajax/urls.py | 19 +++++++++++++ module/web/ajax/views.py | 69 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) (limited to 'module/web/ajax') 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 -- cgit v1.2.3 From 3db583f5f10a72e53ecd8d282ec5db1e3f4cd4dd Mon Sep 17 00:00:00 2001 From: RaNaN Date: Wed, 16 Dec 2009 22:49:20 +0100 Subject: Webinterface authsystem --- module/web/ajax/views.py | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) (limited to 'module/web/ajax') diff --git a/module/web/ajax/views.py b/module/web/ajax/views.py index d883376e7..c4395a659 100644 --- a/module/web/ajax/views.py +++ b/module/web/ajax/views.py @@ -12,9 +12,10 @@ def check_server(function): def _view(request, *args, **kwargs): try: version = settings.PYLOAD.get_server_version() - return view_func(request, *args, **kwargs) except Exception, e: return HttpResponseServerError() + + return view_func(request, *args, **kwargs) _view.__name__ = view_func.__name__ _view.__dict__ = view_func.__dict__ @@ -30,7 +31,7 @@ def check_server(function): def permission(perm): def _dec(view_func): def _view(request, *args, **kwargs): - if request.user.has_perm(perm) and request.user.is_authenticated: + if request.user.has_perm(perm) and request.user.is_authenticated(): return view_func(request, *args, **kwargs) else: return HttpResponseForbidden() @@ -57,14 +58,26 @@ class JsonResponse(HttpResponse): def add_package(request): a = {'b' : [1,2,3], 'dsfsd' : "sadd"} return JsonResponse(a) - -# @TODO: Auth + Auth - + + +@permission('pyload.can_see_dl') def status(request): - return JsonResponse(settings.PYLOAD.status_server()) - + try: + return JsonResponse(settings.PYLOAD.status_server()) + except: + return HttpResponseServerError() + +@permission('pyload.can_see_dl') def links(request): - return JsonResponse(settings.PYLOAD.status_downloads()) - + try: + return JsonResponse(settings.PYLOAD.status_downloads()) + except: + return HttpResponseServerError() + +@permission('pyload.can_see_dl') def queue(request): - return JsonResponse(settings.PYLOAD.get_queue()) \ No newline at end of file + try: + return JsonResponse(settings.PYLOAD.get_queue()) + + except: + return HttpResponseServerError() \ No newline at end of file -- cgit v1.2.3 From aea618c1bffe9ea6eb44b8555f17349b39dfe22b Mon Sep 17 00:00:00 2001 From: RaNaN Date: Wed, 16 Dec 2009 23:45:21 +0100 Subject: new functions for interacting with core --- module/web/ajax/urls.py | 2 ++ module/web/ajax/views.py | 43 ++++++++++++++++++++----------------------- 2 files changed, 22 insertions(+), 23 deletions(-) (limited to 'module/web/ajax') diff --git a/module/web/ajax/urls.py b/module/web/ajax/urls.py index 0db240578..d1c90aa21 100644 --- a/module/web/ajax/urls.py +++ b/module/web/ajax/urls.py @@ -16,4 +16,6 @@ urlpatterns = patterns('ajax', (r'^status$', 'views.status'), (r'^links$', 'views.links'), (r'^queue$', 'views.queue'), + (r'^pause$', 'views.pause'), + (r'^unpause$', 'views.unpause'), ) \ No newline at end of file diff --git a/module/web/ajax/views.py b/module/web/ajax/views.py index c4395a659..05c91597f 100644 --- a/module/web/ajax/views.py +++ b/module/web/ajax/views.py @@ -6,28 +6,7 @@ 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() - except Exception, e: - return HttpResponseServerError() - - return view_func(request, *args, **kwargs) - - _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): @@ -80,4 +59,22 @@ def queue(request): return JsonResponse(settings.PYLOAD.get_queue()) except: - return HttpResponseServerError() \ No newline at end of file + return HttpResponseServerError() + + +@permission('pyload.can_change_satus') +def pause(request): + try: + return JsonResponse(settings.PYLOAD.pause_server()) + + except: + return HttpResponseServerError() + + +@permission('pyload.can_change_status') +def unpause(request): + try: + return JsonResponse(settings.PYLOAD.unpause_server()) + + except: + return HttpResponseServerError() -- cgit v1.2.3 From a9a0ab594e4ea05532ff089b8eee7bf20ea571be Mon Sep 17 00:00:00 2001 From: RaNaN Date: Thu, 17 Dec 2009 23:52:22 +0100 Subject: new web JSON functions --- module/web/ajax/urls.py | 5 ++++- module/web/ajax/views.py | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) (limited to 'module/web/ajax') diff --git a/module/web/ajax/urls.py b/module/web/ajax/urls.py index d1c90aa21..9849004d1 100644 --- a/module/web/ajax/urls.py +++ b/module/web/ajax/urls.py @@ -14,8 +14,11 @@ urlpatterns = patterns('ajax', # Uncomment the next line to enable the admin: (r'^add_package$', 'views.add_package'), (r'^status$', 'views.status'), - (r'^links$', 'views.links'), + (r'^links$', 'views.links'), #currently active links (r'^queue$', 'views.queue'), (r'^pause$', 'views.pause'), (r'^unpause$', 'views.unpause'), + (r'^packages$', 'views.packages'), + (r'^package/(\d+)$', 'views.package'), + (r'^link/(\d+)$', 'views.link'), ) \ No newline at end of file diff --git a/module/web/ajax/views.py b/module/web/ajax/views.py index 05c91597f..584ad1a0e 100644 --- a/module/web/ajax/views.py +++ b/module/web/ajax/views.py @@ -78,3 +78,42 @@ def unpause(request): except: return HttpResponseServerError() + + + +@permission('pyload.can_see_dl') +def packages(request): + try: + data = settings.PYLOAD.get_queue() + + for package in data: + package['links'] = [] + for file in settings.PYLOAD.get_package_files(package['id']): + package['links'].append(settings.PYLOAD.get_file_info(file)) + + return JsonResponse(data) + + except: + return HttpResponseServerError() + +@permission('pyload.can_see_dl') +def package(request,id): + try: + data = settings.PYLOAD.get_package_data(int(id)) + data['links'] = [] + for file in settings.PYLOAD.get_package_files(data['id']): + data['links'].append(settings.PYLOAD.get_file_info(file)) + + return JsonResponse(data) + + except: + return HttpResponseServerError() + +@permission('pyload.can_see_dl') +def link(request,id): + try: + data = settings.PYLOAD.get_file_info(int(id)) + return JsonResponse(data) + + except: + return HttpResponseServerError() -- cgit v1.2.3 From 1d7dc2ca5db0119e01547cd7b01fb77720450d1c Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sat, 19 Dec 2009 00:26:38 +0100 Subject: cleaned --- module/web/ajax/models.py | 1 - module/web/ajax/urls.py | 1 - module/web/ajax/views.py | 1 - 3 files changed, 3 deletions(-) (limited to 'module/web/ajax') diff --git a/module/web/ajax/models.py b/module/web/ajax/models.py index 71a836239..35e0d6486 100644 --- a/module/web/ajax/models.py +++ b/module/web/ajax/models.py @@ -1,3 +1,2 @@ -from django.db import models # Create your models here. diff --git a/module/web/ajax/urls.py b/module/web/ajax/urls.py index 9849004d1..2a7e109c3 100644 --- a/module/web/ajax/urls.py +++ b/module/web/ajax/urls.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- from django.conf.urls.defaults import * -from django.conf import settings urlpatterns = patterns('ajax', diff --git a/module/web/ajax/views.py b/module/web/ajax/views.py index 584ad1a0e..b09a80581 100644 --- a/module/web/ajax/views.py +++ b/module/web/ajax/views.py @@ -3,7 +3,6 @@ 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 -- cgit v1.2.3 From 3d655ddbfbd96abecb9a9c9bebf6e43eb710ab12 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sun, 10 Jan 2010 16:20:31 +0100 Subject: fixed manage.py, addBox working, some code formatted and cleaned --- module/web/ajax/views.py | 52 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 14 deletions(-) (limited to 'module/web/ajax') diff --git a/module/web/ajax/views.py b/module/web/ajax/views.py index b09a80581..952fbe2eb 100644 --- a/module/web/ajax/views.py +++ b/module/web/ajax/views.py @@ -1,16 +1,18 @@ # Create your views here. +from os.path import join + +from django.conf import settings +from django.core.serializers import json from django.http import HttpResponse from django.http import HttpResponseForbidden from django.http import HttpResponseServerError -from django.conf import settings from django.utils import simplejson -from django.core.serializers import json def permission(perm): def _dec(view_func): - def _view(request, *args, **kwargs): + def _view(request, * args, ** kwargs): if request.user.has_perm(perm) and request.user.is_authenticated(): - return view_func(request, *args, **kwargs) + return view_func(request, * args, ** kwargs) else: return HttpResponseForbidden() @@ -25,17 +27,39 @@ def permission(perm): class JsonResponse(HttpResponse): def __init__(self, object): content = simplejson.dumps( - object, indent=2, cls=json.DjangoJSONEncoder, - ensure_ascii=False) + 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' - + content)#, content_type='application/json') #@TODO uncomment + self['Cache-Control'] = 'no-cache, must-revalidate' +@permission('pyload.can_add') def add_package(request): - a = {'b' : [1,2,3], 'dsfsd' : "sadd"} - return JsonResponse(a) + + name = request.POST['add_name'] + + if name is None or "": + return HttpResponseServerError() + + links = request.POST['add_links'].split("\n") + + try: + f = request.FILES['add_file'] + fpath = join(settings.DL_ROOT, f.name) + destination = open(fpath, 'wb') + for chunk in f.chunks(): + destination.write(chunk) + destination.close() + links.insert(0, fpath) + except: + pass + + links = filter(lambda x: x is not "", links) + + settings.PYLOAD.add_package(name, links) + + return JsonResponse("success") @permission('pyload.can_see_dl') @@ -96,12 +120,12 @@ def packages(request): return HttpResponseServerError() @permission('pyload.can_see_dl') -def package(request,id): +def package(request, id): try: data = settings.PYLOAD.get_package_data(int(id)) data['links'] = [] for file in settings.PYLOAD.get_package_files(data['id']): - data['links'].append(settings.PYLOAD.get_file_info(file)) + data['links'].append(settings.PYLOAD.get_file_info(file)) return JsonResponse(data) @@ -109,7 +133,7 @@ def package(request,id): return HttpResponseServerError() @permission('pyload.can_see_dl') -def link(request,id): +def link(request, id): try: data = settings.PYLOAD.get_file_info(int(id)) return JsonResponse(data) -- cgit v1.2.3 From 9bff9c69d6983dc190c189647821e12d0f134883 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Mon, 11 Jan 2010 22:16:31 +0100 Subject: finally and officially: webinterface home page working ;) --- module/web/ajax/views.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'module/web/ajax') diff --git a/module/web/ajax/views.py b/module/web/ajax/views.py index 952fbe2eb..08d87c30e 100644 --- a/module/web/ajax/views.py +++ b/module/web/ajax/views.py @@ -38,8 +38,7 @@ class JsonResponse(HttpResponse): def add_package(request): name = request.POST['add_name'] - - if name is None or "": + if name == None or name == "": return HttpResponseServerError() links = request.POST['add_links'].split("\n") @@ -72,7 +71,12 @@ def status(request): @permission('pyload.can_see_dl') def links(request): try: - return JsonResponse(settings.PYLOAD.status_downloads()) + links = settings.PYLOAD.status_downloads() + ids = map(lambda x: x['id'], links) + data = {} + data['links'] = links + data['ids'] = ids + return JsonResponse(data) except: return HttpResponseServerError() -- cgit v1.2.3 From 9cce347134cffb8e3e920d94768306c2156dddee Mon Sep 17 00:00:00 2001 From: RaNaN Date: Wed, 13 Jan 2010 21:23:05 +0100 Subject: some webinterface improvements, closed #40 --- module/web/ajax/urls.py | 1 + module/web/ajax/views.py | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) (limited to 'module/web/ajax') diff --git a/module/web/ajax/urls.py b/module/web/ajax/urls.py index 2a7e109c3..4decc27b1 100644 --- a/module/web/ajax/urls.py +++ b/module/web/ajax/urls.py @@ -12,6 +12,7 @@ urlpatterns = patterns('ajax', # Uncomment the next line to enable the admin: (r'^add_package$', 'views.add_package'), + (r'^remove_link/(\d+)$', 'views.remove_link'), (r'^status$', 'views.status'), (r'^links$', 'views.links'), #currently active links (r'^queue$', 'views.queue'), diff --git a/module/web/ajax/views.py b/module/web/ajax/views.py index 08d87c30e..ea092745f 100644 --- a/module/web/ajax/views.py +++ b/module/web/ajax/views.py @@ -30,7 +30,7 @@ class JsonResponse(HttpResponse): object, indent=2, cls=json.DjangoJSONEncoder, ensure_ascii=False) super(JsonResponse, self).__init__( - content)#, content_type='application/json') #@TODO uncomment + content, content_type='application/json') #@TODO uncomment self['Cache-Control'] = 'no-cache, must-revalidate' @@ -38,14 +38,17 @@ class JsonResponse(HttpResponse): def add_package(request): name = request.POST['add_name'] + if name == None or name == "": return HttpResponseServerError() - links = request.POST['add_links'].split("\n") + links = request.POST['add_links'].replace(" ","\n").split("\n") try: f = request.FILES['add_file'] + print f fpath = join(settings.DL_ROOT, f.name) + print fpath destination = open(fpath, 'wb') for chunk in f.chunks(): destination.write(chunk) @@ -54,12 +57,19 @@ def add_package(request): except: pass - links = filter(lambda x: x is not "", links) - - settings.PYLOAD.add_package(name, links) + links = filter(lambda x: x != "", links) + settings.PYLOAD.add_package(name, links) + return JsonResponse("success") +@permission('pyload.can_add_dl') +def remove_link(request, id): + try: + settings.PYLOAD.del_links([int(id)]) + return JsonResponse("sucess") + except: + return HttpResponseServerError() @permission('pyload.can_see_dl') def status(request): -- cgit v1.2.3 From 8d842efb12ee7db88505e3078b626855e55aa4bf Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sun, 17 Jan 2010 18:31:52 +0100 Subject: some fixes, closed #62 ?? --- module/web/ajax/urls.py | 1 + module/web/ajax/views.py | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'module/web/ajax') diff --git a/module/web/ajax/urls.py b/module/web/ajax/urls.py index 4decc27b1..7d63ef5a6 100644 --- a/module/web/ajax/urls.py +++ b/module/web/ajax/urls.py @@ -18,6 +18,7 @@ urlpatterns = patterns('ajax', (r'^queue$', 'views.queue'), (r'^pause$', 'views.pause'), (r'^unpause$', 'views.unpause'), + (r'^cancel$', 'views.cancel'), (r'^packages$', 'views.packages'), (r'^package/(\d+)$', 'views.package'), (r'^link/(\d+)$', 'views.link'), diff --git a/module/web/ajax/views.py b/module/web/ajax/views.py index ea092745f..4f136cef9 100644 --- a/module/web/ajax/views.py +++ b/module/web/ajax/views.py @@ -30,7 +30,7 @@ class JsonResponse(HttpResponse): object, indent=2, cls=json.DjangoJSONEncoder, ensure_ascii=False) super(JsonResponse, self).__init__( - content, content_type='application/json') #@TODO uncomment + content)#, content_type='application/json') #@TODO uncomment self['Cache-Control'] = 'no-cache, must-revalidate' @@ -117,6 +117,12 @@ def unpause(request): return HttpResponseServerError() +@permission('pyload.can_change_status') +def cancel(request): + try: + return JsonResponse(settings.PYLOAD.stop_downloads()) + except: + return HttpResponseServerError() @permission('pyload.can_see_dl') def packages(request): -- cgit v1.2.3 From 07f280a220ab5bc5c3fb510ea00aecedfcec7564 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Wed, 20 Jan 2010 19:41:43 +0100 Subject: queue page fully functional, some fixes --- module/web/ajax/urls.py | 6 +++++- module/web/ajax/views.py | 44 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 44 insertions(+), 6 deletions(-) (limited to 'module/web/ajax') diff --git a/module/web/ajax/urls.py b/module/web/ajax/urls.py index 7d63ef5a6..d50e7121e 100644 --- a/module/web/ajax/urls.py +++ b/module/web/ajax/urls.py @@ -12,7 +12,7 @@ urlpatterns = patterns('ajax', # Uncomment the next line to enable the admin: (r'^add_package$', 'views.add_package'), - (r'^remove_link/(\d+)$', 'views.remove_link'), + (r'^abort_link/(\d+)$', 'views.abort_link'), (r'^status$', 'views.status'), (r'^links$', 'views.links'), #currently active links (r'^queue$', 'views.queue'), @@ -22,4 +22,8 @@ urlpatterns = patterns('ajax', (r'^packages$', 'views.packages'), (r'^package/(\d+)$', 'views.package'), (r'^link/(\d+)$', 'views.link'), + (r'^remove_package/(\d+)$', 'views.remove_package'), + (r'^restart_package/(\d+)$', 'views.restart_package'), + (r'^remove_link/(\d+)$', 'views.remove_link'), + (r'^restart_link/(\d+)$', 'views.restart_link'), ) \ No newline at end of file diff --git a/module/web/ajax/views.py b/module/web/ajax/views.py index 4f136cef9..4d9762ab4 100644 --- a/module/web/ajax/views.py +++ b/module/web/ajax/views.py @@ -39,16 +39,15 @@ def add_package(request): name = request.POST['add_name'] - if name == None or name == "": - return HttpResponseServerError() - links = request.POST['add_links'].replace(" ","\n").split("\n") try: f = request.FILES['add_file'] - print f + + if name == None or name == "": + name = f.name + fpath = join(settings.DL_ROOT, f.name) - print fpath destination = open(fpath, 'wb') for chunk in f.chunks(): destination.write(chunk) @@ -57,6 +56,9 @@ def add_package(request): except: pass + if name == None or name == "": + return HttpResponseServerError() + links = filter(lambda x: x != "", links) settings.PYLOAD.add_package(name, links) @@ -160,3 +162,35 @@ def link(request, id): except: return HttpResponseServerError() + +@permission('pyload.can_add_dl') +def remove_package(request, id): + try: + settings.PYLOAD.del_packages([int(id)]) + return JsonResponse("sucess") + except: + return HttpResponseServerError() + +@permission('pyload.can_add_dl') +def restart_package(request, id): + try: + settings.PYLOAD.restart_package(int(id)) + return JsonResponse("sucess") + except: + return HttpResponseServerError() + +@permission('pyload.can_add_dl') +def restart_link(request, id): + try: + settings.PYLOAD.restart_file(int(id)) + return JsonResponse("sucess") + except: + return HttpResponseServerError() + +@permission('pyload.can_add_dl') +def abort_link(request, id): + try: + settings.PYLOAD.stop_download("link", int(id)) + return JsonResponse("sucess") + except: + return HttpResponseServerError() \ No newline at end of file -- cgit v1.2.3