本文整理汇总了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