forms.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:ecs 作者: ecs-org 项目源码 文件源码
def clean_file(self):
        pdf = self.cleaned_data['file']
        if not pdf:
            raise ValidationError(_('no file'))

        # pdf magic check
        if pdf.read(4) != PDF_MAGIC:
            raise ValidationError(_('This file is not a PDF document.'))
        pdf.seek(0)

        # sanitization
        try:
            f = decrypt_pdf(pdf)
        except ValueError:
            raise ValidationError(_('The PDF-File seems to broken. For more Information click on the question mark in the sidebar.'))

        f.seek(0)
        return UploadedFile(f, content_type='application/pdf', name='upload.pdf')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号