#NEWLINE# @ handle_read_only_mode #NEWLINE# @ with_addon ( allow_missing = True ) #NEWLINE# def put( self , request , addon , version_string ) : #NEWLINE# #INDENT# if ( 'upload' in request . FILES ) : #NEWLINE# #INDENT# filedata = request . FILES [ 'upload' ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return Response ( { #NEWLINE# #INDENT# 'error' : _ ( 'Missing "upload" key in multipart file data.' ) , #NEWLINE# #UNINDENT# } , status = status . HTTP_400_BAD_REQUEST ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# pkg = parse_addon ( filedata , addon ) #NEWLINE# if ( not acl . submission_allowed ( e . user , pkg ) ) : #NEWLINE# #INDENT# raise forms . ValidationError ( _ ( 'You cannot submit this type of add-on' ) ) #NEWLINE# #UNINDENT# #UNINDENT# except forms . ValidationError as e : #NEWLINE# #INDENT# return Response ( { #NEWLINE# #INDENT# 'error' : e . message , #NEWLINE# #UNINDENT# } , status = status . HTTP_400_BAD_REQUEST ) #NEWLINE# #UNINDENT# if ( pkg [ 'version' ] != version_string ) : #NEWLINE# #INDENT# return Response ( { #NEWLINE# #INDENT# 'error' : _ ( 'Version does not match the manifest file.' ) , #NEWLINE# #UNINDENT# } , status = status . HTTP_400_BAD_REQUEST ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( addon is not None ) and addon . versions . filter ( version = version_string ) . exists ( ) ) : #NEWLINE# #INDENT# return Response ( { #NEWLINE# #INDENT# 'error' : _ ( 'Version already exists.' ) , #NEWLINE# #UNINDENT# } , status = status . HTTP_409_CONFLICT ) #NEWLINE# #UNINDENT# #UNINDENT# if ( addon is None ) : #NEWLINE# #INDENT# addon = Addon . create_addon_from_upload_data ( data = pkg , user = request . user , is_listed = False ) #NEWLINE# status_code = status . HTTP_201_CREATED #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# status_code = status . HTTP_202_ACCEPTED #NEWLINE# #UNINDENT# file_upload = handle_upload ( filedata = filedata , user = request . user , addon = addon , submit = True ) #NEWLINE# return Response ( FileUploadSerializer ( file_upload ) . data , status = status_code )