diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2009-12-15 17:48:30 +0100 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2009-12-15 17:48:30 +0100 |
commit | 95d09b338ac7aed2b387bf143a5cfd1c4b29f612 (patch) | |
tree | 2f6c078f95bbc80f423609bacab8066fe86d7067 /module/web/pyload | |
parent | gui queue view - unstable (non thread safe) (diff) | |
download | pyload-95d09b338ac7aed2b387bf143a5cfd1c4b29f612.tar.xz |
new Django webinterface(in development), small fixes
Diffstat (limited to 'module/web/pyload')
-rw-r--r-- | module/web/pyload/__init__.py | 0 | ||||
-rw-r--r-- | module/web/pyload/admin.py | 1 | ||||
-rw-r--r-- | module/web/pyload/models.py | 21 | ||||
-rw-r--r-- | module/web/pyload/tests.py | 23 | ||||
-rw-r--r-- | module/web/pyload/urls.py | 7 | ||||
-rw-r--r-- | module/web/pyload/views.py | 80 |
6 files changed, 132 insertions, 0 deletions
diff --git a/module/web/pyload/__init__.py b/module/web/pyload/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/module/web/pyload/__init__.py diff --git a/module/web/pyload/admin.py b/module/web/pyload/admin.py new file mode 100644 index 000000000..40a96afc6 --- /dev/null +++ b/module/web/pyload/admin.py @@ -0,0 +1 @@ +# -*- coding: utf-8 -*- diff --git a/module/web/pyload/models.py b/module/web/pyload/models.py new file mode 100644 index 000000000..293c01109 --- /dev/null +++ b/module/web/pyload/models.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +from django.db import models +#from django.contrib.auth.models.User import User as UserProfile +# Create your models here. + + +class Perm(models.Model): + """ extended pyLoad user Profile """ + + #user = models.ForeignKey(UserProfile, unique=True) + #template = models.CharField(maxlength=30) + + class Meta: + permissions = ( + ("can_see_dl", "Can see Downloads"), + ("can_add", "Can add Downloads"), + ("can_delete", "Can delete Downloads"), + ("can_download", "Can download Files"), + ("can_see_logs", "Can see logs"), + ("can_change_status", "Can change status"), + )
\ No newline at end of file diff --git a/module/web/pyload/tests.py b/module/web/pyload/tests.py new file mode 100644 index 000000000..2247054b3 --- /dev/null +++ b/module/web/pyload/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/pyload/urls.py b/module/web/pyload/urls.py new file mode 100644 index 000000000..9c7942492 --- /dev/null +++ b/module/web/pyload/urls.py @@ -0,0 +1,7 @@ +from django.conf.urls.defaults import * + +urlpatterns = patterns('', + (r'^login/$', 'pyload.views.login'), + (r'^home/$', 'pyload.views.home'), + (r'^test/$', 'pyload.views.home'), +) diff --git a/module/web/pyload/views.py b/module/web/pyload/views.py new file mode 100644 index 000000000..c42511ede --- /dev/null +++ b/module/web/pyload/views.py @@ -0,0 +1,80 @@ +# Create your views here. +from django.http import HttpResponse +from django.http import HttpResponseRedirect +from django.http import HttpResponseGone +from django.conf import settings +from django.shortcuts import render_to_response +from django.template import RequestContext +from django.contrib.auth.decorators import login_required +from os.path import join + + +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 base(request, messages=['Can\'t connect to pyLoad. Please check your configuration and make sure pyLoad is running.',str(e)]) + + _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): + return view_func(request, *args, **kwargs) + else: + return base(request, messages=['You don\'t have permission to view this page.']) + + _view.__name__ = view_func.__name__ + _view.__dict__ = view_func.__dict__ + _view.__doc__ = view_func.__doc__ + + return _view + + return _dec + + +def base(request, messages): + return render_to_response(join(settings.TEMPLATE,'base.html'), {'messages': messages},RequestContext(request)) + +@login_required +#@permission('perm.permissions.can_see_dl') @TODO: Permissions not working :( +@check_server +def home(request): + return render_to_response(join(settings.TEMPLATE,'home.html'), RequestContext(request)) + + +@login_required +#@permission('pyload.perm.can_see_dl') +@check_server +def queue(request): + return render_to_response(join(settings.TEMPLATE,'queue.html'), RequestContext(request)) + + +@login_required +#@permission('pyload.user.can_download') +@check_server +def downloads(request): + return render_to_response(join(settings.TEMPLATE,'downloads.html'), RequestContext(request)) + + +@login_required +#@permission('pyload.user.can_see_logs') +@check_server +def logs(request): + return render_to_response(join(settings.TEMPLATE,'logs.html'), RequestContext(request)) + +
\ No newline at end of file |