def create_comment(request): form = CommentForm(request.POST) if form.is_valid(): new_comment = form.save() return HttpResponseRedirect('/post/' + request.POST['article']) else: print(form.errors) response = render(request, 'index.html') return HttpResponse(response)
def update_comment(request, article_id, comment_id): article = Article.objects.get(pk=article_id) comment = Comment.objects.get(pk=comment_id) form = CommentForm(request.POST, instance=comment) context = {"form": form} if form.is_valid(): form.save() return redirect(reverse('full_article', args=[article_id])) else: context = {"comment": comment, "form": form, "article": article} return render(request, "edit_comment_form.html", context)
def create_comment(request): article_id = request.POST['article'] article = Article.objects.get(id=article_id) form = CommentForm(request.POST) if form.is_valid(): new_comment = form.save(commit=False) new_comment.article = article context = {"form": form, "message": "Add a comment.", "action": "/comments/create", "article": article} form.save() return redirect(reverse('full_article', args=[article_id])) else: return render(request, 'article.html', context)
def comment(request, blog_id): if request.method == "POST": form = CommentForm(request.POST) if form.is_valid(): newComment = form.save() newComment.name = request.session.session_key[:20] newComment.save() return HttpResponseRedirect("/blog/" + str(newComment.blog.id)) else: form = CommentForm({"name": "old", "tweet": "message", "blog": blog_id}) return render_to_response("blog/comment.html", {"form": form, "blog_id": blog_id})
def add_comment(request,pk): if request.method == "POST" and request.POST: p = request.POST comment = Comment(post=Post.objects.get(pk=pk)) f = CommentForm(p) if f.is_valid(): fi = CommentForm(p,instance=comment) fi.save() return HttpResponseRedirect(reverse("blog.views.singlepost",args=[pk])) else: return HttpResponse("Validation Error") else: return HttpResponse("Contact Admin.No Data from FORM")
def create_comment(request): article_id = request.POST['article'] articlelink = Article.objects.filter(id=article_id).first() # name = request.POST['name'] # message = request.POST['message'] # new_comment = Comment(name=name, message=message, article=articlelink) # new_comment.save() form = CommentForm(request.POST) context = {'article': articlelink, 'form': form} if form.is_valid(): new_comment = form.save(commit=False) new_comment.article = articlelink form.save() return HttpResponseRedirect(f'/article/{article_id}') else: return render(request, 'article.html', context)
def comment(request, article_id): if request.method == "POST": if request.POST['verify_message'].strip() == "pyfeng.com": f = CommentForm(request.POST) if f.is_valid(): cmt = f.save(commit=False) cmt.ip = get_client_ip(request) cmt.datetime = datetime.datetime.now() cmt.to_article = Article.objects.get(id=article_id) if request.POST['to_comment_id'] != "": cmt.to_comment = Comment.objects.get(id=request.POST['to_comment_id']) cmt.save() return HttpResponseRedirect('/blog/%s' % article_id) else: articles = Article.objects.order_by('datetime').reverse() tags = Tag.objects.order_by('weight') context = { 'tags': tags, 'recentcmts': Comment.objects.order_by('datetime').reverse()[:5], 'f': f, } return render(request, 'blog/error.html', context) #not "sleepycat.org" else: errmsg = u"Verification Message Error. Please Input: pyfeng.com" articles = Article.objects.order_by('datetime').reverse() tags = Tag.objects.order_by('weight') context = { 'tags': tags, 'recentcmts': Comment.objects.order_by('datetime').reverse()[:5], 'errmsg': errmsg, } return render(request, 'blog/error.html', context) #not POST else: return HttpResponseRedirect('/blog/%s' % article_id)
def addcomment(request, id, slug): url = request.META.get('HTTP_REFERER') # son urlyi al if request.method == 'POST': #form post edildiyse form = CommentForm(request.POST) if form.is_valid(): current_user = request.user #kullanıcı oturum bilgisine erişme data = Comment() #model ile bağlantı kur data.user_id = current_user.id data.post_id = id data.subject = form.cleaned_data['subject'] data.comment = form.cleaned_data['comment'] data.ip = request.META.get('REMOTE_ADDR') #client ip adresi alma data.save() #veritabanına kaydet messages.success(request, "Yorumunuz gönderildi") return HttpResponseRedirect(url) messages.warning(request, "Hata: Yorumunuz gönderilemedi") return HttpResponseRedirect(url)
def addcomment(request,id): url = request.META.get ('HTTP_REFERER') # get last url if request.method == 'POST': # form post edildiyse form = CommentForm(request.POST) if form.is_valid(): current_user=request.user # Access User Session information data = Comment() #model ile bağlantı kur data.user_id = current_user.id data.blog_id =id data.subject = form.cleaned_data['subject'] data.comment = form.cleaned_data['comment'] data.rate = form.cleaned_data[ 'rate'] data.ip = request.META.get('REMOTE_ADDR') # Client computer ip address data.save() # verirabanına kaydet messages.success(request, "Yorumunuz başarı ile gönderilmiştir. Teşekkür Ederiz ") return HttpResponseRedirect(url) #return HttpResponse("Kaydedildi") messages.warning(request, "Yorumunuz Kaydedilmedi. Lutfen Kontrol Ediniz ") return HttpResponseRedirect(url)
def detail(request, slug): post = get_object_or_404(Post, slug=slug) comments = Comment.objects.filter(post_name=slug).order_by('-created')[:5] if request.method == 'POST': form = CommentForm(request.POST) if form.is_valid(): title = form.cleaned_data["title"] comment = form.cleaned_data["comment"] form = form.save(commit=False) form.post_name = slug if request.user.is_authenticated(): form.author = request.user else: messages.info(request, 'You need to have an account to post a comment.') return redirect('auth:index') form.save() return HttpResponseRedirect(reverse('blog:detail', args=(slug,))) else: form = CommentForm() return render(request, 'blog/detail.html', {'form': form, 'post': post, 'comments': comments})