projects
/
qcg-portal.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
clean-up
[qcg-portal.git]
/
filex
/
uploadhandler.py
diff --git
a/filex/uploadhandler.py
b/filex/uploadhandler.py
index
20a1339
..
7e57a36
100644
(file)
--- a/
filex/uploadhandler.py
+++ b/
filex/uploadhandler.py
@@
-1,27
+1,33
@@
+import os
+
from django.core.files.uploadedfile import UploadedFile
from django.core.files.uploadhandler import FileUploadHandler, StopUpload, StopFutureHandlers
from django.core.files.uploadedfile import UploadedFile
from django.core.files.uploadhandler import FileUploadHandler, StopUpload, StopFutureHandlers
+from filex.forms import HostPathForm
from filex.ftp import FTPOperation
class FtpUploadHandler(FileUploadHandler):
ftp = None
from filex.ftp import FTPOperation
class FtpUploadHandler(FileUploadHandler):
ftp = None
+ url = None
+ tmp_url = None
def new_file(self, file_name, *args, **kwargs):
super(FtpUploadHandler, self).new_file(file_name, *args, **kwargs)
def new_file(self, file_name, *args, **kwargs):
super(FtpUploadHandler, self).new_file(file_name, *args, **kwargs)
- # TODO limit to selected request.path
- # TODO validate host and path
- host = self.request.GET.get('host')
- path = self.request.GET.get('path')
+ form = HostPathForm(self.request.GET)
- if self.request.user.is_anonymous() or not host or not path:
+ if self.request.user.is_anonymous() or not form.is_valid():
raise StopUpload(connection_reset=True)
if self.ftp is None:
self.ftp = FTPOperation(self.request.session['proxy'], self.chunk_size)
raise StopUpload(connection_reset=True)
if self.ftp is None:
self.ftp = FTPOperation(self.request.session['proxy'], self.chunk_size)
- self.ftp.put('gsiftp://' + host + path + self.file_name)
+ self.url = 'gsiftp://{}/{}'.format(form.cleaned_data['host'],
+ os.path.join(form.cleaned_data['path'], self.file_name))
+ self.tmp_url = self.url + '.part'
+
+ self.ftp.put(self.tmp_url)
StopFutureHandlers()
StopFutureHandlers()
@@
-33,5
+39,7
@@
class FtpUploadHandler(FileUploadHandler):
self.ftp.stream.put(None)
self.ftp.wait()
self.ftp.stream.put(None)
self.ftp.wait()
+ self.ftp.move(self.tmp_url, self.url)
+
return UploadedFile(name=self.file_name, size=file_size, charset=self.charset,
content_type=self.content_type, content_type_extra=self.content_type_extra)
return UploadedFile(name=self.file_name, size=file_size, charset=self.charset,
content_type=self.content_type, content_type_extra=self.content_type_extra)