Exemple #1
0
 def post(self, request, tablature_id):
     '''
     Post a comment to tablature by id.
     Requires authorization.
     Returns 400 on bad request.
     '''
     if not request.DATA:
         error = ErrorModel('The artist_id, song_id and the body of the tablature\
                            cannot be empty').serialize()
         return Response(error, status=status.HTTP_400_BAD_REQUEST)
     
     if not database.contains_tablature(tablature_id):
         error = ErrorModel('Tablature was not found.').serialize()
         return Response(error, status=status.HTTP_404_NOT_FOUND)
     
     commentmodel = None
     try:
         commentmodel = CommentModel(None, raw_data=request.DATA)
         user_nickname = commentmodel.user_nickname
         commentmodel.tablature_id = tablature_id
     except Exception as e:
         print "Could not add the data "+ str(e)
         traceback.print_exc()
         return Response(status = 400)
         
     authorization = ''
     try:
         authorization = request.user.username #request.META["HTTP_AUTHORIZATION"]
         try:
             if sys.argv[1] == "test":
                 authorization = request.META["HTTP_AUTHORIZATION"]
         except IndexError:
             pass
     except KeyError:
         pass
     if self._isauthorized(user_nickname, authorization):
         return self._createcomment(commentmodel, request) 
     else:
         return Response(status=status.HTTP_401_UNAUTHORIZED)
Exemple #2
0
 def post(self, request, tablature_id, comment_id):
     '''
     Post reply to an existing comment.
     '''
     #request.DATA contains the request body already deserialized in
     #a python dictionary
     if not request.DATA:
         error = ErrorModel('The body of the comment\
                            cannot be empty').serialize()
         return Response(error, status=status.HTTP_400_BAD_REQUEST)
     if not database.contains_comment(comment_id):
         error = ErrorModel("The comment "+comment_id+
                            " is not in the archive").serialize()
         return Response(error, status=status.HTTP_404_NOT_FOUND)
     commentmodel = None
     
     try:
         commentmodel = CommentModel('', raw_data=request.DATA)
     except Exception as e:
         print "Could not add the data "+ str(e)
         traceback.print_exc()
         return Response(status = 400)
     commentmodel.reply_to = comment_id 
     commentmodel.tablature_id = tablature_id
     
     authorization = ''
     try:
         authorization = request.user.username #request.META["HTTP_AUTHORIZATION"]
         try:
             if sys.argv[1] == "test":
                 authorization = request.META["HTTP_AUTHORIZATION"]
         except IndexError:
             pass
     except KeyError:
         pass
     if self._isauthorized(commentmodel.user_nickname, authorization):
         return self._createreply(commentmodel, request) 
     else:
         return Response(status=status.HTTP_401_UNAUTHORIZED)