def edit_comment(request, article_id, comment_id): article = Article.objects.get(pk=article_id) comment = Review.objects.get(pk=comment_id) comment.article_id = comment_id form = CommentForm(instance=comment) context = {"comment": comment, "form": form, "article": article} return render(request, "edit_comment_form.html", context)
def add_comment(request, pk): p = request.POST #print p """output: <QueryDict: {u'body': [u'good eats'], u'csrfmiddlewaretoken': [u'F4ioZcjG9UQQlYzBVQWKAnhOdRavY2Wa'], u'author': [u'salin']}>""" if p.has_key("body") and p["body"]: author = "Anonymous" if p["author"]: author = p["author"] """ Create a form to edit an existing Comment """ comment = Comment(title=Post.objects.get(pk=pk)) """ Create a form to edit an existing Comment, but use POST data to populate the form. """ form_comment = CommentForm(p, instance=comment) form_comment.fields["author"].required = False """ Create, but don't save the new author instance. """ comment = form_comment.save(commit=False) """ Modify the author in some way.""" comment.author = author """ Comment Notification. """ notify = True if comment.author == "salin": notify = False """ Save the new instance.""" comment.save(notify=notify) return HttpResponseRedirect(reverse("post", args=[pk])) #d = {'test': comment} #return render_to_response("blog/test.html", d) else: html = "<html><body>Invalid Form!</body></html>" return HttpResponse(html)
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 blog_post(request, id): post = get_object_or_404(Article, pk=id) if post.comments.count() > 0: comment_count = True else: comment_count = False new_form = CommentForm(initial={'article': id}) context = {'article': post, 'comments': comment_count, 'form': new_form} html = render(request, 'post.html', context) return HttpResponse(html)
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 post(request, pk): """Single post with comments and a comment form.""" """post below gets the title of the post. note: Post.objects.get()""" post = Post.objects.get(pk=int(pk)) comments = Comment.objects.filter(title=post) d = { "post": post, "user": request.user, "months": mkmonth_lst(), "comments": comments, "form": CommentForm(), "searchForm": ModelSearchForm() } d.update(csrf(request)) return render_to_response("blog/post.html", d)
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 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 article(request, id): form = CommentForm(request.POST) context = {'article': Article.objects.get(pk=id), 'form': form} return render(request, 'article.html', context)
def show_article(request, id): article = Article.objects.get(pk=id) form = CommentForm() context = {'article': article, 'form': form} return render(request, 'article.html', context)
def create_comment(request): print(request.POST) article = Article.objects.get(id=request.POST['article']) comment = CommentForm(request.POST) comment.save() return redirect('post_details', id=article.id)
def new_comment(request): form = CommentForm() context = {'form': form} response = render(request, 'comments/post.html', context) return HttpResponse(response)
def post_details(request, id): article = Article.objects.get(id=id) comment = Comment(article=article) form = CommentForm(instance=comment) context = {'form': form, 'post': Article.objects.get(pk=id)} return render(request, 'post.html', context)