def get(self, request, addon, version_string, uuid=None, guid=None): file_upload_qs = FileUpload.objects.filter(addon=addon, version=version_string) try: if uuid is None: file_upload = file_upload_qs.latest() log.info('getting latest upload for {addon} {version}: ' '{file_upload.uuid}'.format(addon=addon, version=version_string, file_upload=file_upload)) else: file_upload = file_upload_qs.get(uuid=uuid) log.info('getting specific upload for {addon} {version} ' '{uuid}: {file_upload.uuid}'.format( addon=addon, version=version_string, uuid=uuid, file_upload=file_upload)) except FileUpload.DoesNotExist: msg = ugettext('No uploaded file for that addon and version.') return Response({'error': msg}, status=status.HTTP_404_NOT_FOUND) try: version = addon.versions.filter(version=version_string).latest() except Version.DoesNotExist: version = None serializer = FileUploadSerializer(file_upload, version=version) return Response(serializer.data)
def post(self, request, *args, **kwargs): version_string = request.data.get('version', None) try: file_upload, _ = self.handle_upload(request, None, version_string) except forms.ValidationError as exc: return Response({'error': exc.message}, status=exc.code or status.HTTP_400_BAD_REQUEST) return Response(FileUploadSerializer(file_upload).data, status=status.HTTP_201_CREATED)
def put(self, request, addon, version_string, guid=None): try: file_upload, created = self.handle_upload(request, addon, version_string) except forms.ValidationError as exc: return Response({'error': exc.message}, status=exc.code) status_code = (status.HTTP_201_CREATED if created else status.HTTP_202_ACCEPTED) return Response(FileUploadSerializer(file_upload).data, status=status_code)
def put(self, request, addon, version_string, guid=None): try: file_upload, created = self.handle_upload(request, addon, version_string, guid=guid) except forms.ValidationError as exc: return Response({'error': exc.message}, status=exc.code or status.HTTP_400_BAD_REQUEST) status_code = status.HTTP_201_CREATED if created else status.HTTP_202_ACCEPTED serializer = FileUploadSerializer(file_upload, context={'request': request}) return Response(serializer.data, status=status_code)
def put(self, request, addon, version_string): if 'upload' in request.FILES: filedata = request.FILES['upload'] else: return Response( {'error': _('Missing "upload" key in multipart file data.')}, status=status.HTTP_400_BAD_REQUEST) try: # Parse the file to get and validate package data with the addon. pkg = parse_addon(filedata, addon) if not acl.submission_allowed(request.user, pkg): raise forms.ValidationError( _(u'You cannot submit this type of add-on')) except forms.ValidationError as e: return Response({'error': e.message}, status=status.HTTP_400_BAD_REQUEST) if pkg['version'] != version_string: return Response( {'error': _('Version does not match the manifest file.')}, status=status.HTTP_400_BAD_REQUEST) elif (addon is not None and addon.versions.filter(version=version_string).exists()): return Response({'error': _('Version already exists.')}, status=status.HTTP_409_CONFLICT) if addon is None: addon = Addon.create_addon_from_upload_data(data=pkg, user=request.user, is_listed=False) status_code = status.HTTP_201_CREATED else: status_code = status.HTTP_202_ACCEPTED file_upload = handle_upload(filedata=filedata, user=request.user, addon=addon, submit=True) return Response(FileUploadSerializer(file_upload).data, status=status_code)