@transaction.atomic
    def post(self, request, *args, **kwargs):
        email = request.FILES.get('email')
        api_key = request.FILES.get('api_key')
        version = request.FILES.get('version')
        platform = request.FILES.get('platform')
        arch = request.FILES.get('arch')
        package_file = request.FILES.get('package')
        package_size = None

        if email:
            email = email.read()
        if api_key:
            api_key = api_key.read()
        if version:
            version = version.read()
        if platform:
            platform = platform.read()
        if arch:
            arch = arch.read()
        if package_file:
            package_size = package_file.seek(0, 2)
        if not email or not api_key or not package_size or not version:
            message = {'success': False, 'errors': []}
            if not email:
                message['errors'].append('Email is mandatory.')
            if not api_key:
                message['errors'].append('API key is mandatory.')
            if not version:
                message['errors'].append('Version is mandatory.')
            if not package_size:
                message['errors'].append('Package is mandatory.')
            return HttpResponseBadRequest(json.dumps(message))

        member = self.get_member(email, api_key)
        if member is None:
            return HttpResponseForbidden(
                json.dumps({'success': False, 'errors': ['Bad credentials.']}))
        if not member.is_active:
            return HttpResponseForbidden(
                json.dumps(
                    {'success': False, 'errors': ['Account not active.']}))

        try:
            version = int(version)
        except ValueError:
            return HttpResponseBadRequest(json.dumps({
                'success': False,
                'errors': ['Bad version. Must be 2 or 3.']}))

        if version not in [2, 3]:
            return HttpResponseBadRequest(json.dumps({
                'success': False,
                'errors': ['Bad version. Must be 2 or 3.']}))

        package = Package(
            member=member,
            version=version,
            platform=platform,
            arch=arch,
            package=package_file)

        try:
            package.full_clean()
        except ValidationError as err:
            return HttpResponseBadRequest(
                json.dumps({'success': False, 'errors': err.messages}))

        package.save()
        # Cleanup old packages
        old_packages = member.package_set.filter(
            version=version).exclude(pk=package.pk)
        for old_package in old_packages:
            old_package.delete()
        return HttpResponse(json.dumps({'success': True}), status=201)
dataset/ETHPy150Open socketubs/sublimall-server/sublimall/storage/views.py/UploadPackageAPIView.post/original