diff options
author | therazer <devnull@localhost> | 2010-11-15 00:28:54 +0100 |
---|---|---|
committer | therazer <devnull@localhost> | 2010-11-15 00:28:54 +0100 |
commit | 08f5c51555a931953423514887aef33bb18a3bce (patch) | |
tree | 1efed11bc7b08400845b1b3e1cb4152596dfd03c /module/web | |
parent | hotfolder fix (diff) | |
download | pyload-08f5c51555a931953423514887aef33bb18a3bce.tar.xz |
making filebrowser compatible with relative paths
Diffstat (limited to 'module/web')
-rw-r--r-- | module/web/pyload/templatetags/quotepath.py | 29 | ||||
-rw-r--r-- | module/web/pyload/views.py | 7 | ||||
-rw-r--r-- | module/web/templates/default/pathchooser.html | 5 | ||||
-rw-r--r-- | module/web/templates/default/settings.html | 5 |
4 files changed, 38 insertions, 8 deletions
diff --git a/module/web/pyload/templatetags/quotepath.py b/module/web/pyload/templatetags/quotepath.py new file mode 100644 index 000000000..a38932d59 --- /dev/null +++ b/module/web/pyload/templatetags/quotepath.py @@ -0,0 +1,29 @@ +from django.template.defaultfilters import stringfilter +from django import template + +register = template.Library() + +quotechar = "::/" + +@stringfilter +def quotepath(path): + try: + return path.replace("../", quotechar) + except AttributeError: + return path + except: + return "" + + +register.filter(quotepath) + +@stringfilter +def unquotepath(path): + try: + return path.replace(quotechar, "../") + except AttributeError: + return path + except: + return "" + +register.filter(unquotepath)
\ No newline at end of file diff --git a/module/web/pyload/views.py b/module/web/pyload/views.py index c1cd31f5f..0fcabaede 100644 --- a/module/web/pyload/views.py +++ b/module/web/pyload/views.py @@ -14,6 +14,7 @@ from datetime import datetime from time import localtime, strftime from copy import deepcopy from operator import itemgetter +from pyload.templatetags import quotepath from django.conf import settings from django.contrib.auth.decorators import login_required @@ -387,7 +388,7 @@ def root(request, type): @permission('pyload.can_change_status') @check_server def path(request, path, type): - + path = quotepath.unquotepath(path) if os.path.isfile(path): oldfile = path path = os.path.dirname(path) @@ -443,6 +444,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)) - - + 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 diff --git a/module/web/templates/default/pathchooser.html b/module/web/templates/default/pathchooser.html index 100754cad..10299e458 100644 --- a/module/web/templates/default/pathchooser.html +++ b/module/web/templates/default/pathchooser.html @@ -1,4 +1,5 @@ {% load truncate %} +{% load quotepath %} <html> <head> <script class="javascript"> @@ -49,9 +50,9 @@ {% for file in files %} <tr> {% ifequal type 'folder' %} - <td class="name">{% ifequal file.type 'dir' %}<a href="{% url path file.fullpath %}" 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">{{ file.name|truncate:25 }}{% endifequal %}</span></td> {% else %} - <td class="name">{% ifequal file.type 'dir' %}<a href="{% url file file.fullpath %}" 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> + <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> diff --git a/module/web/templates/default/settings.html b/module/web/templates/default/settings.html index 79ec62d19..af87d632c 100644 --- a/module/web/templates/default/settings.html +++ b/module/web/templates/default/settings.html @@ -1,6 +1,7 @@ {% extends 'default/base.html' %} {% load i18n %} {% load contains %} +{% load quotepath %} {% block title %}{% trans "Config" %} - {{block.super}} {% endblock %} {% block subtitle %}{% trans "Config" %}{% endblock %} @@ -116,11 +117,11 @@ {% else %} {% ifequal option.type "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 pathroot %}{% endif %}', 'pathchooser', 'scrollbars=yes,toolbar=no,menubar=no,statusbar=no,width=650,height=300'); pathchooser.ifield = ifield; window.ifield = ifield;" value="{% trans "Browse" %}"/> + <input name="browsebutton" type="button" onclick="ifield = document.getElementById('{{skey}}|{{okey}}'); pathchooser = window.open('{% if option.value %}{% url path option.value|quotepath %}{% else %}{% url pathroot %}{% endif %}', 'pathchooser', 'scrollbars=yes,toolbar=no,menubar=no,statusbar=no,width=650,height=300'); pathchooser.ifield = ifield; window.ifield = ifield;" value="{% trans "Browse" %}"/> {% else %} {% ifequal option.type "file" %} <input name="{{configname}}|{{skey}}|{{okey}}" type="text" id="{{skey}}|{{okey}}" value="{{option.value}}"/> - <input name="browsebutton" type="button" onclick="ifield = document.getElementById('{{skey}}|{{okey}}'); filechooser = window.open('{% if option.value %}{% url file option.value %}{% else %}{% url fileroot %}{% endif %}', 'filechooser', 'scrollbars=yes,toolbar=no,menubar=no,statusbar=no,width=650,height=300'); filechooser.ifield = ifield; window.ifield = ifield;" value="{% trans "Browse" %}"/> + <input name="browsebutton" type="button" onclick="ifield = document.getElementById('{{skey}}|{{okey}}'); filechooser = window.open('{% if option.value %}{% url file option.value|quotepath %}{% else %}{% url fileroot %}{% endif %}', 'filechooser', 'scrollbars=yes,toolbar=no,menubar=no,statusbar=no,width=650,height=300'); filechooser.ifield = ifield; window.ifield = ifield;" value="{% trans "Browse" %}"/> {% else %} <input id="{{skey}}|{{okey}}" name="{{configname}}|{{skey}}|{{okey}}" type="text" value="{{option.value}}"/> {% endifequal %} |