Esempio n. 1
0
def respond_post(post):
    comments = Comment.objects.filter(post__id=post.id)
    form = PostCommentForm()
    captcha = BlogConfig.get_captcha()
    random = captcha.random()
    form.fields['random'] = django.forms.CharField(initial=random, \
            widget=django.forms.widgets.HiddenInput())
    nr_comments = len(comments)
    return render_to_resp('post.html', \
            {'post': post, 'commentform':form, 'comments':comments, \
            'captcha_img': captcha.image(), \
            'captcha_audio': captcha.audio_url(), \
            'errormsg': '', 'nr_comments':nr_comments})
Esempio n. 2
0
def respond_post(post):
    comments = Comment.objects.filter(post__id=post.id)
    form = PostCommentForm()
    captcha = BlogConfig.get_captcha()
    random = captcha.random()
    form.fields['random'] = django.forms.CharField(initial=random, \
            widget=django.forms.widgets.HiddenInput())
    nr_comments = len(comments)
    return render_to_resp('post.html', \
            {'post': post, 'commentform':form, 'comments':comments, \
            'captcha_img': captcha.image(), \
            'captcha_audio': captcha.audio_url(), \
            'errormsg': '', 'nr_comments':nr_comments})
Esempio n. 3
0
def post_comment(request, postid):
    if request.method == 'POST':
        post = Post.objects.filter(id=int(postid))
        if len(post) == 0:
            raise Http404
        post = post[0]
        form = PostCommentForm(request.POST)
        if form.is_valid():
            name = form.cleaned_data['name']
            url = form.cleaned_data['url']
            email = form.cleaned_data['email']
            content = form.cleaned_data['content']
            password = form.cleaned_data['password']
            random = request.POST['random']
            now = datetime.datetime.now()
            reader = Reader.objects.filter(name=name)

            captcha = BlogConfig.get_captcha()
            if captcha is not None:
                if not captcha.validate(random):
                    return HttpResponseRedirect('/id/' + postid +
                                                "/captchaerr")
                if not captcha.verify(password):
                    return HttpResponseRedirect('/id/' + postid +
                                                "/captchaerr")

            if len(reader) == 0:
                reader = Reader(name=name, url=url, email=email)
                reader.save()
            else:
                reader = reader[0]
                if len(url) != 0:
                    if reader.url != url:
                        reader.url = url
                if len(email) != 0:
                    if reader.email != email:
                        reader.email = email
                reader.save()
            comment = Comment(reader=reader, \
                    post=post,\
                    content=content, \
                    created=now)
            comment.save()
            return HttpResponseRedirect('/id/' + postid)

    return HttpResponseForbidden("Not implemented\r\n")
Esempio n. 4
0
def post_comment(request, postid):
    if request.method == 'POST':
        post = Post.objects.filter(id=int(postid))
        if len(post) == 0:
            raise Http404
        post = post[0]
        form = PostCommentForm(request.POST)
        if form.is_valid():
            name = form.cleaned_data['name']
            url = form.cleaned_data['url']
            email = form.cleaned_data['email']
            content= form.cleaned_data['content']
            password = form.cleaned_data['password']
            random = request.POST['random']
            now = datetime.datetime.now()
            reader = Reader.objects.filter(name=name)

            captcha = BlogConfig.get_captcha()
            if captcha is not None:
                if not captcha.validate(random):
                    return HttpResponseRedirect('/id/' + postid + "/captchaerr")
                if not captcha.verify(password):
                    return HttpResponseRedirect('/id/' + postid + "/captchaerr")

            if len(reader) == 0:
                reader = Reader(name=name, url=url, email=email)
                reader.save()
            else:
                reader = reader[0]
                if len(url) != 0:
                    if reader.url != url:
                        reader.url = url
                if len(email) != 0:
                    if reader.email != email:
                        reader.email = email
                reader.save()
            comment = Comment(reader=reader, \
                    post=post,\
                    content=content, \
                    created=now)
            comment.save()
            return HttpResponseRedirect('/id/' + postid)

    return HttpResponseForbidden("Not implemented\r\n")