當前位置: 首頁>>代碼示例>>Python>>正文


Python FileNode.parent方法代碼示例

本文整理匯總了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))
開發者ID:cyber778,項目名稱:django-media-tree,代碼行數:36,代碼來源:filenode_admin.py

示例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
開發者ID:quinode,項目名稱:django-media-tree,代碼行數:56,代碼來源:filenode_admin.py

示例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
開發者ID:datakortet,項目名稱:django-media-tree,代碼行數:45,代碼來源:filenode_admin.py


注:本文中的media_tree.models.FileNode.parent方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。