extract validators and decorator to utils
[qcg-portal.git] / filex / views.py
index 8ef9d5b..f5aabb8 100644 (file)
@@ -13,7 +13,7 @@ from django.views.generic import View
 
 from filex.forms import HostPathNameForm, RenameForm, FavoriteForm, HostPathForm, ExtractForm, HostItemsForm, \
     CompressForm
-from filex.ftp import FTPOperation, FTPException
+from filex.ftp import FTPOperation, FTPError
 from filex.models import Favorite
 from filex.uploadhandler import with_ftp_upload_handler
 
@@ -37,7 +37,7 @@ class FTPView(View):
 
             try:
                 return self.handle(FTPOperation(request.session['proxy']), form.cleaned_data)
-            except FTPException as e:
+            except FTPError as e:
                 status = 400
                 if 'No such file or directory' in e.message:
                     status = 404
@@ -102,7 +102,7 @@ class DeleteView(FTPView):
         for path in params['dirs']:
             try:
                 ftp.rmdir(url + path)
-            except FTPException as e:
+            except FTPError as e:
                 fail[path] = e.message
             else:
                 done.append(path)
@@ -110,7 +110,7 @@ class DeleteView(FTPView):
         for path in params['files']:
             try:
                 ftp.delete(url + path)
-            except FTPException as e:
+            except FTPError as e:
                 fail[path] = e.message
             else:
                 done.append(path)
@@ -133,7 +133,6 @@ class MoveView(FTPView):
     form_class = RenameForm
 
     def handle(self, ftp, params):
-        print params
         ftp.move(make_url(params, 'src'), make_url(params, 'dst'))
 
         return JsonResponse({'success': True})
@@ -168,7 +167,7 @@ class ExtractView(FTPView):
 
 
 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
@@ -190,7 +189,7 @@ def fav_add(request):
         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)