当前位置: 首页>>代码示例>>Python>>正文


Python forms.UploadFileForm类代码示例

本文整理汇总了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
开发者ID:atupal,项目名称:hue,代码行数:47,代码来源:views.py

示例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")
          }
开发者ID:mobilipia,项目名称:hue,代码行数:43,代码来源:views.py


注:本文中的filebrowser.forms.UploadFileForm类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。