From: Maciej Tronowski Date: Fri, 3 Apr 2015 14:50:46 +0000 (+0200) Subject: file upload to gridftp X-Git-Tag: v1.0~91 X-Git-Url: http://mmka.chem.univ.gda.pl/gitweb/?a=commitdiff_plain;ds=sidebyside;h=a0070644fd09063d4222ca3142f3e920924c0bea;hp=9b5f7c38b0213c78beb5c34d821b0562f6a1946a;p=qcg-portal.git file upload to gridftp --- diff --git a/filex/templates/filex/upload.css.html b/filex/templates/filex/upload.css.html new file mode 100644 index 0000000..3490714 --- /dev/null +++ b/filex/templates/filex/upload.css.html @@ -0,0 +1,30 @@ + diff --git a/filex/templates/filex/upload.html b/filex/templates/filex/upload.html new file mode 100644 index 0000000..ef1ddf0 --- /dev/null +++ b/filex/templates/filex/upload.html @@ -0,0 +1,23 @@ +
+

{% block title %}Wgrywanie plików{% endblock %}

+

Lokalizacja: {{ host }}{{ path }}

+
+ + + +
+
+ + diff --git a/filex/templates/filex/upload.js.html b/filex/templates/filex/upload.js.html new file mode 100644 index 0000000..1ad049f --- /dev/null +++ b/filex/templates/filex/upload.js.html @@ -0,0 +1,100 @@ +{% load staticfiles %} + + + + + + + + + + diff --git a/filex/uploadhandler.py b/filex/uploadhandler.py index 20a1339..0f5bfb3 100644 --- a/filex/uploadhandler.py +++ b/filex/uploadhandler.py @@ -1,5 +1,8 @@ +from functools import wraps + from django.core.files.uploadedfile import UploadedFile from django.core.files.uploadhandler import FileUploadHandler, StopUpload, StopFutureHandlers +from django.views.decorators.csrf import csrf_exempt, csrf_protect from filex.ftp import FTPOperation @@ -35,3 +38,13 @@ class FtpUploadHandler(FileUploadHandler): return UploadedFile(name=self.file_name, size=file_size, charset=self.charset, content_type=self.content_type, content_type_extra=self.content_type_extra) + + +def with_ftp_upload_handler(view_func): + @wraps(view_func) + def wrapped_view(request, *args, **kwargs): + request.upload_handlers = [FtpUploadHandler(request)] + + return csrf_protect(view_func)(request, *args, **kwargs) + + return csrf_exempt(wrapped_view) diff --git a/filex/urls.py b/filex/urls.py index 382d720..3a1945d 100644 --- a/filex/urls.py +++ b/filex/urls.py @@ -5,4 +5,5 @@ from filex import views urlpatterns = patterns('', url(r'^list/$', views.list_content, name='list'), url(r'^download/$', views.download, name='download'), + url(r'^upload/$', views.upload, name='upload'), ) diff --git a/filex/views.py b/filex/views.py index 2bda5c8..57932d7 100644 --- a/filex/views.py +++ b/filex/views.py @@ -1,13 +1,14 @@ from datetime import datetime +import mimetypes from django.core.exceptions import PermissionDenied, SuspiciousOperation from django.http import JsonResponse, StreamingHttpResponse from django.template.defaultfilters import filesizeformat from django.utils.formats import date_format from django.utils.timezone import UTC, localtime -import mimetypes from filex.ftp import FTPOperation, FTPException +from filex.uploadhandler import with_ftp_upload_handler def check_auth(request): @@ -78,3 +79,9 @@ def download(request): response['Content-Encoding'] = encoding return response + + +@with_ftp_upload_handler +def upload(request): + # TODO error handling + return JsonResponse({'success': True}) diff --git a/qcg/templates/qcg/base.html b/qcg/templates/qcg/base.html index 7030598..9f38b0c 100644 --- a/qcg/templates/qcg/base.html +++ b/qcg/templates/qcg/base.html @@ -1,4 +1,4 @@ -{% load staticfiles webdesign %} +{% load staticfiles %} {% load firstof from future %} @@ -14,6 +14,7 @@ {% block extra_css %}{% endblock %} + {% block body %}