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,}(?<!-)\.?))(?::\d+)?$', msg)
-path_validator = RegexValidator(r'^/(?:[^/\0]+/?)*$', msg)
+path_validator = RegexValidator(r'^~?(?:/[^/\0]*)*$', msg)
name_validator = RegexValidator(r'^[^/\0]+$', msg)
def clean_path(path):
- return urlquote(os.path.normpath(path))
+ return urlquote(os.path.normpath(path), safe='/~')
class FavoriteForm(forms.ModelForm):
class Favorite(models.Model):
owner = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=u"Właściciel", related_name='favorites')
host = models.CharField(u"Host", max_length=256)
- path = models.CharField(u"Ścieżka", max_length=1024, default='/')
+ path = models.CharField(u"Ścieżka", max_length=1024, default='~')
created = models.DateTimeField(u"Utworzono", auto_now_add=True)
updated = models.DateTimeField(u"Uaktualniono", auto_now=True)
},
full: function() {
- return this.pluck('path').join('/') || '/';
+ return this.pluck('name').join('/').replace(/^\/+/, '/');
}
});
render: function() {
if (this.model.get('active')) {
- this.$el.text(this.model.get('text'));
+ this.$el.text(this.model.get('name'));
}
else {
this.$el.html($('<a/>', {
href: '#',
- text: this.model.get('text')
+ text: this.model.get('name')
}));
}
this.$el.toggleClass('active', this.model.get('active'));
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),
},
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);
},
selectedDir: function(dir) {
- this.path.add({'text': dir.get('name'), 'path': dir.get('name')});
+ this.path.add({'name': dir.get('name')});
},
selectedPath: function(bit) {
$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');
},
updateFavorites: function() {
- var loc = this.host + this.path.full(),
+ var loc = this.host + '/' + this.path.full(),
favorites = this.hostSelectize.options;
if (favorites.hasOwnProperty(loc)) {
def make_url(params, *parts):
- return 'gsiftp://' + params['host'] + (os.path.join(*[params[part] for part in parts]) if parts else '')
+ return 'gsiftp://{}/{}'.format(params['host'], os.path.join(*[params[part] for part in parts]) if parts else '')
@require_POST
instance = form.save()
return JsonResponse({'group': 'usr', 'host': instance.host, 'path': instance.path,
- 'value': instance.host + instance.path})
+ 'value': instance.host + '/' + instance.path})
return JsonResponse({'error': form.errors}, status=400)