当前位置: 首页>>代码示例>>Python>>正文


Python forms.CommentForm类代码示例

本文整理汇总了Python中blog.forms.CommentForm的典型用法代码示例。如果您正苦于以下问题:Python CommentForm类的具体用法?Python CommentForm怎么用?Python CommentForm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了CommentForm类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: post_comment_ajax

def post_comment_ajax(request, object_id):
    try:
        entry = Entry.published_objects.get(pk=object_id)
    except:
        raise Http404

    if request.method == "POST":
        form = CommentForm(request.POST)

        if form.is_valid():
            r = re.compile('(\w+\s+\n)|[<>"=]', re.I)
            #r = re.compile('[\w\s\n]?', re.I)
            #r = re.compile('<a href=', re.I)
            if not r.search(form.cleaned_data['body']) == None:
                raise Http404

            add_comment(form, entry)

            page = HttpResponseRedirect('/blog/comment/' + object_id + '/')
            page.set_cookie('commentName', form.cleaned_data['author'].encode('utf-8'), expires=cookie_expires_value(), path='/', domain=None, secure=None)
            return no_cache_page(page)
        else:
            form = CommentForm()

        page = render_to_response('entry_comment.html', {'comments': entry.published_comment_list(), 'entry': entry, 'form': form})
        return no_cache_page(page)
开发者ID:tactactad,项目名称:reiare,代码行数:26,代码来源:views.py

示例2: post_comment

def post_comment(request, year, month, day, slug):
    try:
        entry = get_entry(year, month, day, slug)
    except:
        raise Http404

    if request.method == "POST":
        form = CommentForm(request.POST)
        if form.is_valid():
            r = re.compile('(\w+\s+\n)|[<>"=]', re.I)
            #r = re.compile('<a href=', re.I)
            if not r.search(form.cleaned_data['body']) == None:
                return HttpResponseForbidden('<h1>403 Forbidden.</h1>')

            add_comment(form, entry)

            page = HttpResponseRedirect(entry.get_absolute_url())
            page.set_cookie('commentName', form.cleaned_data['author'].encode('utf-8'), expires=cookie_expires_value(), path='/', domain=None, secure=None)
            return page

        else:
            form = CommentForm()

        return render_to_response('blog/entry_detail.html',
            dict(form=form, object=entry, do_display_comments=True,
                do_display_comment_form=True),
            context_instance=RequestContext(request))
    return HttpResponseForbidden('<h1>403 Forbidden.</h1>')
开发者ID:tactactad,项目名称:reiare,代码行数:28,代码来源:views.py

示例3: comment

def comment(request, id):
    """
    Add a comment to blog
    """
    if request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            comment = Comment()
            comment.comment = data['comment']
            comment.blog_id = id
            comment.user_name = data['user_name']
            comment.email = data['email']
            comment.source_address = request.META['REMOTE_ADDR']# '192.168.2.8'
            comment.create_date = datetime.datetime.now()
            comment.save()
            blog = Blog.objects.get(id=id)
            if blog.comment_count is None:
                blog.comment_count = 0
            blog.comment_count += 1
            blog.save()
            if request.user.is_authenticated():
                return HttpResponseRedirect('/adminshow/%s/' % id)
            else:
                return HttpResponseRedirect('/show/%s/' % id)
        else:
            blog = Blog.objects.get(id=id)
            comments = Comment.objects.filter(blog_id=id)
            return render_to_response('artical.html', {'blog' : blog, 'comments' : comments, 'form' : form}, context_instance=RequestContext(request, processors=[new_blog, blog_group]))
    else:
        return HttpResponseRedirect('/show/%s/' % id)
开发者ID:kelvinfang,项目名称:juncheefamily,代码行数:31,代码来源:views.py

示例4: index

def index(request):
	entries = Blog.objects.all()

	if request.method == 'POST':
		
		form = CommentForm(request.POST)
		
		if form.is_valid():
			
			name = form.cleaned_data['name']
			comments = form.cleaned_data['comments']

			isSpam = consume(comments)
			closeWriters(writer_1, writer_2)
			updateSpamScore(isSpam)
			updateSvm(collectionSpamScores, scores[0])
			writeSpamScores(spamScoresFilename)				

			if isSpam:
				return render_to_response('postFail.html', locals())
				
			else:		
				return render_to_response('postSuccess.html', locals())	
	else:
		form = CommentForm()

	return render_to_response('index.html', locals())
开发者ID:jlburgos,项目名称:Spam-Filter,代码行数:27,代码来源:views.py

示例5: comment

def comment(req):
	if req.method == 'POST':
		form = CommentForm(req.POST) # 换成表单
		if form.is_valid():
			comment = form.save()
			return HttpResponseRedirect('/comment/')
	comment_list = Comment.objects.all()
	paginator = Paginator(comment_list, 10)
	num_pages = paginator.num_pages
	pages = range(1, num_pages + 1)
	width = num_pages * 34

	# Make sure page request is an int. If not, deliver first page.
	try:
	    page = int(req.GET.get('page', '1'))
	except ValueError:
		page = 1

	 # If page request (9999) is out of range, deliver last page of results.
	try:
		comments = paginator.page(page)
	except (EmptyPage, InvalidPage):
		comments = paginator.page(paginator.num_pages)

	return render(req, 'comment.html', {
		'comments': comments,
		'tests': comment_list,
		'pages': pages,	
        'current_page': int(page),
        'width': width,
		})
开发者ID:GitNickZhang,项目名称:FirstBlog,代码行数:31,代码来源:views.py

示例6: comment

def comment(request, post_id):
    if request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            if not request.user.is_authenticated():
                r = captcha.submit(request.POST['recaptcha_challenge_field'], request.POST['recaptcha_response_field'], settings.RECAPTCHA_PRIVATE_KEY, request.META['REMOTE_ADDR'])
                if not r.is_valid:
                    return redirect('/blog/'+post_id+'/') # Invalid form entry
            f = form.save(commit=False);
          
            f.post_id = post_id
            if request.user.is_authenticated():
                f.author_id = request.user.id
                f.author_name = ''
                f.author_email = ''
            f.save()
        
            email_msg  = 'You have a new comment at http://www.jessicasteiber.com/blog/'+post_id+'/#comments'
            email_from = '[email protected]'
            email_to   = ['[email protected]', '[email protected]']
        
            # Send email notification
            send_mail('New Blog Comment - JessicaSteiber.com', email_msg, email_from, email_to)
        
            return redirect('/blog/'+post_id+'/#comments') # Go back to blog with new comment
        else:
            return redirect('/blog/'+post_id+'/') # Invalid form entry
    else:
        return redirect('/blog/'+post_id+'/') # Go back to blog
开发者ID:UTAlan,项目名称:JesiSteiber.com,代码行数:29,代码来源:views.py

示例7: comment

def comment(request, post_id):
	if request.method == 'POST':
		post_obj = Post.objects.get(id = post_id)
		mail     = request.POST.get('mail')
		username = request.POST.get('username')
		message  = request.POST.get('message')
		post     = request.POST.get('post', post_id)

		data = {
			'mail'     : mail,
			'username' : username,
			'message'  : message,
			'post'     : post_id
		}

		form = CommentForm(data)

		if form.is_valid():
			comment = Comment(mail= mail, username=username, message=message, post=post_obj)
			comment.save()
			request.session['comment_error']   = False
			request.session['comment_success'] = True
		else:
			request.session['comment_success'] = False
			request.session['comment_error']   = True
	else:
		form = CommentForm()

	return HttpResponseRedirect(reverse('post_details', kwargs={'slug': post_obj.slug}))
开发者ID:4goodapp,项目名称:BlogMVC,代码行数:29,代码来源:views.py

示例8: post_detail

def post_detail(request, year, month, day, post):
    post = get_object_or_404(Post, slug=post, status='published',
                             publish__year=year, publish__month=month,
                             publish__day=day)
    comments = post.comments.filter(active=True)

    if request.method == 'POST':
        comment_form = CommentForm(data=request.POST)
        if comment_form.is_valid():
            new_comment = comment_form.save(commit=False)
            new_comment.post = post
            new_comment.save()
            # XXX: fix this, can't find post after submitting
            return HttpResponseRedirect(reverse('blog:post_detail', kwargs={'year': year,
                                                                            'month': month,
                                                                            'day': day,
                                                                            'post': post}))
    else:
        comment_form = CommentForm()

    post_tags_ids = post.tags.values_list('id', flat=True)
    similar_posts = Post.published.filter(tags__in=post_tags_ids).exclude(id=post.id)
    similar_posts = similar_posts.annotate(same_tags=Count('tags')).order_by('-same_tags',
                                                                             '-publish')[:4]

    return render(request, 'blog/post/detail.html', {'post': post, 'comments': comments,
                                                     'comment_form': comment_form,
                                                     'similar_posts': similar_posts})
开发者ID:matthynes,项目名称:djangobyexample---blog,代码行数:28,代码来源:views.py

示例9: post

def post(request, username, post_id):
    try:
        template = 'blog/post.html'
        args = {}
        required_post = Post.objects.get(id=post_id)

        if not required_post.visible and required_post.user != request.user:
            raise Http404()

        args.update({'post': required_post})
        args.update({'comments': Comment.objects.filter(post=post_id)})

        if request.method == 'POST':
            form = CommentForm(request.POST)

            if form.is_valid():
                Comment(post=Post.objects.get(id=post_id),
                        user=User.objects.get(username=request.user.username),
                        body=form.cleaned_data['body']).save()

                return HttpResponseRedirect('/' + username + '/post' + post_id)
        else:
            form = CommentForm()

        args.update({'form': form})
    except:
        raise Http404()

    return render_to_response(template, args, context_instance=RequestContext(request))
开发者ID:luciys,项目名称:website,代码行数:29,代码来源:views.py

示例10: view_entry

def view_entry(request, e_id):
    """ View Entry """
    entry = Entry.objects.get(id=e_id)
    entry.parsed_content = mark_safe(entry.content) #bbcode.render_html(entry.content) 
    msg = ''
    if(request.method == 'POST'):
        user_data= {'author': request.POST['author'] , 'email': request.POST['email'], 'message': request.POST['message'],'captcha': request.POST['captcha'] }

        #check captcha
        code = request.session['captcha_code']

        if(request.user.is_authenticated()):
            #user auth witrh external account
            user_data['author'] = '%s %s '%(request.user.first_name, request.user.last_name ) 
            
            if(request.session['backend'] == 'twitter'):
                user_data['author'] += '(@%s)'%(request.user.username)
            else:
                user_data['author'] +='(%s)'%(request.session['backend'])

            if(request.user.email == ''):
               user_data['email'] = '[email protected]'#request.user.email
            else:
               user_data['email'] = request.user.email
            logout(request)

        cf = CommentForm(user_data)
            
        if(cf.is_valid()):
            #Check Captcha
            if(''.join(code) == str.strip(str(request.POST['captcha'].upper()))):
                #save comment
                com = Comment()
                com.author = cf.cleaned_data['author']
                com.content = cf.cleaned_data['message']
                com.email = cf.cleaned_data['email']
                com.entry = entry
                try: 
                    com.save()
                    msg = 'Comment posted succesfully. Thanks.!'
                except:
                    msg = 'Error saving your comment. Please try again.' 
            else:
                msg = 'Wrong Captcha code. Please Try Again'
            
        else:
            msg = 'Error processing your comment. Please Try Again.'

        request.session['comment_posted_msg'] = msg
        return redirect('/blog/article/%s'%(e_id))#TODO put marker here to go to specific part of the html

    if('comment_posted_msg' in request.session):
        msg= request.session['comment_posted_msg']
        del request.session['comment_posted_msg']
    comments = entry.comment_set.filter(status=True)
    cf = CommentForm()

    t = get_template("entry.htm")
    c = RequestContext(request, {'entry': entry,'comments': comments, 'cform': cf, 'rn': random.randint(1,999999), 'msg': msg})
    return HttpResponse(t.render(c))
开发者ID:jeysonmc,项目名称:falsepixel,代码行数:60,代码来源:views.py

示例11: lire_article

def lire_article(request, slug):
    """
    Affiche un article complet, sélectionné en fonction du slug
    fourni en paramètre
    """
    article = get_object_or_404(Article, slug=slug)
    comments = Comment.objects.filter(article=article)
    
    if request.method == 'POST':
        form = CommentForm(request.POST)
        
        if form.is_valid():
            
            # ajouter la relation avec l'article
            comment = Comment()
            comment.pseudo = form.cleaned_data['pseudo']
            comment.email = form.cleaned_data['email']
            comment.contenu = form.cleaned_data['contenu']
            comment.article = article
            
            comment.save()
            
            renvoi = True 
    else:
            form = CommentForm()

    return render(request, 'blog/lire_article.html', locals())
开发者ID:VincentMardon,项目名称:django_blog,代码行数:27,代码来源:views.py

示例12: entry_detail

def entry_detail(request, year, month, day, slug, draft=False):
    date = datetime.date(*time.strptime(year+month+day, '%Y'+'%b'+'%d')[:3])
    entry = get_object_or_404(Entry, slug=slug,
            created_on__range=(
                datetime.datetime.combine(date, datetime.time.min),
                datetime.datetime.combine(date, datetime.time.max)
            ), is_draft=draft)

    if request.method == 'POST' and entry.comments_allowed():
        form = CommentForm(request.POST)
        if form.is_valid():
            comment = Comment(**form.cleaned_data)
            comment.entry = entry
            if request.META['REMOTE_ADDR'] != '':
                comment.ip = request.META['REMOTE_ADDR']
            else:
                comment.ip = request.META['REMOTE_HOST']
            comment.date = datetime.datetime.now()
            comment.karma = 0
            comment.spam = akismet(request, comment)
            comment.save()
            if (not comment.spam) and settings.BLOG_COMMENT_EMAIL:
                comment_email = "%s\n--\n%s\n%s\n%s" % (comment.comment,
                        comment.name, comment.email, comment.website)
                send_mail('[Blog] %s' % entry.title, comment_email,
                        comment.email, [entry.author.email], fail_silently=True)
            return HttpResponseRedirect(entry.get_absolute_url())
    else:
        form = CommentForm()

    return render_to_response('blog/entry_detail.html',
            {'blog_title': settings.BLOG_TITLE, 'tags': Tag.objects.all(),
                'object': entry, 'comment_form': form},
                context_instance=RequestContext(request))
开发者ID:spr,项目名称:spr-django-blog,代码行数:34,代码来源:views.py

示例13: detail

def detail(request, p_id):
    context = RequestContext(request)
    tags = Tag.objects.all()
    context_dict = {'tags': tags}

    post = get_object_or_404(Post, id=p_id)
    context_dict['post'] = post

    comments = Comment.objects.filter(post=post)
    context_dict['comments'] = comments

    if request.method == 'POST':
        form = CommentForm(request.POST)

        if form.is_valid():
            comment = form.save(commit=False)
            comment.post = post
            comment.save()
            return redirect('detail', p_id=p_id)
    else:
        form = CommentForm()

    context_dict['comment_form'] = form
    return render_to_response('blog/detail.html',
                              context_dict, context)
开发者ID:redlolgeerf,项目名称:simple_blog,代码行数:25,代码来源:views.py

示例14: article

def article(request, article_pk, slug=None):
    article = get_object_or_404(Article, pk=article_pk, is_draft=False)
    # If slug is incorrect, "redirect friendly" to the correct link.
    if not slug or slug != article.slug:
        return http.HttpResponsePermanentRedirect(article.get_absolute_url())
    if request.method == "POST":
        user = request.user
        if user.is_anonymous():
            return http.HttpResponseForbidden()
        comment_form = CommentForm(request.POST, user=user)
        if comment_form.is_valid():
            comment = comment_form.save(commit=False)
            comment.author = user
            if user.is_staff and user.is_superuser:
                comment.is_moderated = True
            comment.save()
            return redirect(comment.get_absolute_url())
    else:
        comment_form = CommentForm()
    return render_to_response(
        "article.html",
        {
            "page_title": article.title,
            "article": article,
            "comment_form": comment_form,
            "comment_pk": request.GET.get("comment_pk"),
        },
        context_instance=RequestContext(request),
    )
开发者ID:daGrevis,项目名称:daGrevis.lv,代码行数:29,代码来源:views.py

示例15: get_article

def get_article(request,slug):
    try:
        article=Article.objects.get(slug=slug)
    except ObjectDoesNotExist:
        return HttpResponseRedirect('/')

    try:
        comments=Comment.objects.filter(article=article).order_by('-date','-id')        
    except ObjectDoesNotExist:
        comments=None
   
    if request.method == 'POST': 
        form = CommentForm(request.POST, **{'article':article,'ip':request.META['REMOTE_ADDR'],})
        if form.is_valid(): 
            comment=Comment()
            comment.comment = form.cleaned_data['comment']
            comment.article = article
            if request.user.is_authenticated():
                comment.user = request.user
            comment.ip=request.META['REMOTE_ADDR']
            comment.save()
            return HttpResponseRedirect('/'+article.slug) 
    else:
        form = CommentForm() 

    
    return render_to_response('blog/article.html', {
        'form': form,
        'article': article,
        'comments':comments,
    },context_instance=RequestContext(request))
开发者ID:glebkolyagin,项目名称:superblog,代码行数:31,代码来源:views.py


注:本文中的blog.forms.CommentForm类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。