From 8218c2b3e47684d580f388603ea38c40374d4359 Mon Sep 17 00:00:00 2001 From: therazer Date: Mon, 15 Nov 2010 18:53:36 +0100 Subject: fixes for file browser --- module/web/media/default/css/pathchooser.css | 19 +++++++++++++ module/web/pyload/templatetags/quotepath.py | 24 +++++++++++++++- module/web/pyload/views.py | 38 ++++++++++++++++++------- module/web/templates/default/pathchooser.html | 40 +++++++++++++++++---------- 4 files changed, 95 insertions(+), 26 deletions(-) (limited to 'module/web') 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 %}