summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar therazer <devnull@localhost> 2010-11-15 18:53:36 +0100
committerGravatar therazer <devnull@localhost> 2010-11-15 18:53:36 +0100
commit8218c2b3e47684d580f388603ea38c40374d4359 (patch)
treec4911eb38a63be22bc012636b32847f6e8977155
parentmaking filebrowser compatible with relative paths (diff)
downloadpyload-8218c2b3e47684d580f388603ea38c40374d4359.tar.xz
fixes for file browser
-rw-r--r--module/web/media/default/css/pathchooser.css19
-rw-r--r--module/web/pyload/templatetags/quotepath.py24
-rw-r--r--module/web/pyload/views.py38
-rw-r--r--module/web/templates/default/pathchooser.html40
4 files changed, 95 insertions, 26 deletions
diff --git a/module/web/media/default/css/pathchooser.css b/module/web/media/default/css/pathchooser.css
index f660b7c5a..894cc335e 100644
--- a/module/web/media/default/css/pathchooser.css
+++ b/module/web/media/default/css/pathchooser.css
@@ -1,4 +1,5 @@
table {
+ width: 90%;
border: 1px dotted #888888;
font-family: sans-serif;
font-size: 10pt;
@@ -18,6 +19,11 @@ a, a:visited {
font-weight: bold;
}
+#paths {
+ width: 90%;
+ text-align: left;
+}
+
.file_directory {
color: #c0c0c0;
}
@@ -47,3 +53,16 @@ a, a:visited {
.mtime {
text-align: center;
}
+
+.path_abs_rel {
+ color: #3c3c3c;
+ text-decoration: none;
+ font-weight: bold;
+ font-family: sans-serif;
+ font-size: 10pt;
+}
+
+.path_abs_rel a {
+ color: #3c3c3c;
+ font-style: italic;
+}
diff --git a/module/web/pyload/templatetags/quotepath.py b/module/web/pyload/templatetags/quotepath.py
index a38932d59..6c461b445 100644
--- a/module/web/pyload/templatetags/quotepath.py
+++ b/module/web/pyload/templatetags/quotepath.py
@@ -1,5 +1,6 @@
from django.template.defaultfilters import stringfilter
from django import template
+import os
register = template.Library()
@@ -26,4 +27,25 @@ def unquotepath(path):
except:
return ""
-register.filter(unquotepath) \ No newline at end of file
+register.filter(unquotepath)
+
+def path_make_absolute(path):
+ p = os.path.abspath(path)
+ if p[-1] == os.path.sep:
+ return p
+ else:
+ return p + os.path.sep
+
+
+register.filter(path_make_absolute)
+
+def path_make_relative(path):
+ p = os.path.relpath(path)
+ if p[-1] == os.path.sep:
+ return p
+ else:
+ return p + os.path.sep
+
+
+register.filter(path_make_relative)
+
diff --git a/module/web/pyload/views.py b/module/web/pyload/views.py
index 0fcabaede..4de53a61d 100644
--- a/module/web/pyload/views.py
+++ b/module/web/pyload/views.py
@@ -388,23 +388,41 @@ def root(request, type):
@permission('pyload.can_change_status')
@check_server
def path(request, path, type):
- path = quotepath.unquotepath(path)
+
+ path = os.path.normpath(quotepath.unquotepath(path))
+
if os.path.isfile(path):
oldfile = path
path = os.path.dirname(path)
else:
oldfile = ''
-
+
+ abs = False
+
if os.path.isdir(path):
- cwd = path
+ if os.path.isabs(path):
+ cwd = os.path.abspath(path)
+ abs = True
+ else:
+ cwd = os.path.relpath(path)
else:
cwd = os.getcwd()
-
- if cwd[-1] == '/':
- parentdir = os.path.split(cwd[:-1])[0]
- else:
- parentdir = os.path.split(cwd)[0]
-
+
+ cwd = os.path.normpath(os.path.abspath(cwd))
+ parentdir = os.path.dirname(cwd)
+ if not abs:
+ if os.path.abspath(cwd) == "/":
+ cwd = os.path.relpath(cwd)
+ else:
+ cwd = os.path.relpath(cwd) + os.path.sep
+ parentdir = os.path.relpath(parentdir) + os.path.sep
+
+ if os.path.abspath(cwd) == "/":
+ parentdir = ""
+
+ print os.path.split(cwd)
+ print "parentdir: %s" % parentdir
+
try:
folders = os.listdir(cwd)
except:
@@ -444,4 +462,4 @@ def path(request, path, type):
files = sorted(files, key=itemgetter('type', 'sort'))
- return render_to_response(join(settings.TEMPLATE, 'pathchooser.html'), {'cwd': cwd, 'files': files, 'parentdir': parentdir, 'type': type, 'oldfile': oldfile}, RequestContext(request)) \ No newline at end of file
+ return render_to_response(join(settings.TEMPLATE, 'pathchooser.html'), {'cwd': cwd, 'files': files, 'parentdir': parentdir, 'type': type, 'oldfile': oldfile, 'absolute': abs}, RequestContext(request)) \ No newline at end of file
diff --git a/module/web/templates/default/pathchooser.html b/module/web/templates/default/pathchooser.html
index 10299e458..6a72214e8 100644
--- a/module/web/templates/default/pathchooser.html
+++ b/module/web/templates/default/pathchooser.html
@@ -1,5 +1,6 @@
{% load truncate %}
{% load quotepath %}
+{% load i18n %}
<html>
<head>
<script class="javascript">
@@ -31,40 +32,49 @@
</head>
<body{% ifequal type 'file' %}{% if not oldfile %} onload="setInvalid();"{% endif %}{% endifequal %}>
<center>
- <form method="get" action="?" onSubmit="chosen();" onReset="exit();">
- <input type="text" name="p" value="{{ oldfile|default:cwd }}" size="60" onfocus="setValid();">
- <input type="submit" value="Ok" name="send">
- </form>
- <table border="0" cellspacing="0" cellpadding="3" width="90%">
+ <div id="paths">
+ <form method="get" action="?" onSubmit="chosen();" onReset="exit();">
+ <input type="text" name="p" value="{{ oldfile|default:cwd }}" size="60" onfocus="setValid();">
+ <input type="submit" value="Ok" name="send">
+ </form>
+
+ {% ifequal type 'folder' %}
+ <span class="path_abs_rel">{% trans "Path" %}: <a href="{% url path cwd|path_make_absolute|quotepath %}"{% if absolute %} style="text-decoration: underline;"{% endif %}>{% trans "absolute" %}</a> | <a href="{% url path cwd|path_make_relative|quotepath %}"{% if not absolute %} style="text-decoration: underline;"{% endif %}>{% trans "relative" %}</a></span>
+ {% else %}
+ <span class="path_abs_rel">{% trans "Path" %}: <a href="{% url file cwd|path_make_absolute|quotepath %}"{% if absolute %} style="text-decoration: underline;"{% endif %}>{% trans "absolute" %}</a> | <a href="{% url file cwd|path_make_relative|quotepath %}"{% if not absolute %} style="text-decoration: underline;"{% endif %}>{% trans "relative" %}</a></span>
+ {% endifequal %}
+ </div>
+ <table border="0" cellspacing="0" cellpadding="3">
<tr>
- <th>Name</th>
- <th>Size</th>
- <th>Type</th>
- <th>Last modified</th>
+ <th>{% trans "name" %}</th>
+ <th>{% trans "size" %}</th>
+ <th>{% trans "type" %}</th>
+ <th>{% trans "last modified" %}</th>
</tr>
+ {% if parentdir %}
<tr>
<td colspan="4">
- <a href="{% ifequal type 'folder' %}{% url path parentdir %}{% else %}{% url file parentdir %}{% endifequal %}"><span class="parentdir">parent directory</span></a>
+ <a href="{% ifequal type 'folder' %}{% url path parentdir|quotepath %}{% else %}{% url file parentdir|quotepath %}{% endifequal %}"><span class="parentdir">{% trans "parent directory" %}</span></a>
</td>
</tr>
+ {% endif %}
{% for file in files %}
<tr>
{% ifequal type 'folder' %}
- <td class="name">{% ifequal file.type 'dir' %}<a href="{% url path file.fullpath|quotepath %}" title="{{ file.fullpath }}"><span class="path_directory">{{ file.name|truncate:25 }}</span></a>{% else %}<span class="path_file">{{ file.name|truncate:25 }}{% endifequal %}</span></td>
+ <td class="name">{% ifequal file.type 'dir' %}<a href="{% url path file.fullpath|quotepath %}" title="{{ file.fullpath }}"><span class="path_directory">{{ file.name|truncate:25 }}</span></a>{% else %}<span class="path_file" title="{{ file.fullpath }}">{{ file.name|truncate:25 }}{% endifequal %}</span></td>
{% else %}
<td class="name">{% ifequal file.type 'dir' %}<a href="{% url file file.fullpath|quotepath %}" title="{{ file.fullpath }}"><span class="file_directory">{{ file.name|truncate:25 }}</span></a>{% else %}<a href="#" onclick="setFile('{{ file.fullpath }}');" title="{{ file.fullpath }}"><span class="file_file">{{ file.name|truncate:25 }}{% endifequal %}</span></a></td>
{% endifequal %}
<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="type">{% ifequal file.type 'dir' %}directory{% else %}{{ file.ext|default:"file" }}{% endifequal %}</td>
<td class="mtime">{{ file.modified|date:"d.m.Y - H:i:s" }}</td>
<tr>
{% empty %}
<tr>
- <td colspan="4">no content</td>
+ <td colspan="4">{% trans "no content" %}</td>
</tr>
{% endfor %}
</table>
</center>
</body>
-</html>
-
+</html> \ No newline at end of file