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


Python UploadedFile.skip_validation方法代码示例

本文整理汇总了Python中django.core.files.uploadedfile.UploadedFile.skip_validation方法的典型用法代码示例。如果您正苦于以下问题:Python UploadedFile.skip_validation方法的具体用法?Python UploadedFile.skip_validation怎么用?Python UploadedFile.skip_validation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.core.files.uploadedfile.UploadedFile的用法示例。


在下文中一共展示了UploadedFile.skip_validation方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_form

# 需要导入模块: from django.core.files.uploadedfile import UploadedFile [as 别名]
# 或者: from django.core.files.uploadedfile.UploadedFile import skip_validation [as 别名]
def get_form(request, form_class, field_order, bound=False):
    """
    Generic function. Used for all submission types. Specify the ``form_class``
    that's given in ``forms.py``. The ``field_order`` is a list of strings that
    indicates the linear order of the fields in the form. A ``bound`` form
    is a function of the object assigned to ``bound`` (see below). An unbound
    form is simply an empty form.
    """
    if bound:
        if isinstance(bound, models.Revision):
            tags = ','.join([str(tag) for tag in bound.tags.all()])
            fields =  {'item_url': bound.item_url,
                       'title': bound.title,
                       'description': bound.description,
                       'sub_tags': tags,
                       'snippet_code': bound.item_code,
                       'sub_type': 'snippet',
                       'sub_license': bound.sub_license_id,
                       }
            if bound.entry.sub_type == 'link':
                fields['sub_type'] = 'link'
            elif bound.entry.sub_type == 'package':
                fields['sub_type'] = 'package'
            elif  bound.entry.sub_type == 'code':
                fields['sub_type'] = 'snippet'

            form_output = form_class(fields)
        else:
            if request.POST['sub_type'] == 'package':
                # Create a fake "UploadedFile" object, so the user can resume
                # editing or finish their submission, without being told
                # they have to reenter this field.
                zip_hash = request.POST.get('package_hash', '')
                zip_file = models.ZipFile.objects.filter(zip_hash=zip_hash)
                if zip_file:
                    zip_name = zip_file[0].raw_zip_file.name
                    uploaded_file = UploadedFile(zip_name, name=zip_name,
                                        content_type='application/zip',
                                        size=zip_file[0].raw_zip_file.size)
                    uploaded_file.skip_validation = True # see ``forms.py``
                    request.FILES['package_file'] = uploaded_file
            form_output = form_class(request.POST, request.FILES)

            if request.POST['sub_type'] == 'package' and zip_file:
                form_output.fields['package_file'].initial = uploaded_file

    else:
        form_output = form_class()

    # Rearrange the form order
    form_output.fields.keyOrder = field_order
    index = 1
    for field_name, field in form_output.fields.iteritems():
        field.widget.attrs['tabindex'] = str(index)
        index += 1

    if request.user.is_authenticated():
        # Email field not required for signed-in users
        form_output.fields.pop('email')

    return form_output
开发者ID:pv,项目名称:SciPyCentral,代码行数:63,代码来源:views.py


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