本文整理汇总了Python中filebrowser.forms.UploadFileForm类的典型用法代码示例。如果您正苦于以下问题:Python UploadFileForm类的具体用法?Python UploadFileForm怎么用?Python UploadFileForm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UploadFileForm类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _upload_file
def _upload_file(request):
"""
Handles file uploaded by HDFSfileUploadHandler.
The uploaded file is stored in HDFS at its destination with a .tmp suffix.
We just need to rename it to the destination path.
"""
form = UploadFileForm(request.POST, request.FILES)
response = {'status': -1, 'data': ''}
if request.META.get('upload_failed'):
raise PopupException(request.META.get('upload_failed'))
if form.is_valid():
uploaded_file = request.FILES['hdfs_file']
dest = form.cleaned_data['dest']
if request.fs.isdir(dest) and posixpath.sep in uploaded_file.name:
raise PopupException(_('Sorry, no "%(sep)s" in the filename %(name)s.' % {'sep': posixpath.sep, 'name': uploaded_file.name}))
dest = request.fs.join(dest, uploaded_file.name)
tmp_file = uploaded_file.get_temp_path()
username = request.user.username
try:
# Remove tmp suffix of the file
request.fs.do_as_user(username, request.fs.rename, tmp_file, dest)
response['status'] = 0
except IOError, ex:
already_exists = False
try:
already_exists = request.fs.exists(dest)
except Exception:
pass
if already_exists:
msg = _('Destination %(name)s already exists.') % {'name': dest}
else:
msg = _('Copy to %(name)s failed: %(error)s') % {'name': dest, 'error': ex}
raise PopupException(msg)
response.update({
'path': dest,
'result': _massage_stats(request, request.fs.stats(dest)),
'next': request.GET.get("next")
})
return response
示例2: _upload_file
def _upload_file(request):
"""
Handles file uploaded by HDFSfileUploadHandler.
The uploaded file is stored in HDFS. We just need to rename it to the destination path.
"""
form = UploadFileForm(request.POST, request.FILES)
if form.is_valid():
uploaded_file = request.FILES['hdfs_file']
dest = form.cleaned_data['dest']
if request.fs.isdir(dest) and posixpath.sep in uploaded_file.name:
raise PopupException(_('Sorry, no "%(sep)s" in the filename %(name)s.' % {'sep': posixpath.sep, 'name': uploaded_file.name}))
dest = request.fs.join(dest, uploaded_file.name)
tmp_file = uploaded_file.get_temp_path()
username = request.user.username
try:
# Temp file is created by superuser. Chown the file.
request.fs.do_as_superuser(request.fs.chmod, tmp_file, 0644)
request.fs.do_as_superuser(request.fs.chown, tmp_file, username, username)
# Move the file to where it belongs
request.fs.rename(tmp_file, dest)
except IOError, ex:
already_exists = False
try:
already_exists = request.fs.exists(dest)
except Exception:
pass
if already_exists:
msg = _('Destination %(name)s already exists.') % {'name': dest}
else:
msg = _('Copy to %(name)s failed: %(error)s') % {'name': dest, 'error': ex}
raise PopupException(msg)
return {
'status': 0,
'path': dest,
'result': _massage_stats(request, request.fs.stats(dest)),
'next': request.GET.get("next")
}