本文整理汇总了Python中media_tree.models.FileNode.parent方法的典型用法代码示例。如果您正苦于以下问题:Python FileNode.parent方法的具体用法?Python FileNode.parent怎么用?Python FileNode.parent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类media_tree.models.FileNode
的用法示例。
在下文中一共展示了FileNode.parent方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: upload_file_view
# 需要导入模块: from media_tree.models import FileNode [as 别名]
# 或者: from media_tree.models.FileNode import parent [as 别名]
def upload_file_view(self, request):
self.init_parent_folder(request)
if not self.has_add_permission(request):
raise PermissionDenied
if request.method == 'POST':
form = UploadForm(request.POST, request.FILES)
if form.is_valid():
node = FileNode(file=form.cleaned_data['file'], node_type=FileNode.FILE)
parent_folder = self.get_parent_folder(request)
if not parent_folder.is_top_node():
node.parent = parent_folder
self.save_model(request, node, None, False)
# Respond with 'ok' for the client to verify that the upload was successful, since sometimes a failed
# request would not result in a HTTP error and look like a successful upload.
# For instance: When requesting the admin view without authentication, there is a redirect to the
# login form, which to SWFUpload looks like a successful upload request.
if request.is_ajax() or 'Adobe Flash' in request.META.get('HTTP_USER_AGENT', ''):
return HttpResponse("ok", mimetype="text/plain")
else:
messages.info(request, _('Successfully uploaded file %s.') % node.name)
return HttpResponseRedirect(reverse('admin:media_tree_filenode_changelist'))
else:
if not settings.DEBUG:
raise ValidationError
return
if not settings.DEBUG:
raise ViewDoesNotExist
else:
# Form is rendered for troubleshooting SWFUpload. If this form works, the problem is not server-side.
from django.template import Template, RequestContext
if request.method != 'POST':
form = UploadForm()
return render_to_response('admin/media_tree/filenode/upload_form.html',
{'form': form, 'node': self.get_parent_folder(request)}, context_instance=RequestContext(request))
示例2: upload_file_view
# 需要导入模块: from media_tree.models import FileNode [as 别名]
# 或者: from media_tree.models.FileNode import parent [as 别名]
def upload_file_view(self, request):
try:
if not self.has_add_permission(request):
raise PermissionDenied
FILE_PARAM_NAME = 'qqfile'
self.init_parent_folder(request)
if request.method == 'POST':
if request.is_ajax() and request.GET.get(FILE_PARAM_NAME, None):
from django.core.files.base import ContentFile
from django.core.files.uploadedfile import UploadedFile
content_file = ContentFile(request.raw_post_data)
uploaded_file = UploadedFile(content_file, request.GET.get(FILE_PARAM_NAME), None, content_file.size)
form = UploadForm(request.POST, {'file': uploaded_file})
else:
form = UploadForm(request.POST, request.FILES)
if form.is_valid():
node = FileNode(file=form.cleaned_data['file'], node_type=FileNode.FILE)
parent_folder = self.get_parent_folder(request)
if not parent_folder.is_top_node():
node.parent = parent_folder
self.save_model(request, node, None, False)
# Respond with 'ok' for the client to verify that the upload was successful, since sometimes a failed
# request would not result in a HTTP error and look like a successful upload.
# For instance: When requesting the admin view without authentication, there is a redirect to the
# login form, which to SWFUpload looks like a successful upload request.
if request.is_ajax():
return HttpResponse('{"success": true}', mimetype="application/json")
else:
messages.info(request, _('Successfully uploaded file %s.') % node.name)
return HttpResponseRedirect(reverse('admin:media_tree_filenode_changelist'))
else:
# invalid form data
if request.is_ajax():
return HttpResponse('{"error": "%s"}' % ' '.join(
[item for sublist in form.errors.values() for item in sublist]),
mimetype="application/json")
# Form is rendered for troubleshooting SWFUpload. If this form works, the problem is not server-side.
if not settings.DEBUG:
raise ViewDoesNotExist
if request.method == 'GET':
form = UploadForm()
return render_to_response('admin/media_tree/filenode/upload_form.html', {'form': form})
except Exception as e:
if request.is_ajax():
return HttpResponse('{"error": "%s"}' % ugettext('Server Error'),
mimetype="application/json")
else:
raise
示例3: upload_file_view
# 需要导入模块: from media_tree.models import FileNode [as 别名]
# 或者: from media_tree.models.FileNode import parent [as 别名]
def upload_file_view(self, request):
try:
if not self.has_add_permission(request):
raise PermissionDenied
self.init_parent_folder(request)
if request.method == 'POST':
form = UploadForm(request.POST, request.FILES)
if form.is_valid():
node = FileNode(file=form.cleaned_data['file'], node_type=FileNode.FILE)
parent_folder = self.get_parent_folder(request)
if not parent_folder.is_top_node():
node.parent = parent_folder
self.save_model(request, node, None, False)
# Respond with success
if request.is_ajax():
return HttpResponse('{"success": true}', mimetype="application/json")
else:
messages.info(request, _('Successfully uploaded file %s.') % node.name)
return HttpResponseRedirect(reverse('admin:media_tree_filenode_changelist'))
else:
# invalid form data
if request.is_ajax():
return HttpResponse('{"error": "%s"}' % ' '.join(
[item for sublist in form.errors.values() for item in sublist]),
mimetype="application/json")
# Form is rendered for troubleshooting XHR upload.
# If this form works, the problem is not server-side.
if not settings.DEBUG:
raise ViewDoesNotExist
if request.method == 'GET':
form = UploadForm()
return render_to_response('admin/media_tree/filenode/upload_form.html', {'form': form},
context_instance=RequestContext(request))
except Exception as e:
if request.is_ajax():
return HttpResponse('{"error": "%s"}' % ugettext('Server Error'),
mimetype="application/json")
else:
raise