summaryrefslogtreecommitdiffstats
path: root/module
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2009-12-16 17:09:14 +0100
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2009-12-16 17:09:14 +0100
commitfe85f003f3adfb568c8b1a650035128c183a739d (patch)
tree3abde88d3554831e0a41e3fd2d5d4092fd677a1f /module
parentre-added progressbar (diff)
downloadpyload-fe85f003f3adfb568c8b1a650035128c183a739d.tar.xz
some Webinterface Json Code
Diffstat (limited to 'module')
-rw-r--r--module/web/ajax/urls.py19
-rw-r--r--module/web/ajax/views.py69
-rw-r--r--module/web/pyload.dbbin32768 -> 34816 bytes
-rw-r--r--module/web/pyload/admin.py14
-rw-r--r--module/web/pyload/models.py26
-rw-r--r--module/web/pyload/urls.py22
-rw-r--r--module/web/pyload/views.py4
-rw-r--r--module/web/settings.py5
-rw-r--r--module/web/templates/default/base.html9
-rw-r--r--module/web/templates/default/downloads.html8
-rw-r--r--module/web/templates/default/logs.html8
-rw-r--r--module/web/templates/default/queue.html8
-rw-r--r--module/web/urls.py13
13 files changed, 155 insertions, 50 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
diff --git a/module/web/pyload.db b/module/web/pyload.db
index 8d34ef89c..45f55284e 100644
--- a/module/web/pyload.db
+++ b/module/web/pyload.db
Binary files differ
diff --git a/module/web/pyload/admin.py b/module/web/pyload/admin.py
index 40a96afc6..11f325200 100644
--- a/module/web/pyload/admin.py
+++ b/module/web/pyload/admin.py
@@ -1 +1,15 @@
# -*- coding: utf-8 -*-
+from django.contrib import admin
+from models import UserProfile
+from django.contrib.auth.models import User
+from django.contrib.auth.admin import UserAdmin as RealUserAdmin
+
+
+class UserProfileInline(admin.StackedInline):
+ model = UserProfile
+
+class UserAdmin(RealUserAdmin):
+ inlines = [ UserProfileInline ]
+
+admin.site.unregister(User)
+admin.site.register(User, UserAdmin) \ No newline at end of file
diff --git a/module/web/pyload/models.py b/module/web/pyload/models.py
index 293c01109..d3d99febc 100644
--- a/module/web/pyload/models.py
+++ b/module/web/pyload/models.py
@@ -1,21 +1,15 @@
# -*- coding: utf-8 -*-
from django.db import models
-#from django.contrib.auth.models.User import User as UserProfile
+from django.contrib.auth.models import User
# Create your models here.
-
-class Perm(models.Model):
- """ extended pyLoad user Profile """
-
- #user = models.ForeignKey(UserProfile, unique=True)
- #template = models.CharField(maxlength=30)
+class UserProfile(models.Model):
+ """ Permissions setting """
- 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
+ user = models.ForeignKey(User, unique=True)
+ template = models.CharField(max_length=30, default='default', null=False, blank=False)
+
+def user_post_save(sender, instance, **kwargs):
+ profile, new = UserProfile.objects.get_or_create(user=instance)
+
+models.signals.post_save.connect(user_post_save, User) \ No newline at end of file
diff --git a/module/web/pyload/urls.py b/module/web/pyload/urls.py
index 9c7942492..667a4ed3d 100644
--- a/module/web/pyload/urls.py
+++ b/module/web/pyload/urls.py
@@ -1,7 +1,19 @@
+
+from os.path import join
+
+from django.conf import settings
from django.conf.urls.defaults import *
-urlpatterns = patterns('',
- (r'^login/$', 'pyload.views.login'),
- (r'^home/$', 'pyload.views.home'),
- (r'^test/$', 'pyload.views.home'),
-)
+
+urlpatterns = patterns('pyload',
+ (r'^home/$', 'views.home'),
+ (r'^downloads/$', 'views.downloads',{},'downloads'),
+ (r'^queue/$', 'views.queue',{}, 'queue'),
+ (r'^logs/$', 'views.logs',{}, 'logs'),
+ (r'^$', 'views.home',{}, 'home'),
+ )
+
+urlpatterns += patterns('django.contrib.auth',
+ (r'^login/$', 'views.login', {'template_name': join(settings.TEMPLATE, 'login.html')}),
+ (r'^logout/$', 'views.logout', {'template_name': join(settings.TEMPLATE, 'logout.html')}, 'logout'),
+) \ No newline at end of file
diff --git a/module/web/pyload/views.py b/module/web/pyload/views.py
index c42511ede..6c2954555 100644
--- a/module/web/pyload/views.py
+++ b/module/web/pyload/views.py
@@ -1,7 +1,6 @@
# 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
@@ -14,9 +13,9 @@ 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 base(request, messages=['Can\'t connect to pyLoad. Please check your configuration and make sure pyLoad is running.',str(e)])
+ return view_func(request, *args, **kwargs)
_view.__name__ = view_func.__name__
_view.__dict__ = view_func.__dict__
@@ -54,6 +53,7 @@ def base(request, messages):
#@permission('perm.permissions.can_see_dl') @TODO: Permissions not working :(
@check_server
def home(request):
+ print request.user.get_all_permissions()
return render_to_response(join(settings.TEMPLATE,'home.html'), RequestContext(request))
diff --git a/module/web/settings.py b/module/web/settings.py
index 0dc86d699..00395b328 100644
--- a/module/web/settings.py
+++ b/module/web/settings.py
@@ -97,7 +97,10 @@ TEMPLATE_LOADERS = (
# 'django.template.loaders.eggs.load_template_source',
)
+
MIDDLEWARE_CLASSES = (
+ 'django.middleware.gzip.GZipMiddleware',
+ 'django.middleware.http.ConditionalGetMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
@@ -123,5 +126,5 @@ INSTALLED_APPS = (
)
-AUTH_PROFILE_MODULE = 'pyload.User'
+AUTH_PROFILE_MODULE = 'pyload.UserProfile'
LOGIN_URL = '/login' \ No newline at end of file
diff --git a/module/web/templates/default/base.html b/module/web/templates/default/base.html
index 096692a3c..27aa72b9f 100644
--- a/module/web/templates/default/base.html
+++ b/module/web/templates/default/base.html
@@ -6,6 +6,7 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}css/default.css">
+<link rel="icon" href="/favicon.ico" type="image/vnd.microsoft.icon">
{% block head %}
{% endblock %}
<title>{% block title %}pyLoad Webinterface{% endblock %}</title>
@@ -40,14 +41,14 @@
{% block menu %}
<li class="selected">
- <a href="/" title=""><img src="{{ MEDIA_URL }}img/head-menu-home.png" alt="" /> Home</a>
+ <a href="{% url home %}" title=""><img src="{{ MEDIA_URL }}img/head-menu-home.png" alt="" /> Home</a>
</li>
<li>
- <a href="/queue/" title=""><img src="{{ MEDIA_URL }}img/head-menu-download.png" alt="" /> Queue</a></li>
+ <a href="{% url queue %}" title=""><img src="{{ MEDIA_URL }}img/head-menu-download.png" alt="" /> Queue</a></li>
<li>
- <a href="/downloads/" title=""><img src="{{ MEDIA_URL }}img/head-menu-development.png" alt="" /> Downloads</a></li>
+ <a href="{% url downloads %}" title=""><img src="{{ MEDIA_URL }}img/head-menu-development.png" alt="" /> Downloads</a></li>
<li class="right">
- <a href="/logs/" class="action index" accesskey="x" rel="nofollow"><img src="{{ MEDIA_URL }}img/head-menu-index.png" alt="" />Logs</a>
+ <a href="{% url logs %}" class="action index" accesskey="x" rel="nofollow"><img src="{{ MEDIA_URL }}img/head-menu-index.png" alt="" />Logs</a>
</li>
{% endblock %}
diff --git a/module/web/templates/default/downloads.html b/module/web/templates/default/downloads.html
index 3c9bb5df4..202965b3c 100644
--- a/module/web/templates/default/downloads.html
+++ b/module/web/templates/default/downloads.html
@@ -4,13 +4,13 @@
{% block menu %}
<li>
- <a href="/" title=""><img src="{{ MEDIA_URL }}img/head-menu-home.png" alt="" /> Home</a>
+ <a href="{% url home %}" title=""><img src="{{ MEDIA_URL }}img/head-menu-home.png" alt="" /> Home</a>
</li>
<li>
- <a href="/queue" title=""><img src="{{ MEDIA_URL }}img/head-menu-download.png" alt="" /> Queue</a></li>
+ <a href="{% url queue %}" title=""><img src="{{ MEDIA_URL }}img/head-menu-download.png" alt="" /> Queue</a></li>
<li class="selected">
- <a href="/downloads" title=""><img src="{{ MEDIA_URL }}img/head-menu-development.png" alt="" /> Downloads</a></li>
+ <a href="{% url downloads %}" title=""><img src="{{ MEDIA_URL }}img/head-menu-development.png" alt="" /> Downloads</a></li>
<li class="right">
- <a href="/logs" class="action index" accesskey="x" rel="nofollow"><img src="{{ MEDIA_URL }}img/head-menu-index.png" alt="" />Logs</a>
+ <a href="{% url logs %}" class="action index" accesskey="x" rel="nofollow"><img src="{{ MEDIA_URL }}img/head-menu-index.png" alt="" />Logs</a>
</li>
{% endblock %} \ No newline at end of file
diff --git a/module/web/templates/default/logs.html b/module/web/templates/default/logs.html
index d6f392f58..39f4b8660 100644
--- a/module/web/templates/default/logs.html
+++ b/module/web/templates/default/logs.html
@@ -4,13 +4,13 @@
{% block menu %}
<li>
- <a href="/" title=""><img src="{{ MEDIA_URL }}img/head-menu-home.png" alt="" /> Home</a>
+ <a href="{% url home %}" title=""><img src="{{ MEDIA_URL }}img/head-menu-home.png" alt="" /> Home</a>
</li>
<li>
- <a href="/queue" title=""><img src="{{ MEDIA_URL }}img/head-menu-download.png" alt="" /> Queue</a></li>
+ <a href="{% url queue %}" title=""><img src="{{ MEDIA_URL }}img/head-menu-download.png" alt="" /> Queue</a></li>
<li>
- <a href="/downloads" title=""><img src="{{ MEDIA_URL }}img/head-menu-development.png" alt="" /> Downloads</a></li>
+ <a href="{% url downloads %}" title=""><img src="{{ MEDIA_URL }}img/head-menu-development.png" alt="" /> Downloads</a></li>
<li class="right" class="selected">
- <a href="/logs" class="action index" accesskey="x" rel="nofollow"><img src="{{ MEDIA_URL }}img/head-menu-index.png" alt="" />Logs</a>
+ <a href="{% url logs %}" class="action index" accesskey="x" rel="nofollow"><img src="{{ MEDIA_URL }}img/head-menu-index.png" alt="" />Logs</a>
</li>
{% endblock %} \ No newline at end of file
diff --git a/module/web/templates/default/queue.html b/module/web/templates/default/queue.html
index b6a185b19..8c582c5d0 100644
--- a/module/web/templates/default/queue.html
+++ b/module/web/templates/default/queue.html
@@ -4,13 +4,13 @@
{% block menu %}
<li>
- <a href="/" title=""><img src="{{ MEDIA_URL }}img/head-menu-home.png" alt="" /> Home</a>
+ <a href="{% url home %}" title=""><img src="{{ MEDIA_URL }}img/head-menu-home.png" alt="" /> Home</a>
</li>
<li class="selected">
- <a href="/queue" title=""><img src="{{ MEDIA_URL }}img/head-menu-download.png" alt="" /> Queue</a></li>
+ <a href="{% url queue %}" title=""><img src="{{ MEDIA_URL }}img/head-menu-download.png" alt="" /> Queue</a></li>
<li>
- <a href="/downloads" title=""><img src="{{ MEDIA_URL }}img/head-menu-development.png" alt="" /> Downloads</a></li>
+ <a href="{% url downloads %}" title=""><img src="{{ MEDIA_URL }}img/head-menu-development.png" alt="" /> Downloads</a></li>
<li class="right">
- <a href="/logs" class="action index" accesskey="x" rel="nofollow"><img src="{{ MEDIA_URL }}img/head-menu-index.png" alt="" />Logs</a>
+ <a href="{% url logs %}" class="action index" accesskey="x" rel="nofollow"><img src="{{ MEDIA_URL }}img/head-menu-index.png" alt="" />Logs</a>
</li>
{% endblock %} \ No newline at end of file
diff --git a/module/web/urls.py b/module/web/urls.py
index 3e573aa95..4f47fc281 100644
--- a/module/web/urls.py
+++ b/module/web/urls.py
@@ -9,22 +9,15 @@ admin.autodiscover()
urlpatterns = patterns('',
# 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'^admin/', include(admin.site.urls)),
- #(r'^json/', include(ajax.urls)),
+ (r'^json/', include('ajax.urls')),
+ (r'^favicon\.ico$', 'django.views.generic.simple.redirect_to', {'url': '/media/img/favicon.ico'}),
(r'^media/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT}),
- (r'^login/$', 'django.contrib.auth.views.login', {'template_name': join(settings.TEMPLATE,'login.html')}),
- (r'^logout/$', 'django.contrib.auth.views.logout', {'template_name': join(settings.TEMPLATE,'logout.html')}),
- (r'^home/$', 'pyload.views.home'),
- (r'^downloads/$', 'pyload.views.downloads'),
- (r'^queue/$', 'pyload.views.queue'),
- (r'^logs/$', 'pyload.views.logs'),
- (r'^$', 'pyload.views.home'),
+ (r'^', include('pyload.urls')),
)