Python django.conf.settings 模块,MAX_UPLOAD_SIZE 实例源码

我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用django.conf.settings.MAX_UPLOAD_SIZE

项目:Django-Fileserver    作者:brijshah    | 项目源码 | 文件源码
def put(self, request, format=None):
        """
        Return 200 if file is saved successfully
        """
        file = request.FILES['file']

        # Check if file is greater than max upload size
        if file._size > settings.MAX_UPLOAD_SIZE:
            return Response("File too large", status=status.HTTP_400_BAD_REQUEST)

        # Add the user information to our serializer
        request.data['user'] = request.user.id
        serializer = FileSerializer(data=request.data)

        if serializer.is_valid():
           serializer.save()
           return Response(serializer.data, status=status.HTTP_201_CREATED)
        return Response(status=status.HTTP_400_BAD_REQUEST)
项目:Kiwi    作者:kiwitcms    | 项目源码 | 文件源码
def attachment(request, plan_id, template_name='plan/attachment.html'):
    '''Manage attached files'''
    SUB_MODULE_NAME = 'plans'

    file_size_limit = settings.MAX_UPLOAD_SIZE
    limit_readable = int(file_size_limit) / 2 ** 20  # Mb

    tp = get_object_or_404(TestPlan, plan_id=plan_id)
    context_data = {
        'module': MODULE_NAME,
        'sub_module': SUB_MODULE_NAME,
        'test_plan': tp,
        'limit': file_size_limit,
        'limit_readable': str(limit_readable) + "Mb",
    }
    return render(request, template_name, context_data)
项目:Kiwi    作者:kiwitcms    | 项目源码 | 文件源码
def attachment(request, case_id, template_name='case/attachment.html'):
    """Manage test case attachments"""
    SUB_MODULE_NAME = 'cases'

    file_size_limit = settings.MAX_UPLOAD_SIZE
    limit_readable = int(file_size_limit) / 2 ** 20  # Mb

    tc = get_object_or_404(TestCase, case_id=case_id)
    tp = plan_from_request_or_none(request)

    context_data = {
        'module': request.GET.get('from_plan') and 'testplans' or MODULE_NAME,
        'sub_module': SUB_MODULE_NAME,
        'testplan': tp,
        'testcase': tc,
        'limit': file_size_limit,
        'limit_readable': str(limit_readable) + "Mb",
    }
    return render(request, template_name, context_data)
项目:registration    作者:HackAssistant    | 项目源码 | 文件源码
def clean_receipt(self):
        receipt = self.cleaned_data['receipt']
        size = getattr(receipt, '_size', 0)
        if size > settings.MAX_UPLOAD_SIZE:
            raise forms.ValidationError("Please keep resume under %s. Current filesize %s" % (
                filesizeformat(settings.MAX_UPLOAD_SIZE), filesizeformat(size)))
        return receipt
项目:registration    作者:HackAssistant    | 项目源码 | 文件源码
def clean_resume(self):
        resume = self.cleaned_data['resume']
        size = getattr(resume, '_size', 0)
        if size > settings.MAX_UPLOAD_SIZE:
            raise forms.ValidationError("Please keep resume size under %s. Current filesize %s" % (
                filesizeformat(settings.MAX_UPLOAD_SIZE), filesizeformat(size)))
        return resume
项目:mes    作者:osess    | 项目源码 | 文件源码
def yt_file_save(file, obj, display_name, path): 
    if file is not None:
        name = file.name
        content = file.read()
        file_type = magic.from_buffer(content)
        size = len(content)
        if size > int(settings.MAX_UPLOAD_SIZE):
            #TODO
            raise forms.ValidationError('Please keep filesize under %s.' % settings.MAX_UPLOAD_SIZE)

        imgtag = 0
        if "image" in file_type:
            imgtag = 1
        #use to technology, modify by xxd
        from django.contrib.contenttypes.models import ContentType
        if ContentType.objects.get_for_model(obj).model in ['technology']:
           imgtag = 0

        if display_name is None:
            display_name = name.split('.')[0]
        # if "T_" in file.name or "P_" in file.name:
        #     file = File(
        #         name = file.name,
        #         data = get_prep_value_encrypt(content,encryption_header_notin_field),#to see custom_fields.encrypt
        #         imgtag = imgtag,
        #         type = file_type,
        #         size = size,
        #         file = obj,
        #         display_name = display_name,
        #         path = path
        #     )
        #     file.save()
        # else:
        file = FileDirectory(
            name = file.name,
            data = file,
            imgtag = imgtag,
            type = file_type,
            size = size,
            file = obj,
            display_name = display_name,
            path = path
        )
        file.save()

        return 0

    return 1