Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
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})
Ejemplo n.º 5
0
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")
Ejemplo n.º 6
0
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)
Ejemplo n.º 7
0
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)
Ejemplo n.º 8
0
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)
Ejemplo n.º 9
0
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)
Ejemplo n.º 10
0
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)
Ejemplo n.º 11
0
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)
Ejemplo n.º 12
0
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)
Ejemplo n.º 13
0
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)
Ejemplo n.º 14
0
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})
Ejemplo n.º 15
0
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)
Ejemplo n.º 16
0
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)
Ejemplo n.º 17
0
def article(request, id):
    form = CommentForm(request.POST)
    context = {'article': Article.objects.get(pk=id), 'form': form}
    return render(request, 'article.html', context)
Ejemplo n.º 18
0
def new_comment(request):
    form = CommentForm()
    context = {'form': form}
    response = render(request, 'comments/post.html', context)
    return HttpResponse(response)
Ejemplo n.º 19
0
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)
Ejemplo n.º 20
0
def show_article(request, id):
    article = Article.objects.get(pk=id)
    form = CommentForm()
    context = {'article': article, 'form': form}
    return render(request, 'article.html', context)