summaryrefslogtreecommitdiffstats
path: root/module
diff options
context:
space:
mode:
authorGravatar therazer <devnull@localhost> 2010-11-09 15:57:49 +0100
committerGravatar therazer <devnull@localhost> 2010-11-09 15:57:49 +0100
commit46f947f7d8fd3012c648750e685cec8628e5db91 (patch)
treef39f5be671a7c7d64cbcaa8374701fe62321ddc6 /module
parentaccount cache fix (diff)
downloadpyload-46f947f7d8fd3012c648750e685cec8628e5db91.tar.xz
added browser to set paths in settings
Diffstat (limited to 'module')
-rw-r--r--module/web/media/default/css/pathchooser.css40
-rw-r--r--module/web/pyload/templatetags/truncate.py13
-rw-r--r--module/web/pyload/urls.py6
-rw-r--r--module/web/pyload/views.py60
-rw-r--r--module/web/templates/default/pathchooser.html52
-rw-r--r--module/web/templates/default/settings.html8
6 files changed, 176 insertions, 3 deletions
diff --git a/module/web/media/default/css/pathchooser.css b/module/web/media/default/css/pathchooser.css
new file mode 100644
index 000000000..2573c2eb1
--- /dev/null
+++ b/module/web/media/default/css/pathchooser.css
@@ -0,0 +1,40 @@
+TABLE {
+ border: 1px dotted #888888;
+ font-family: sans-serif;
+ font-size: 10pt;
+}
+
+TH {
+ background-color: #525252;
+ color: #E0E0E0;
+}
+
+TABLE, TR, TD {
+ background-color: #F0F0F0;
+}
+
+A, A:visited {
+ text-decoration: none;
+ font-weight: bold;
+}
+
+.file {
+ color: #c0c0c0;
+}
+
+.parentdir {
+ color: #000000;
+ font-size: 10pt;
+}
+.name {
+ text-align: left;
+}
+.size {
+ text-align: right;
+}
+.type {
+ text-align: left;
+}
+.mtime {
+ text-align: center;
+}
diff --git a/module/web/pyload/templatetags/truncate.py b/module/web/pyload/templatetags/truncate.py
new file mode 100644
index 000000000..ed35ea998
--- /dev/null
+++ b/module/web/pyload/templatetags/truncate.py
@@ -0,0 +1,13 @@
+from django.template.defaultfilters import stringfilter
+from django import template
+
+register = template.Library()
+
+
+@stringfilter
+def truncate(value, n):
+ if (n - len(value)) < 3:
+ return value[:n]+"..."
+ return value
+
+register.filter(truncate)
diff --git a/module/web/pyload/urls.py b/module/web/pyload/urls.py
index c4c2f6ef2..6523d711a 100644
--- a/module/web/pyload/urls.py
+++ b/module/web/pyload/urls.py
@@ -17,9 +17,13 @@ urlpatterns = patterns('pyload',
(r'^logs/(?P<item>\d+)$', 'views.logs',{}, 'logs'),
(r'^package_ui.js$', 'views.package_ui', {}, 'package_ui'),
(r'^$', 'views.home',{}, 'home'),
+ url(r'^pathchooser/(?P<path>.*)', 'views.path', name='path'),
+ url(r'^pathchooser/$', 'views.root', name='root'),
)
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 240465285..8e08e408b 100644
--- a/module/web/pyload/views.py
+++ b/module/web/pyload/views.py
@@ -2,6 +2,7 @@
# Create your views here.
import mimetypes
+import os
from os import listdir
from os import stat
from os.path import isdir
@@ -12,6 +13,7 @@ from itertools import chain
from datetime import datetime
from time import localtime, strftime
from copy import deepcopy
+from operator import itemgetter
from django.conf import settings
from django.contrib.auth.decorators import login_required
@@ -20,6 +22,7 @@ from django.http import HttpResponseNotFound
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.utils.translation import ugettext as _
+from django.core.urlresolvers import reverse
def get_sort_key(item):
@@ -369,4 +372,59 @@ def config(request):
@permission('pyload.can_change_status')
@check_server
def package_ui(request):
- return render_to_response(join(settings.TEMPLATE, 'package_ui.js'), RequestContext(request, {}, )) \ No newline at end of file
+ return render_to_response(join(settings.TEMPLATE, 'package_ui.js'), RequestContext(request, {}, ))
+
+
+@login_required
+@permission('pyload.can_change_status')
+@check_server
+def root(request):
+ cwd = os.getcwd()
+ return HttpResponseRedirect(reverse('path', args=[cwd[1:]]))
+
+@login_required
+@permission('pyload.can_change_status')
+@check_server
+def path(request, path):
+
+ files = []
+ if os.path.isdir(path):
+ cwd = path
+ else:
+ cwd = os.getcwd()
+
+ if cwd[-1] == '/':
+ parentdir = os.path.split(cwd[:-1])[0]
+ else:
+ parentdir = os.path.split(cwd)[0]
+
+ for f in os.listdir(cwd):
+ data = {'name': f[:50],
+ 'size': '',
+ 'modified': '',
+ 'type': 'file',
+ 'fullpath': ''}
+ data['fullpath'] = os.path.join(cwd, f)
+ data['sort'] = data['fullpath'].lower()
+ data['modified'] = datetime.fromtimestamp(int(os.path.getmtime(os.path.join(cwd, f))))
+ data['ext'] = os.path.splitext(f)[1]
+ if os.path.isdir(os.path.join(cwd, f)):
+ data['type'] = 'dir'
+
+ if os.path.isfile(os.path.join(cwd, f)):
+ data['size'] = os.path.getsize(os.path.join(cwd, f))
+
+ power = 0
+ while (data['size']/1024) > 0.3:
+ power += 1
+ data['size'] = data['size'] / 1024.
+ units = ('', 'K','M','G','T')
+ data['unit'] = units[power]+'Byte'
+
+ files.append(data)
+
+ files = sorted(files, key=itemgetter('type', 'sort'))
+
+ return render_to_response(join(settings.TEMPLATE, 'pathchooser.html'), {'cwd': cwd, 'files': files, 'parentdir': parentdir}, RequestContext(request))
+
+
diff --git a/module/web/templates/default/pathchooser.html b/module/web/templates/default/pathchooser.html
new file mode 100644
index 000000000..3c5329f09
--- /dev/null
+++ b/module/web/templates/default/pathchooser.html
@@ -0,0 +1,52 @@
+{% load truncate %}
+<html>
+<head>
+ <script class="javascript">
+ function chosen()
+ {
+ opener.ifield.value = document.forms[0].p.value;
+ close();
+ }
+ function exit()
+ {
+ close();
+ }
+ </script>
+ <link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}css/pathchooser.css"/>
+</head>
+<body>
+<center>
+ <form method="get" action="?" onSubmit="chosen();" onReset="exit();">
+ <input type="text" name="p" value="{{ cwd }}" size="60">
+ <input type="submit" value="Ok">
+ </form>
+
+ <table border="0" cellspacing="0" cellpadding="3" width="90%">
+ <tr>
+ <th>Name</th>
+ <th>Size</th>
+ <th>Type</th>
+ <th>Last modified</th>
+ </tr>
+ <tr>
+ <td colspan="4">
+ <a href="{% url path parentdir %}"><span class="parentdir">parent directory</span></a>
+ </td>
+ </tr>
+{% for file in files %}
+ <tr>
+ <td class="name">{% ifequal file.type 'dir' %}<a href="{% url path file.fullpath %}"><span class="directory">{{ file.name|truncate:25 }}</a></span>{% else %}<span class="file">{{ file.name|truncate:25 }}{% endifequal %}</span></td>
+ <td class="size">{{ file.size|floatformat:-2 }} {{ file.unit }}</td>
+ <td class="type">{% ifequal file.type 'dir' %}directory{% else %}{{ file.ext }}{% endifequal %}</td>
+ <td class="mtime">{{ file.modified|date:"d.m.Y - H:i:s" }}</td>
+ <tr>
+{% empty %}
+ <tr>
+ <td colspan="4">no content</td>
+ </tr>
+{% endfor %}
+ </table>
+ </center>
+</body>
+</html>
+
diff --git a/module/web/templates/default/settings.html b/module/web/templates/default/settings.html
index 6c9c2982a..dd67801a9 100644
--- a/module/web/templates/default/settings.html
+++ b/module/web/templates/default/settings.html
@@ -114,7 +114,13 @@
{% endfor %}
</select>
{% else %}
- <input id="{{skey}}|{{okey}}" name="{{configname}}|{{skey}}|{{okey}}" type="text" value="{{option.value}}"/>
+ {% if okey|contains:"_folder" %}
+
+ <input name="{{configname}}|{{skey}}|{{okey}}" type="text" id="{{skey}}|{{okey}}" value="{{option.value}}"/>
+ <input name="browsebutton" type="button" onClick="ifield = document.getElementById('{{skey}}|{{okey}}'); pathchooser = window.open('{% if option.value %}{% url path option.value %}{% else %}{% url root %}{% endif %}', 'pathchooser', 'scrollbars=yes,toolbar=no,menubar=no,statusbar=no,width=650,height=300'); pathchooser.ifield = ifield; window.ifield = ifield;" value="browse"/>
+ {% else %}
+ <input id="{{skey}}|{{okey}}" name="{{configname}}|{{skey}}|{{okey}}" type="text" value="{{option.value}}"/>
+ {% endif %}
{% endif %}
{% endifequal %}
</td>