From dee5b1cbf07c44e308dbccea2e49bb484eb6f2f5 Mon Sep 17 00:00:00 2001 From: Maciej Tronowski Date: Mon, 20 Apr 2015 17:12:05 +0200 Subject: [PATCH] gridftp: handle paths beginning with `~` --- filex/forms.py | 4 +-- filex/migrations/0003_auto_20150420_1646.py | 20 +++++++++++ filex/models.py | 2 +- filex/static/filex/filex.js | 51 ++++++++++++--------------- filex/templates/filex/source.js.html | 4 --- filex/templatetags/filex.py | 2 +- filex/uploadhandler.py | 3 +- filex/views.py | 4 +-- 8 files changed, 51 insertions(+), 39 deletions(-) create mode 100644 filex/migrations/0003_auto_20150420_1646.py diff --git a/filex/forms.py b/filex/forms.py index 26ca737..e9b866f 100644 --- a/filex/forms.py +++ b/filex/forms.py @@ -12,12 +12,12 @@ from filex.models import Favorite msg = u'Invalid value' host_validator = RegexValidator(r'^(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+' r'(?:[a-zA-Z]{2,6}\.?|[a-zA-Z0-9-]{2,}(?', { href: '#', - text: this.model.get('text') + text: this.model.get('name') })); } this.$el.toggleClass('active', this.model.get('active')); @@ -261,13 +261,13 @@ $(function(){ lockOptgroupOrder: true, create: function(input, callback) { var $form = $('#favorite-form'), - parts = input.split('/', 1), + parts = input.split('/'), callback_called = false; - $form.find('#id_host').val(parts[0]); + $form.find('#id_host').val(parts.shift()); - if (parts.length > 1) - $form.find('#id_path').val(parts[1]); + if (parts.length) + $form.find('#id_path').val(parts.join('/')); $form.on('submit', function(e) { var $this = $(this), @@ -326,13 +326,15 @@ $(function(){ }, load: function(location) { - var path = location.replace(/(^\/+|\/+$)/g, '').split('/'), - host = path.shift(), - pathBits = [new Filex.PathBit({'text': '/', 'path': ''})].concat(_.map(path, function(name) { - return new Filex.PathBit({'text': name, 'path': name}); - })); - - this.host = host; + var hostRootPath = location.split(/\/(\/|~)(.*)/), + pathBits = [new Filex.PathBit({'name': hostRootPath[1]})].concat( + _.chain(hostRootPath[2].split('/')) + .filter(_.identity) + .map(function(name) { return new Filex.PathBit({'name': name}) }) + .value() + ); + + this.host = hostRootPath[0]; this.path.reset(pathBits); this.$host.text(this.host); @@ -393,7 +395,7 @@ $(function(){ }, selectedDir: function(dir) { - this.path.add({'text': dir.get('name'), 'path': dir.get('name')}); + this.path.add({'name': dir.get('name')}); }, selectedPath: function(bit) { @@ -459,20 +461,13 @@ $(function(){ $btn.button('loading'); - $.post(url, data, 'json').done(function () { + $.post(url, data, 'json').done(function (response) { $btn.button('reset'); - if (is_active) { - locations.removeOption(data.host + data.path); - } - else { - locations.addOption({ - group: 'usr', - host: data.host, - path: data.path, - value: data.host + data.path - }); - } + if (is_active) + locations.removeOption(data.host + '/' + data.path); + else + locations.addOption(response); }).fail(function() { $btn.button('reset'); $btn.button('toggle'); @@ -495,7 +490,7 @@ $(function(){ }, updateFavorites: function() { - var loc = this.host + this.path.full(), + var loc = this.host + '/' + this.path.full(), favorites = this.hostSelectize.options; if (favorites.hasOwnProperty(loc)) { diff --git a/filex/templates/filex/source.js.html b/filex/templates/filex/source.js.html index 311acb7..0623fde 100644 --- a/filex/templates/filex/source.js.html +++ b/filex/templates/filex/source.js.html @@ -12,10 +12,6 @@ }); - -