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


Python Comment.save方法代码示例

本文整理汇总了Python中blog.models.Comment.save方法的典型用法代码示例。如果您正苦于以下问题:Python Comment.save方法的具体用法?Python Comment.save怎么用?Python Comment.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在blog.models.Comment的用法示例。


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

示例1: post_comment

# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import save [as 别名]
def post_comment(request,blog_id):
	blog=get_object_or_404(Blog,id=blog_id)
	titl=request.POST['title']
	content=request.POST['content']
	c=Comment(title=titl,pub_date=timezone.now(),parent=blog,content=content,author=User.objects.get(id=1))
	c.save()
	return HttpResponse('Your comment has been posted!')
开发者ID:siddharthm,项目名称:dblog,代码行数:9,代码来源:views.py

示例2: view_entry

# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import save [as 别名]
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,代码行数:62,代码来源:views.py

示例3: blog_comment

# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import save [as 别名]
def blog_comment(request, offset):
	offset=int(offset)
	e=Entries.objects.filter(id=offset)
	if not request.POST['name']:
		return HttpResponse(u'이름을 입력하세요')
	cmt_name=request.POST['name']
	cmt_content=request.POST['content']
	if not request.POST['content']:
		return HttpResponse(u'글 내용을 입력하세요')
	cmt_password=request.POST['password']
	if not request.POST['password']:
		return HttpResponse(u'비밀번호를 입력하세요')
	cmt_password = md5.md5(cmt_password).hexdigest()
	cmt=Comment()
	try:
		cmt.name=cmt_name
		cmt.password=cmt_password
		cmt.text=cmt_content
		ie=Entries.objects.get(id=request.POST['entry_id'])
		cmt.entry=ie
		ie.cnumber=ie.cnumber+1
		ie.save()
		cmt.save()
	except:
		return HttpResponse('오류가 나고 있습니다')
	c=Comment.objects.filter(entry=Entries.objects.get(id=offset))
	return render_to_response('blog.html',{'offset':offset,'e':e,'c':c})
开发者ID:kimshangyup,项目名称:myfirstsns,代码行数:29,代码来源:views.py

示例4: test_creating_a_new_comment_and_saving_it_to_the_database

# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import save [as 别名]
 def test_creating_a_new_comment_and_saving_it_to_the_database(self):
     # start by create one Category and one post
     category = Category()
     category.name = "First"
     category.slug = "first"
     category.save()
     
     # create new post
     post = Post()
     post.category = category
     post.title = "First post"
     post.content = "Content"
     post.visable = True
     post.save()
     
     # create one comment
     comment = Comment()
     comment.name = "John"
     comment.content = "This is cool"
     comment.post = post
     
     # check save
     comment.save()
     
     # now check we can find it in the database
     all_comment_in_database = Comment.objects.all()
     self.assertEquals(len(all_comment_in_database), 1)
     only_comment_in_database = all_comment_in_database[0]
     self.assertEquals(only_comment_in_database, comment)
     
     # and check that it's saved its two attributes: name and content
     self.assertEquals(only_comment_in_database.name, comment.name)
     self.assertEquals(only_comment_in_database.content, comment.content)
开发者ID:pabllo87,项目名称:Ultra-simple-blog,代码行数:35,代码来源:models.py

示例5: entry_detail

# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import save [as 别名]
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,代码行数:36,代码来源:views.py

示例6: add_comment_to_post

# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import save [as 别名]
def add_comment_to_post(id, subName, subComment):
    
    blogPostObj = BlogPost.objects.get(pk=id)
    addComment = Comment(name=subName, comment=subComment, blogPost=blogPostObj)
    addComment.save()
    
    return True
开发者ID:fayaaz,项目名称:jzargo,代码行数:9,代码来源:comments.py

示例7: show_blog

# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import save [as 别名]
def show_blog(request, blog_id):
    stats = mytools.get_stats(request)
    try:
        this_blog = Blog.objects.get(pk = blog_id)
    except Blog.DoesNotExist:
        raise Http404
    if request.POST:    #Save and refresh the comments.
        response = HttpResponse()
        response['Content-Type'] = 'text/plain'
        user = request.POST.get('user')
        email = request.POST.get('email')
        this_content = request.POST.get('content')
        ctime = datetime.now()
        comment = Comment(user_name=user, email_addr=email, content=this_content, blog=this_blog, comment_time=ctime)
        comment.save()
        str_ctime = str(ctime).split('.')[0][:16]
        response.write(str_ctime)
        return response

    this_blog.scan += 1
    this_blog.save()
    comments = Comment.objects.filter(blog__exact=this_blog)
    tags = Tag.objects.all()
    arch = mytools.get_arch()
    return render_to_response('blog.html',
                              {'blog':this_blog, 'comments':comments, 'show_tags':tags, 'arch':arch, 'stats':stats}
                             )
开发者ID:bt404,项目名称:kblog,代码行数:29,代码来源:views.py

示例8: add_comment

# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import save [as 别名]
def add_comment(request):
	name = request.POST.get('name', '')
	if not name.strip():
		return HttpResponse('name error')

	password = request.POST.get('password', '')
	if not password.strip():
		return HttpResponse('password error')
	password = hashlib.md5(password.encode('utf-8')).hexdigest()

	website = request.POST.get('website', '')
	if not website.strip():
		return HttpResponse('website error')
	if website.find("http://") == -1 or website.find("https://") == -1:
		website = "http://" + website

	content = request.POST.get('content', '')
	if not content.strip():
		return HttpResponse('content error')

	post_id = request.POST.get('post_id', '')
	if not post_id.strip():
		return HttpResponse('post_id error')

	post = Post.objects.get(id=post_id)

	print('blog.views.add_comment post_id{0}'.format(post_id), sys.stderr)

	new_cmt = Comment(name=name, password=password, website=website, content=content, post=post)
	new_cmt.save()

	return redirect('blog.views.main', slug=post.slug)
开发者ID:Devgrapher,项目名称:django_blog,代码行数:34,代码来源:views.py

示例9: saveComment

# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import save [as 别名]
def saveComment(request):
    userid = request.session.get('userid', '')
    if userid == '':
        return HttpResponseRedirect('/index')

    permission = request.session.get('permission', '')
    if permission < 1:
        return HttpResponseRedirect('/index')
    commentText = request.POST['commentText']
    passageID = int(request.META['HTTP_REFERER'].split('/passage/')[1])
    passageObj = Passage.objects.get(id = passageID)
    passageObj.CommentTimes += 1
    passageObj.save()
    commentObj = Comment()
    userObj = User.objects.get(id = userid)
    commentObj.UserID = userObj
    commentObj.UserName = userObj.UserName
    commentObj.PassageID = passageObj
    commentObj.Time = datetime.now()
    commentObj.Content = commentText
    commentObj.save()
    commentObjLs = Comment.objects.filter(PassageID = passageID)[0:10]
    t = get_template('moreComment.html')
    c = Context({'commentObjLs':commentObjLs})
    html = t.render(c)
    #return HttpResponse('Hello')
    jsonObject = json.dumps({'html':html, 'commentCount':passageObj.CommentTimes},ensure_ascii = False)
    #加上ensure_ascii = False,就可以保持utf8的编码,不会被转成unicode
    return HttpResponse(jsonObject,content_type="application/json")
开发者ID:ChanSeaThink,项目名称:chanalpha,代码行数:31,代码来源:views.py

示例10: reply_comment

# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import save [as 别名]
def reply_comment(request):
    data = request.POST.copy()
    ctype = data.get("content_type")
    object_pk = data.get("object_pk")
    path=data.get('path')
    user=request.user
    try:
        model = models.get_model(*ctype.split(".", 1))
        target = model._default_manager.get(pk=object_pk)
    except (TypeError,AttributeError,ObjectDoesNotExist):
        logging.info('object not exits')
    comment = Comment(content_type = ContentType.objects.get_for_model(target),
            object_pk    = force_unicode(target._get_pk_val()),
            author=user.username,
            email=user.email,
            weburl=user.get_profile().website,
            content=data.get('comment'),
            date  = datetime.now(),
            mail_notify=True,
            is_public    = True,
            parent_id    = data.get('parent_id'),
            )
    comment.save()
    signals.comment_was_submit.send(
        sender  = comment.__class__,
        comment = comment                             
    )
    return HttpResponseRedirect(path)
开发者ID:zhigoo,项目名称:youflog,代码行数:30,代码来源:admin.py

示例11: comment

# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import save [as 别名]
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,代码行数:33,代码来源:views.py

示例12: post_comment

# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import save [as 别名]
def post_comment(request, entry_id):
    comment = Comment(entry_id = entry_id,
                      name = request.POST['name'],
                      comment = request.POST['comment'],
                      date = datetime.now())
    comment.save();
    return entry(request, entry_id)
开发者ID:santialbo,项目名称:django_blog,代码行数:9,代码来源:views.py

示例13: add_comment

# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import save [as 别名]
def add_comment(request, post_id):
	#add new comment to our post
	p = request.POST

	if p.has_key("text") and p["text"]:
		
		# if has no author then name him myself
		author = "Nemo"
		if p["comment_author"]: 
			author = p["comment_author"]
		comment = Comment(post=Post.objects.get(pk=post_id))
		
		# save comment form
		cf = CommentForm(p, instance=comment)
		cf.fields["comment_author"].required = False
		comment = cf.save(commit=False)
		
		# save comment instance
		comment.comment_author = author
		notify = True

		comment.save()	

	return_path  = redirect(request.META.get('HTTP_REFERER','/'))

	return return_path
开发者ID:Shmendrik,项目名称:mysite,代码行数:28,代码来源:views.py

示例14: detail

# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import save [as 别名]
def detail(request, entry_id):
    if request.method == "POST":
        form = CommentForm(request.POST, error_class=DivErrorList)
        if form.is_valid():
            author = request.user
            text = request.POST['text']
            entry = entry = Entry.objects.get(pk=entry_id)
            pub_date = timezone.now()
            comment = Comment(author=author,
                              entry=entry,
                              text=text,
                              pub_date=pub_date)
            comment.save()

    dates = Entry.get_dates()
    form = CommentForm()

    try:
        entry = Entry.objects.get(pk=entry_id)
    except Entry.DoesNotExist:
        raise Http404
    comments = Comment.objects.filter(entry=entry)
    context = {'entry': entry, 'dates': dates,
               'comments': comments, 'form': form}
    return render(request, 'blog/detail.html', context)
开发者ID:paulmouzas,项目名称:blogodrone,代码行数:27,代码来源:views.py

示例15: add_comment

# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import save [as 别名]
def add_comment(request, slug):
    """Add a new comment."""
    p = request.POST
    post = Post.objects.get(slug=slug)
    author_ip = get_ip(request)

    if p.has_key("body") and p["body"]:
        author = "Anonymous"
        if p["author"]:
            author = p["author"]

        comment = Comment(post=post)
        cf = CommentForm(p, instance=comment)
        cf.fields["author"].required = False

        comment = cf.save(commit=False)
        comment.author = author
        comment.author_ip = author_ip
        comment.save()
        messages.success(
            request, "Thank you for submitting a comment. It will appear once reviewed by an administrator."
        )
    else:
        messages.error(request, "Something went wrong. Please try again later.")
    return HttpResponseRedirect(post.get_absolute_url())
开发者ID:akmiller01,项目名称:know-arbitrage,代码行数:27,代码来源:views.py


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