def post(self, request, *args, **kwargs): #print(request.POST) movie = Movie.objects.get(pk=request.POST.get("movie_pk")) title = request.POST.get("title") body = request.POST.get("body") rating = request.POST.get("rating") author = self.request.user review = Review.create(movie=movie, title=title, body=body, author=author, rating=rating) review.save() notification = Notification.create(title="New review for ", movie=movie, inside=review) notification.save() all_followers = movie.all_followers() for follower in all_followers: if (notification not in follower.notifications.all()): follower.notifications.add(notification) if (follower.chat_id): telegram_bot_sendtext( follower.chat_id, "New review for " + notification.movie_title + " with title " + notification.inside_title, "https://empire-of-movies.herokuapp.com" + notification.inside_link) return redirect(review)
def _method_name(self, event): bot.telegram_bot_sendtext("Path name: " + event.pathname + ".\n Event Name: " + event.maskname + ".") print("Method name: process_{}()\n" "Path name: {}\n" "Event Name: {}\n".format(method, event.pathname, event.maskname))
def post(self, request, *args, **kwargs): #print(request.POST) current_movie = Movie.objects.get(pk=self.kwargs.get('movie_pk')) title = request.POST.get('title') body = request.POST.get('body') rating = request.POST.get('rating') author = self.request.user new_review = Review.create(movie=current_movie, title=title, body=body, rating=rating, author=author) new_review.save() reviews = Movie.objects.get( pk=self.kwargs.get('movie_pk')).review.all() sum = 0 total = 0 reviewer = [] for review in reviews: author = review.author if author in reviewer: pass else: current_author_review = Review.objects.filter( author=author).filter(movie=current_movie) current_sum = 0 current_total = 0 for current in current_author_review: current_sum += current.rating current_total += 1 sum += current_sum / current_total total += 1 reviewer.append(author) if (total == 0): current_movie.website_rating = None current_movie.save() else: current_movie.website_rating = round(sum / total, 1) current_movie.save() all_followers = current_movie.all_followers() title = "New review for" # print(new_review.get_absolute_url()) notification = Notification.create(title=title, movie=current_movie, inside=new_review) notification.save() for follower in all_followers: if (notification not in follower.notifications.all()): follower.notifications.add(notification) if (follower.chat_id): telegram_bot_sendtext( follower.chat_id, "New review for " + notification.movie_title + " with title " + notification.inside_title, "https://empire-of-movies.herokuapp.com" + notification.inside_link) return redirect(new_review)
def post(self, request, *args, **kwargs): #print(request.POST) super().post(request, *args, **kwargs) current_movie = Movie.objects.get(pk=self.kwargs.get('movie_pk')) all_followers = current_movie.all_followers() title = "New discussion for" # print(self.object.get_absolute_url()) notification = Notification.create(title=title, movie=current_movie, inside=self.object) notification.save() for follower in all_followers: if (notification not in follower.notifications.all()): follower.notifications.add(notification) if (follower.chat_id): telegram_bot_sendtext( follower.chat_id, "New discussion for " + notification.movie_title + " with title " + notification.inside_title, "https://empire-of-movies.herokuapp.com" + notification.inside_link) return redirect(self.object)