def like_view(request): user = check_validation(request) if user and request.method == 'POST': form = LikeForm(request.POST) if form.is_valid(): post_id = form.cleaned_data.get('post').id puser = request.POST.get('pusername') pemail = request.POST.get('pemail') existing_like = LikeModel.objects.filter(post_id=post_id, user=user).first() if not existing_like: LikeModel.objects.create(post_id=post_id, user=user) print print pemail print puser to_email = Email(pemail) subject = "like" content = Content( "text/plain", "Hi ,\n " + " user - " + user.username + " has liked your post.") mail = Mail(from_email, subject, to_email, content) response = sg.client.mail.send.post(request_body=mail.get()) print(response.status_code) print(response.body) print(response.headers) else: existing_like.delete() return redirect('/feed/', {'drop': drop}) else: return redirect('/login/')
def like_view(request): user = check_validation(request) if user and request.method == 'POST': form = LikeForm(request.POST) if form.is_valid(): post_id = form.cleaned_data.get('post').id existing_like = LikeModel.objects.filter(post_id=post_id, user=user).first() if not existing_like: like = LikeModel.objects.create(post_id=post_id, user=user) ctypes.windll.user32.MessageBoxW(0,u"You got a new like!",u"Liked!",0) sg = sendgrid.SendGridAPIClient(apikey=(send_grid_api)) from_email = Email("*****@*****.**") to_email = Email(like.post.user.email) subject = "Welcome to Clement-Critique!" content = Content("text/plain", "You have a new like on your post!") mail = Mail(from_email, subject, to_email, content) response = sg.client.mail.send.post(request_body=mail.get()) print(response.status_code) print(response.body) print(response.headers) else: existing_like.delete() return redirect('/feed/') else: return redirect('/login/')
def like_view(request): user = check_validation(request) if user and request.method == 'POST': form = LikeForm(request.POST) if form.is_valid(): post_id = form.cleaned_data.get('post').id existing_like = LikeModel.objects.filter(post_id=post_id, user=user).first() if not existing_like: LikeModel.objects.create(post_id=post_id, user=user) # mail to the user about the new like post = form.cleaned_data.get('post') email = post.user.email sg = sendgrid.SendGridAPIClient(apikey=apikey) from_email = Email(my_email) to_email = Email(email) subject = "Swacch Bharat" content = Content("text/plain", "you have a new like") mail = Mail(from_email, subject, to_email, content) sg.client.mail.send.post(request_body=mail.get()) else: existing_like.delete() return redirect('/feed/') else: return redirect('/login/')
def like_view(request): user = check_validation(request) if user and request.method == 'POST': form = LikeForm(request.POST) if form.is_valid(): post_id = form.cleaned_data.get('post').id posts = PostModel.objects.all().order_by('-created_on') for post in posts: existing_like = PostLikeModel.objects.filter(post_id=post_id, user=user).first() if existing_like: post.has_liked = True if not existing_like: PostLikeModel.objects.create(post_id=post_id, user=user) else: existing_like.delete() return redirect('/feed/') else: return redirect('/feed/') else: return redirect('/login/')
def like_view(request): user = check_validation(request) if user and request.method == 'POST': form = LikeForm(request.POST) if form.is_valid(): post_id = form.cleaned_data.get('post').id existing_like = LikeModel.objects.filter(post_id=post_id, user=user).first() if not existing_like: LikeModel.objects.create(post_id=post_id, user=user) d=LikeModel.objects.filter(post_id=post_id,user=user).first() to=d.post.user.email subject = 'Django App ' message = "Someone just liked your post " from_email = settings.EMAIL_HOST_USER to_list = [to, settings.EMAIL_HOST_USER] send_mail(subject, message, from_email, to_list, fail_silently=True) else: existing_like.delete() return redirect('/feed/') else: return redirect('/login/')
def like_view(request): user = check_validation(request) if user and request.method == 'POST': form = LikeForm(request.POST) if form.is_valid(): post_id = form.cleaned_data.get('post').id existing_like = LikeModel.objects.filter(post_id=post_id, user=user).first() if not existing_like: like = LikeModel.objects.create(post_id=post_id, user=user) sg = sendgrid.SendGridAPIClient(apikey=(SENDGRID_API_KEY)) from_email = Email("*****@*****.**") to_email = Email(like.post.user.email) subject = "Welcome " content = Content("text/plain", "Your post has been liked!") mail = Mail(from_email, subject, to_email, content) response = sg.client.mail.send.post(request_body=mail.get()) print(response.status_code) print(response.body) print(response.headers) else: existing_like.delete() return redirect('/feed/') else: return redirect('/login/')
def like_view(request): user = check_validation(request) if user and request.method == 'POST': form = LikeForm(request.POST) if form.is_valid(): post_id = form.cleaned_data.get('post').id existing_like = LikeModel.objects.filter(post_id=post_id, user=user).first() if not existing_like: like = LikeModel.objects.create(post_id=post_id, user=user) sg = sendgrid.SendGridAPIClient(apikey=key) from_email = Email("*****@*****.**") to_email = Email(like.post.user.email) subject = "Confiramation Mail" content = Content("text/plain", "to verify provided email address") mail = Mail(from_email, subject, to_email, content) response = sg.client.mail.send.post(request_body=mail.get()) print(response.status_code) print(response.body) print(response.headers) else: existing_like.delete() return redirect('/feed/') else: return redirect('/login/')
def like_view(request): user = check_validation(request) if user and request.method == 'POST': form = LikeForm(request.POST) if form.is_valid(): post = form.cleaned_data.get('post') email = post.user.email #post_id = post existing_like = LikeModel.objects.filter(post=post, user=user).first() if not existing_like: LikeModel.objects.create(post=post, user=user) # welcome email to the user for successfully completing the sign up sg = sendgrid.SendGridAPIClient(apikey=sendgrid_api) from_email = Email("*****@*****.**") to_email = Email(email) subject = "Upload to win" content = Content("text/plain", user.name + " has liked your post") mail = Mail(from_email, subject, to_email, content) sg.client.mail.send.post(request_body=mail.get()) else: existing_like.delete() return redirect('/feed/') else: return redirect('/login/')
def like_view(request): user = check_validation(request) if user and request.method == 'POST': form = LikeForm(request.POST) if form.is_valid(): post_id = form.cleaned_data.get('post').id existing_like = LikeModel.objects.filter(post_id=post_id, user=user).first() if not existing_like: like = LikeModel.objects.create(post_id=post_id, user=user) sg = sendgrid.SendGridAPIClient(apikey=(sendgrid_key)) from_email = Email("*****@*****.**") to_email = Email(like.post.user.email) subject = "You have a new like on your post %d " % (post_id) content = Content( "text/plain", "You have a new like on your post %d /n Login to view the details" % post_id) mail = Mail(from_email, subject, to_email, content) response = sg.client.mail.send.post(request_body=mail.get()) print(response.status_code) print(response.body) print(response.headers) else: existing_like.delete() return redirect('/feed/') else: return redirect('/login/')
def like_view(request): user = check_validation(request) if user and request.method == 'POST': form = LikeForm(request.POST) if form.is_valid(): post_id = form.cleaned_data.get('post').id existing_like = LikeModel.objects.filter(post_id=post_id, user=user).first() if not existing_like: LikeModel.objects.create(post_id=post_id, user=user) else: existing_like.delete() return redirect('/feed/') else: return redirect('/login/')
def like_view(request): user_valid = check_validation(request) if user_valid and request.method == "POST": lform = LikeForm(request.POST) if lform.is_valid(): postid = lform.cleaned_data.get("post").id existing_like = LikeModel.objects.filter(post_id=postid, user=user_valid).first() if not existing_like: LikeModel.objects.create(post_id=postid, user=user_valid) else: existing_like.delete() return redirect('myapp/feed') else: return redirect('/myapp/login')
def like_view(request): user = check_validation(request) if user and request.method == 'POST': form = LikeForm(request.POST) if form.is_valid(): post_id = form.cleaned_data.get('post').id existing_like = LikeModel.objects.filter(post_id=post_id, user=user).first() if not existing_like: LikeModel.objects.create(post_id=post_id, user=user) post = PostModel.objects.filter(id=post_id).first() like_email(user.username, post.user.email) else: # If already liked, deleting the like existing_like.delete() return redirect('/feed/') else: return redirect('/login/')
def like_view(request): user = check_validation(request) if user and request.method == "POST": form = LikeForm(request.POST) if form.is_valid(): #fetching like or unlike.................................................................................... post_id = form.cleaned_data.get('post').id existing_like = LikeModel.objects.filter(post_id=post_id, user=user).first() #checking for like or unlike................................................................................ if not existing_like: LikeModel.objects.create(post_id=post_id, user=user) else: existing_like.delete() #redirecting again to feed view............................................................................. return redirect('/feed/') else: return render(request, 'feed1.html') else: return redirect('/login/')
def like_view(request): # checking whether user is logged in user = check_validation(request) if user and request.method == 'POST': form = LikeForm(request.POST) # if form is valid if form.is_valid(): # getting post id post_id = form.cleaned_data.get('post').id # checking for existing like existing_like = LikeModel.objects.filter(post_id=post_id, user=user).first() # if hasent liked before then make a like if not existing_like: LikeModel.objects.create(post_id=post_id, user=user) a = PostModel.objects.filter(id=post_id) b = a[0].user # accessing user attribute of PostModel object a c = b.email d = user.username # accessing username of the creator of that post which is liked e = str(a[0].image) sg = sendgrid.SendGridAPIClient( apikey=sg_api ) # sending email to creator of post informing # their post is liked using sendgrid from_email = Email("*****@*****.**") to_email = Email(b) subject = "Your post has been liked" content = Content( "text/plain", "Your post " + e + " on Review This Website is liked by " + d) mail = Mail(from_email, subject, to_email, content) response = sg.client.mail.send.post(request_body=mail.get()) print response # liked before then delete the like else: existing_like.delete() # redirecting to feed return redirect('/feed/') # not logged in so redirecting to login page else: return redirect('/login/')
def like_view(request): user = check_validation(request) if user and request.method == 'POST': form = LikeForm(request.POST) if form.is_valid(): post_id = form.cleaned_data.get('post').id existing_like = LikeModel.objects.filter(post_id=post_id, user=user).first() if not existing_like: LikeModel.objects.create(post_id=post_id, user=user) email = EmailMessage('Subject', 'New Like on post', to=['*****@*****.**']) email.send() else: existing_like.delete() return redirect('/feed/') else: return redirect('/login/')
def add_user_to_g(): """If we're logged in, add curr user to Flask global.""" if CURR_USER_KEY in session: g.user = User.query.get(session[CURR_USER_KEY]) g.logout_form = LogoutForm() g.like_form = LikeForm() g.liked_messages = set(g.user.liked_messages) g.message_form = MessageForm() else: g.user = None
def like_view(request): user = check_validation(request) if user and request.method == 'POST': form = LikeForm(request.POST) if form.is_valid(): post_id = form.cleaned_data.get('post').id existing_like = LikeModel.objects.filter(post_id=post_id, user=user).first() if not existing_like: like = LikeModel.objects.create(post_id=post_id, user=user) post = PostModel.objects.get(id=post_id) content_text = like.user.username + " has just liked your post!" recipient_mail = post.user.email sending_mail(recipient_mail, content_text) else: existing_like.delete() return redirect('/feed/') else: return redirect('/login/')
def like_view(request): user = check_validation(request) if user and request.method == 'POST': form = LikeForm(request.POST) if form.is_valid(): post_id = form.cleaned_data.get('post').id existing_like = LikeModel.objects.filter(post_id=post_id, user=user).first() if not existing_like: LikeModel.objects.create(post_id=post_id, user=user) subject = "InstaClone Like Notification" post = PostModel.objects.filter(id=post_id).first() creator = UserModel.objects.filter(id=post.user_id).first() message = "Hello %s \n%s (%s) liked your photo" % ( creator.name, user.username, user.name) print creator.email send_email(str(creator.email), subject, message) else: existing_like.delete() return redirect('/feed/') else: return redirect('/login/')
def like_view(request): user = check_validation(request) if user and request.method == 'POST': form = LikeForm(request.POST) if form.is_valid(): post_id = form.cleaned_data.get('post').id existing_like = LikeModel.objects.filter(post_id=post_id, user=user) if not existing_like: like = LikeModel.objects.create(post_id=post_id, user=user) email = like.post.user.email subject = "Like on your post" body = "Someone just liked your post" send_mail(email, subject, body) ctypes.windll.user32.MessageBoxW(0, u"Liked successfully", u"SUCCESS", 0) else: existing_like.delete() ctypes.windll.user32.MessageBoxW(0, u"Unlike successfully", u"SUCCESS", 0) return redirect('/feed/') else: return redirect('/login/')
def like_view(request): user = check_validation(request) if user and request.method == "POST": like_form = LikeForm(request.POST) if like_form.is_valid(): post_id = like_form.cleaned_data.get('post').id existing_like = LikeModel.objects.filter(post_id=post_id, user=user).first() if not existing_like: like = LikeModel.objects.create(post_id=post_id, user=user) sg = sendgrid.SendGridAPIClient(apikey=sendgrid_api_key) from_email = Email("*****@*****.**") to_email = Email(like.post.user.email) subject = "Post Liked!!" message = "%s liked your post" % like.user.username content = Content("text/plain", message) mail = Mail(from_email, subject, to_email, content) response = sg.client.mail.send.post(request_body=mail.get()) ctypes.windll.user32.MessageBoxW(0, u"Post has been successfully liked", u"Success", 0) else: existing_like.delete() return redirect('/feed/') else: return redirect('/login/')
def like_view(request): user = check_validation(request) if user and request.method == 'POST': form = LikeForm(request.POST) if form.is_valid(): post_id = form.cleaned_data.get('post').id existing_like = LikeModel.objects.filter(post_id=post_id, user=user).first() if not existing_like: like = LikeModel.objects.create(post_id=post_id, user=user) ctypes.windll.user32.MessageBoxW(0, u"Keep scrolling for more.", u"Liked!", 0) sg = sendgrid.SendGridAPIClient(apikey=SENDGRID_API_KEY) from_email = Email("*****@*****.**") to_email = Email(like.post.user.email) subject = "Upload to win!" content = Content( "text/plain", "You have a new like on your post. Keep posting!") mail = Mail(from_email, subject, to_email, content) response = sg.client.mail.send.post(request_body=mail.get()) print(response.status_code) print(response.body) print(response.headers) else: existing_like.delete() return redirect('/feed/') else: return redirect('/login/')
def like_view(request): liked_msg = '' user = check_validation(request) if user and request.method == 'POST': form = LikeForm(request.POST) if form.is_valid(): post_id = form.cleaned_data.get('post').id existing_like = Like.objects.filter(post_id=post_id, user=user).first() if not existing_like: # print 'liking post' Like.objects.create(post_id=post_id, user=user) liked_msg = 'Liked!' else: # print ' unliking post' existing_like.delete() liked_msg = 'Unliked!' return redirect('/login_success/', {'liked_msg': liked_msg}) else: return redirect('/login/')
def homepage(): """Show homepage: - anon users: no messages - logged in: 100 most recent messages of followees """ form = LikeForm() if g.user: following_ids = [u.id for u in g.user.following] messages = (Message.query.filter( or_(Message.user_id == g.user.id, Message.user_id.in_(following_ids))).order_by( Message.timestamp.desc()).limit(100).all()) return render_template('home.html', messages=messages, user=g.user, form=form, redirect_to='/') else: return render_template('home-anon.html')