summaryrefslogtreecommitdiffstats
path: root/module/web/pyload
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 /module/web/pyload
parentmaking filebrowser compatible with relative paths (diff)
downloadpyload-8218c2b3e47684d580f388603ea38c40374d4359.tar.xz
fixes for file browser
Diffstat (limited to 'module/web/pyload')
-rw-r--r--module/web/pyload/templatetags/quotepath.py24
-rw-r--r--module/web/pyload/views.py38
2 files changed, 51 insertions, 11 deletions
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