#NEWLINE# @ handle_exceptions_for_ajax #NEWLINE# def post( self , request , project_id ) : #NEWLINE# #INDENT# '\n        Adds a new contribution to a project\n\n        Parameters\n        ----------\n        request : rest_framework.request.Request\n            Represents the request\n        project_id : int\n            identifies the project in the data base\n\n        Returns\n        -------\n        rest_framework.response.Respone\n            Contains the serialised contribution\n        ' #NEWLINE# user = request . user #NEWLINE# if user . is_anonymous ( ) : #NEWLINE# #INDENT# user = User . objects . get ( display_name = 'AnonymousUser' ) #NEWLINE# #UNINDENT# data = request . data #NEWLINE# project = Project . objects . as_contributor ( project . user , project_id ) #NEWLINE# if ( ( not ( data . get ( 'meta' ) . get ( 'status' ) == 'draft' ) ) and project . can_moderate ( user ) ) : #NEWLINE# #INDENT# data [ 'meta' ] [ 'status' ] = 'active' #NEWLINE# #UNINDENT# serializer = ContributionSerializer ( data = data , context = { #NEWLINE# #INDENT# 'user' : user , #NEWLINE# 'project' : project , #NEWLINE# #UNINDENT# } ) #NEWLINE# if serializer . is_valid ( raise_exception = True ) : #NEWLINE# #INDENT# serializer . save ( ) #NEWLINE# return Response ( serializer . data , status = status . HTTP_201_CREATED )