def liked(request): #print(request.data) a, b = verify_user(request.data['username']) if a == False: return Response(b) try: i = reviews.objects.filter(movie_id=request.data['movieId'], review_user_id=request.data['username']) if len(i) == 0: raise Exception for i in reviews.objects.filter( movie_id=request.data['movieId'], review_user_id=request.data['username']): i.liked = request.data['likeMovie'] i.save() response = { 'success': 'True', 'statusCode': status.HTTP_200_OK, 'message': 'likestatus updated for a new user and movie', } except Exception: e = reviews() e.movie_id = request.data['movieId'] e.review_user_id = request.data['username'] if 'likeMovie' in request.data.keys(): e.liked = request.data['likeMovie'] e.save() response = { 'success': 'True', 'statusCode': status.HTTP_200_OK, 'message': 'like added for a new user and movie', } return Response(response)
def add_rating(request): #print(request.data) try: for i in reviews.objects.filter(movie_id=request.data['movie'], review_user_id=request.data['user']): i.rating = request.data['rating'] i.save() response = { 'success': 'True', 'statusCode': status.HTTP_200_OK, 'message': 'rating updated for a new user and movie', } except Exception: e = reviews() e.movie_id = request.data['movie'] e.review_user_id = request.data['user'] if 'rating' in request.data.keys(): e.rating = request.data['rating'] e.save() response = { 'success': 'True', 'statusCode': status.HTTP_200_OK, 'message': 'rating added for a new user and movie', } return Response(response)
def add_review(request): a, b = verify_user(request.data['user']) if a == False: return Response(b) try: e = reviews() e.movie_id = request.data['movie'] e.review_user_id = request.data['user'] if 'review' in request.data.keys(): e.review = request.data['review'] if 'rating' in request.data.keys(): e.rating = request.data['rating'] e.review_date = datetime.date.today() e.review_time = datetime.datetime.now().time() e.save() response = { 'success': 'True', 'statusCode': status.HTTP_200_OK, 'message': 'Review added for a particular user and movie', } except Exception as e: print(e) for i in reviews.objects.filter(movie_id=request.data['movie'], review_user_id=request.data['user']): if 'review' in request.data.keys(): i.review = request.data['review'] if 'rating' in request.data.keys(): i.rating = request.data['rating'] i.review_date = datetime.date.today() i.review_time = datetime.datetime.now().time() i.save() response = { 'success': 'True', 'statusCode': status.HTTP_200_OK, 'message': 'Review updated', } send_notifications(request.data['user'], request.data['movie'], request.data['movieTitle']) #print(response) return Response(response)
def put(self, request, *args, **kwargs): user_profile = UserProfile.objects.get(username=request.data['username']) try: movie_review = reviews.objects.get(movie_id=request.data['movieID'] , review_user_id=request.data['username']) except Exception: movie_review = reviews() movie_review.movie_id = request.data['movieID'] movie_review.review_user_id = request.data['username'] #print('-----------------########',movie_review) if request.data['movieStatus'] and str(request.data['movieID']) not in user_profile.watched: #print('yes') user_profile.watched.append(request.data['movieID']) movie_review.watched = True movie_review.save() message = 'movie watched' elif request.data['movieStatus']==False and str(request.data['movieID']) in user_profile.watched: user_profile.watched.remove(str(request.data['movieID'])) movie_review.watched = False movie_review.save() message = 'Movie unwatched' else: response = { 'success': 'true', 'statusCode': status.HTTP_200_OK, 'message': 'doubled request', 'data': { 'watchlist':list(map(int, list(user_profile.watched)))}} return Response(response, status=status.HTTP_200_OK) user_profile.save() statusCode = status.HTTP_200_OK response = { 'success': 'true', 'statusCode': statusCode, 'message': message, 'data': { 'watchlist':list(map(int, list(user_profile.watched)))}} return Response(response, status=status.HTTP_200_OK)