Пример #1
0
def suggest_movie(request):
    if (request.user.is_authenticated):
        movie_id = Movie.objects.get(id=request.POST.get('movie_id'))
        user_id_to = User.objects.get(id=request.POST.get('friend'))
        user_id_from = request.user

        if (Notification.objects.filter(movie_id = movie_id, user1 = user_id_from, user2 = user_id_to).exists()):
            messages.error(request, 'You already suggested this movie to this user')
        else:
            movie_genre = movie_id.gerne_ids.all()
            movie_genres = []
            for genre in movie_genre:
                movie_genres.append(genre.name)
            
            user_to_genres = get_profile_genre(user_id=user_id_to.id)

            print("Friend's genres", user_to_genres)
            print("Movie's genres", movie_genres)
            # ['action', 'adventure', 'animation', 'crime', 'horror', 'sci-fi', 'mystery']

            add_notification_flag = False
            for genre in movie_genres:
                if (genre in user_to_genres):
                    add_notification_flag = True

            if (add_notification_flag):
                notification = Notification(movie_id = movie_id, user1 = user_id_from, user2 = user_id_to)
                notification.save();
                messages.success(request, 'Suggested successfully.')
            else:
                messages.error(request, "Your friend usualy doesn't like movies with this type of genre.")

    return redirect('movie', movie_id = request.POST.get('movie_id'))
Пример #2
0
def viewcontact(request,pg_id):
    message="Clicked your pg details"
    userdetails=request.user
    not_object= Notification(message_not=message,mysub_id=pg_id,user=userdetails)
    not_object.save()
    
    return HttpResponse("Successfull")
    notification.send(recipients, 'new_comment', context)
 def post(self, request, *args, **kwargs):
     success = False
     if request.user.is_authenticated and 'notification_id' in request.data:
         notification_id = request.data['notification_id']
         success = Notification.remove_notification(request.user,
                                                    notification_id)
     return Response({
         "success": success,
     })
Пример #4
0
def deny(request, post_id):
    if request.method == 'POST':
        if request.user.is_staff:
            if request.POST['moderation_comments']:
                post_to_deny = get_object_or_404(Post, pk=post_id)
                post_to_deny.is_denied = True
                post_to_deny.moderation_comments = request.POST[
                    'moderation_comments']
                post_to_deny.save()
                notify_author = Notification()
                notify_author.user_to_notify = post_to_deny.author
                notify_author.content = '''Your post titled <a href="\posts\\''' + str(
                    post_to_deny.id
                ) + '''">''' + post_to_deny.title + '''</a> has been denied by astroblog moderation. Visit the post to view moderation comments.'''
                notify_author.save()
                posts_to_approve = Post.objects.filter(
                    is_approved=False).order_by('-dateandtime')
                return render(
                    request, 'blog/approvals.html', {
                        'posts': posts_to_approve,
                        'denied_post': post_to_deny,
                        'notification_count': get_notify_count(request.user)
                    })
            else:
                return render(
                    request, 'blog/approvals.html', {
                        'posts': posts_to_approve,
                        'denied_error': post_to_deny,
                        'notification_count': get_notify_count(request.user)
                    })
Пример #5
0
def delete(request, post_id):
    if request.method == 'POST':
        post = get_object_or_404(Post, pk=post_id)
        if request.user.id == post.author.id:
            notify_author = Notification()
            notify_author.user_to_notify = post.author
            notify_author.content = '''Your post titled <a href="\posts\\''' + str(
                post.id
            ) + '''">''' + post.title + '''</a> has been deleted by you.'''
            notify_author.save()
            post.delete()
            return redirect('index')
        else:
            return redirect('unauthorized')
Пример #6
0
def star(request, post_id):
    if request.method == 'POST':
        post = get_object_or_404(Post, pk=post_id)
        if request.user.username != post.author.username:
            post.totalstars += 1
            notify_author = Notification()
            notify_author.user_to_notify = post.author
            notify_author.content = '''<a href="/user/''' + str(
                request.user.id
            ) + '''">''' + request.user.username + '''</a> starred the post "<a href="\posts\\''' + str(
                post_id
            ) + '''">''' + post.title + '''</a>"'''  ################ (This is done lol) USSSSSSSSSSSSERRRRRRRRRRRRRRRR PAGGGGGGGGGGGGGE FOR STARRING NOTIFY
            notify_author.save()
            post.starredby.add(request.user)
            post.save()
        return redirect('blogpost', post_id)
Пример #7
0
def keep(request, post_id):
    if request.method == 'POST':
        post = get_object_or_404(Post, pk=post_id)
        if request.user.username != post.author.username:
            notify_author = Notification()
            notify_author.user_to_notify = post.author
            notify_author.content = '''<a href="/user/''' + str(
                request.user.id
            ) + '''">''' + request.user.username + '''</a> kept the post "<a href="\posts\\''' + str(
                post_id
            ) + '''">''' + post.title + '''</a>"'''  ################ (This is done lol) USSSSSSSSSSSSERRRRRRRRRRRRRRRR PAGGGGGGGGGGGGGE FOR STARRING NOTIFY
            notify_author.save()
            keep = Keep()
            keep.blog_post = post
            keep.keep_user = request.user
            keep.save()
        return redirect('blogpost', post_id)
Пример #8
0
def approve(request, post_id):
    if request.method == 'POST':
        if request.user.is_staff:
            post_to_approve = get_object_or_404(Post, pk=post_id)
            post_to_approve.is_approved = True
            post_to_approve.save()
            notify_author = Notification()
            notify_author.user_to_notify = post_to_approve.author
            notify_author.content = '''Your post titled <a href="\posts\\''' + str(
                post_to_approve.id
            ) + '''">''' + post_to_approve.title + '''</a> has been approved by astroblog moderation.'''
            notify_author.save()
            posts_to_approve = Post.objects.filter(
                is_approved=False).order_by('-dateandtime')
            return render(
                request, 'blog/approvals.html', {
                    'posts': posts_to_approve,
                    'approved_post': post_to_approve,
                    'notification_count': get_notify_count(request.user)
                })
        else:
            return redirect('unauthorized')
Пример #9
0
 def handle(self, *args, **options):
     while True:
         Notification.perform_sends()
         time.sleep(2)