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


Python Comment.save方法代码示例

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


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

示例1: comment_new

# 需要导入模块: from app.models import Comment [as 别名]
# 或者: from app.models.Comment import save [as 别名]
def comment_new(id):
    post = Post.get_by_id(id)

    if post is None or post.is_hidden:
        abort(404)

    form = CommentForm()

    if form.is_submitted():
        try:
            if not form.validate():
                raise Exception(_('ERROR_INVALID_SUBMISSION'))

            comment = Comment(user=current_user, post=post)
            form.populate_obj(comment)
            comment.save()

            flash(_('COMMENT_SAVE_SUCESS'))

            if comment.parent_comment:
                send_email('reply_comment', comment)
            else:
                send_email('comment', post, comment)

            return redirect(url_for('stamp.show',
                                    id=post.id,
                                    _anchor='comment-%s' % comment.id))

        except Exception as e:
            flash(e.message, 'error')

    return render_template('main/stamp/show.html',
                           post=post,
                           form=form)
开发者ID:jctt1983,项目名称:PythonBlog,代码行数:36,代码来源:index.py

示例2: article

# 需要导入模块: from app.models import Comment [as 别名]
# 或者: from app.models.Comment import save [as 别名]
def article(post_id):
    login_form = LoginForm()
    register_form = RegistrationForm()
    post = Post.query.get_or_404(post_id)
    if request.method == 'POST':
        if not current_user.is_authenticated():
            return 'please log in '
        data = request.get_json(force=True)
        if 'content' in data.keys():
            if 'self_ref_id' in data.keys():
                # user cannot be set directly to current_user because this is a context variable proxy object.
                # the expression current_user._get_current_object() returns the actual User object.
                # user = current_user._get_current_object()
                comment = Comment(content=data['content'], user_id=current_user.id, post_id=post_id,
                                  self_ref_id=data['self_ref_id'])
                response_data = {'content': data['content'], 'user': current_user.nickname,
                                 'ref_user': Comment.query.get(int(data['self_ref_id'])).user.nickname}
            else:
                comment = Comment(content=data['content'], user_id=current_user.id, post_id=post_id)
                response_data = {'content': data['content'], 'user': current_user.nickname}
            comment.save()
            return json.dumps(response_data)
        if 'voted' in data.keys():
            if data['voted'] == 'False' and not post.was_voted_by(current_user):
                post.do_vote(current_user)
                voted = 'True'
            else:
                post.cancel_vote(current_user)
                voted = 'False'
            return json.dumps({'count': post.votes.count(), 'voted': voted})

    comments = Post.query.get(post_id).comments
    form = CommentOnPostForm()
    return render_template('blog/post.html', post=post, form=form, comments=comments,
                           login_form=login_form, register_form=register_form)
开发者ID:cymoo,项目名称:very-simple,代码行数:37,代码来源:blog.py

示例3: create

# 需要导入模块: from app.models import Comment [as 别名]
# 或者: from app.models.Comment import save [as 别名]
 def create(self, request, apikey, apisignature):
     print "creating"
     if not key_check( apikey, apisignature, '/idea/comment/'):
         return {'error':'authentication failed'}
     else:
         print 
         commentForm = CommentForm({"comment":request.POST['comment']})
         if commentForm.is_valid():
             print "form valid"
             clean = commentForm.cleaned_data
             print clean
             print request.POST
             idea = Idea.objects.get(id = request.POST['idea_id'])
             print idea
             try:
                 print "trying"
                 comment = Comment(
                     text = clean['comment'], 
                     user = User.objects.get(id = request.POST['user_id']), 
                     idea = idea)
                 print comment
             except Idea.DoesNotExist:
                 return {'error':'no idea'}
             except User.DoesNotExist:
                 return {'error':'no user'}
             else:
                 comment.save()
                 #helpers.filter_tags(clean['tags'], idea)
                 print comment
                 return comment
         else:
             return {'error':'no comment'}
开发者ID:simonv3,项目名称:ideas,代码行数:34,代码来源:handlers.py

示例4: addComment

# 需要导入模块: from app.models import Comment [as 别名]
# 或者: from app.models.Comment import save [as 别名]
def addComment(request):
    """
    Respond to an HTTP request to add a comment to an oligo, at the URL ...app/addComment

    :param primer: oligo primer
    :param rating: user's rating
    :type rating: 1 - 5
    :param comment: user's comment
    :return: new comment list
    """
    if request.method == 'GET':
        q = request.GET
        if q.__contains__('primer'):
            if q.__contains__('rating'):
                rating = q['rating']
            else:
                rating = 0;
            if q.__contains__('text'):
                text = html.escape(q['text']) #escape evil embedded html
            elif q.__contains__('rating') == False:
                return HttpResponseBadRequest(json.dumps({'error': 'at least one of rating or text is required'}))
            else:
                text = '';
            comment = Comment(
                primer = q['primer'],
                rating = rating,
                text = text
            )
            comment.save()
            return findComments(q['primer'])
        return HttpResponseBadRequest(json.dumps({'error': 'primer is required'}))
    return HttpResponseBadRequest(json.dumps({'error':'POST not supported'}))
开发者ID:ucscHexmap,项目名称:djangoOligo,代码行数:34,代码来源:views.py

示例5: comment_view

# 需要导入模块: from app.models import Comment [as 别名]
# 或者: from app.models.Comment import save [as 别名]
def comment_view(request, identifier):
    if request.method == 'POST':
        snippet = Snippet.objects.get(pk=(int(identifier)))
        c = Comment(
            snippet=snippet, user=request.user, text=request.POST['text'])
        c.save()
        return redirect('/snippet/' + identifier)
开发者ID:dmitry-yakutkin,项目名称:snippetshare,代码行数:9,代码来源:views.py

示例6: event_show

# 需要导入模块: from app.models import Comment [as 别名]
# 或者: from app.models.Comment import save [as 别名]
def event_show(request, event_id):
    user = request.user
    event = Event.objects.get(pk=event_id)
    if request.method == 'POST':  # TODO: should really be PUT
        if user.get_profile().is_funder:
            grants = []
            for item in event.item_set.all():
                amount = request.POST.get("item_" + str(item.id), None)
                if amount:
                    amount = Decimal(amount)
                    grant, _ =\
                        Grant.objects.get_or_create(funder=user.get_profile(),
                                                    item=item,
                                                    defaults={'amount': 0})
                    amount_funded = sum(grant.amount for grant in
                                        Grant.objects.filter(item=item))
                    amount_funded += item.funding_already_received
                    # if the funder gave too much,
                    # adjust the price to be only enough
                    if amount + amount_funded - grant.amount > item.total:
                        amount = item.total - amount_funded + grant.amount
                    # only append if the amount has changed
                    if grant.amount != amount:
                        grant.amount = amount
                        grant.save()
                        grants.append(grant)
            if grants:
                messages.success(request, "Saved grant!")
                # email the event requester indicating that they've been funded
                event.status = 'F'  # F for FUNDED
                event.save()
                event.notify_requester(grants)
                # try to notify osa, but osa is not guaranteed to exist
                try:
                    user.get_profile().notify_osa(event, grants)
                except smtplib.SMTPException:
                    pass
            if request.POST.get('new-comment', None):
                comment = Comment(comment=request.POST['new-comment'],
                                  funder=user.get_profile(), event=event)
                comment.save()
            return redirect(EVENTS_HOME)
        else:
            return redirect(EVENTS_HOME)
    elif request.method == 'GET':
        if 'id' in request.GET:
            event.shared_funder = \
                User.objects.get(id=request.GET['id']).get_profile()
        return render_to_response('app/application-show.html',
                                  {'event': event},
                                  context_instance=RequestContext(request))
    else:
        return HttpResponseNotAllowed(['POST'])
开发者ID:JacobHenner,项目名称:common-funding-application,代码行数:55,代码来源:views.py

示例7: comment_add

# 需要导入模块: from app.models import Comment [as 别名]
# 或者: from app.models.Comment import save [as 别名]
def comment_add(order_id):
    text = request.form['text']
    c = Comment()
    o = Order.get(order_id)
    if not o:
        abort(404)
    c.text = text
    c.order_id = order_id
    c.user_login = current_user.login
    c.save()
    if current_user.is_admin:
        return redirect(url_for('admin_order', order_id=order_id))
    return redirect(url_for('order', order_id=order_id))
开发者ID:Cirreth,项目名称:orglib,代码行数:15,代码来源:CommentController.py

示例8: commit_comment

# 需要导入模块: from app.models import Comment [as 别名]
# 或者: from app.models.Comment import save [as 别名]
def commit_comment(request):
	user = User.objects.get(id = 1)
	aid = int(request.GET.get('id'))
	article = Article.objects.get(id = aid)
	nickname = request.GET.get('nickname')
	content = request.GET.get('content')
	if nickname == '':
		return HttpResponse("1")
	elif content == '':
		return HttpResponse("2")
	comment = Comment(user = user, article = article, nickname = nickname, content =content)
	comment.save()
	return HttpResponse('提交成功')
开发者ID:xueyue123,项目名称:zhBlog,代码行数:15,代码来源:front_manage.py

示例9: index

# 需要导入模块: from app.models import Comment [as 别名]
# 或者: from app.models.Comment import save [as 别名]
def index(request):
	user = User.objects.get(id=1)
	userprofile = UserProfile.objects.get(id = user.id)
	category_list = Category.objects.filter(user=user)
	essays_list = Essays.objects.filter(user=user.id)[:8]
	pages = request.GET.get('page')
	#print pages
	if pages == 'category_article_list':	#显示分类下的文章列表
		category = Category.objects.get(id=request.GET['id'])
		article_list = Article.objects.filter(category=category)
		content_dict = {'articles': article_list, 'categories': category_list, 'essays': essays_list, 'category': category, 'page': pages}
	elif pages == 'article_list':		#显示所有文章列表
		#article_list = Article.objects.order_by("date", "time")
		article_list = Article.objects.filter(user=user)[:8]		#取最近的5篇文章显示在首页,在模型中已经对文章进行排序
		#article_list
		content_dict = {'articles': article_list, 'categories': category_list, 'essays': essays_list, 'page': pages}
	elif pages == 'read_article':		#显示文章内容
		aid = int(request.GET['id'])
		article = Article.objects.get(id = aid)
		comment_list = Comment.objects.filter(article = article)
		content_dict = {'article': article, 'categories': category_list, 'essays': essays_list, 'comments': comment_list, 'page': pages}
	elif pages == 'all_essays_list':		#显示所有随笔列表
		all_essays_list = Essays.objects.filter(user=user)
		content_dict = {'allessays': all_essays_list, 'categories': category_list, 'essays': essays_list, 'page': pages}
	elif pages == 'read_essays':		#显示随笔内容
		essay = Essays.objects.get(id = request.GET['id'])
		content_dict = {'categories': category_list, 'essays': essays_list, 'essay': essay, 'page': pages}
	elif pages == 'commit_comment':
		aid = int(request.GET['id'])
		article = Article.objects.get(id = aid)
		nickname = request.GET.get('nickname')
		content = request.GET.get('content')
		if nickname == '':
			return HttpResponse("1")
		elif content == '':
			return HttpResponse("2")
		comment = Comment(user = user, article = article, nickname = nickname, content =content)
		comment.save()
		#print nickname + content
		comment_list = Comment.objects.filter(article = article)
		content_dict = {'article': article, 'categories': category_list, 'essays': essays_list, 'comments': comment_list, 'page': 'read_article'}
		return HttpResponse("评论成功")
	elif pages == 'message':
		article_list = Article.objects.filter(user=user)
		content_dict = {'categories': category_list, 'essays': essays_list, 'page': pages}
	else:					#其它
		article_list = Article.objects.filter(user = user)[:8]
		content_dict = {'articles': article_list, 'categories': category_list, 'essays': essays_list, 'page': 'index_page', 'user': user, 'userprofile': userprofile}
		#print content_dict
	return render(request, 'blog/index.htm', content_dict)
开发者ID:xueyue123,项目名称:zhBlog,代码行数:52,代码来源:front_manage.py

示例10: comment

# 需要导入模块: from app.models import Comment [as 别名]
# 或者: from app.models.Comment import save [as 别名]
def comment(request):
    if request.method == "POST":
        if not request.body is None:
            if User.objects.filter(user = request.POST['user']).exists() :
                d = timezone.localtime(timezone.now())
                comment = Comment(board = Board.objects.get(id = request.POST['board_id']),
                                  user = User.objects.get(user = request.POST['user']),
                                  content = request.POST['content'],
                                  date = d.strftime('%Y-%m-%d %H:%M:%S')
                                  )
                comment.save()
                return JSONResponse('')
            return HttpResponse(status=400)
        else :
            return HttpResponse(status=400)
    else :
        return HttpResponse(status=400)
开发者ID:Yoo2,项目名称:SabangPalbang-server,代码行数:19,代码来源:views.py

示例11: _comment

# 需要导入模块: from app.models import Comment [as 别名]
# 或者: from app.models.Comment import save [as 别名]
def _comment():
    data = request.get_json(force=True)
    content = data['content']
    post_id = data['post_id']

    # test

    bar = Post.query.get(post_id).user.pyname

    hub.add_notice(content, bar)
    comment_id = int(data['comment_id'])
    # print type(comment_id), comment_id, type(post_id), post_id, type(current_user.id)
    if comment_id == 0:
        comment = Comment(content=content, user_id=current_user.id, post_id=post_id)
    else:
        comment = Comment(content=content, user_id=current_user.id, post_id=post_id, ref_comment_id=comment_id)
    comment.save()
    return render_template('blog/_comment_item.html', comment=comment)
开发者ID:cymoo,项目名称:very-simple,代码行数:20,代码来源:blog.py

示例12: add_comment

# 需要导入模块: from app.models import Comment [as 别名]
# 或者: from app.models.Comment import save [as 别名]
def add_comment(post_id, parent_id=None):
    post = Post.query.get_or_404(post_id)
    post.permissions.view.test(403)
    parent = Comment.query.get_or_404(parent_id) if parent_id else None
    
    #user = User.query.first()
    form = CommentForm()
    if form.validate_on_submit():
        comment = Comment(post=post,
                          parent=parent,
                          author=current_user)
        form.populate_obj(comment)
        comment.save()
        post.num_comments += 1
        post.save()

        save_action(u"评论了条目 " + u'"' + post.title + u'"' )

        #comment_added.send()
        flash(u"谢谢你的评论", "successfully")
        author = parent.author if parent else post.author

        if author.email_alerts and author.id != current_user.id:
            if setting.MAIL_ENABLE:
                subject = u"有人回复了你的评论" if parent else \
                          u"有人给你的提交添加了评论"
                template = "emails/comment_replied.html" if parent else \
                           "emails/post_commented.html"
                body = render_template(template,
                                       author=author,
                                       post=post,
                                       parent=parent,
                                       comment=comment)
                mail.send_message(subject=subject,
                                  body=body,
                                  recipients=[post.author.email])
                flash(u"谢谢,你的邮件已发出", "successfully")
            else:
                flash(u"邮件服务器未开启,请联系管理员", "error")
        return redirect(comment.url)
    return render_template("post/add_comment.html",
                           parent=parent,
                           post=post,
                           form=form)
开发者ID:yxm0513,项目名称:7topdig,代码行数:46,代码来源:post.py

示例13: add_quote

# 需要导入模块: from app.models import Comment [as 别名]
# 或者: from app.models.Comment import save [as 别名]
def add_quote(request):
    if request.method == 'POST':
        print request.POST
        post_quote = ''
        post_comment = ''
        post_author = ''

        quote_form = QuoteForm(request.POST.copy(), prefix='quote')
        if quote_form.is_valid():
            cd = quote_form.cleaned_data
            post_quote = cd['quote']
            post_comment = cd['comment']
            post_author = cd['author']

            quote = Quote()

            if post_comment:
                print 'post_comment',post_comment
                comment = Comment()
                comment.text = post_comment
                comment.save()
                quote.comment = comment

            author, created = Author.objects.get_or_create(name__iexact=post_author)
            if post_author:
                author.name = post_author
            else:
                author.name = 'Anonymous'
            author.save()

            quote.author = author
            quote.quote = post_quote
            quote.save()
        else:
            print "Quote_form is not valid!"
        
        data = {
            'quote_text': post_quote,
            'quote_comment': post_comment,
            'quote_author': post_author,
        }

        return HttpResponse(simplejson.dumps(data))
    raise Http404
开发者ID:eddieberklee,项目名称:quotes,代码行数:46,代码来源:views.py

示例14: comment

# 需要导入模块: from app.models import Comment [as 别名]
# 或者: from app.models.Comment import save [as 别名]
def comment(request):
	if request.method == 'POST':
		form = CommentForm(request.POST, request.FILES)
		if form.is_valid():
			text = form.cleaned_data['text']
			pic = request.FILES['pic']
			comment = Comment(text=text, pic=pic)
			comment.save()
			import Image
			im = Image.open(comment.pic)
			im = im.resize((im.size[0]/4, im.size[1]/4), Image.ANTIALIAS)
			from django.conf import settings
			path = settings.MEDIA_ROOT+comment.pic.name
			im.save(path)
			return HttpResponseRedirect('/info/ok/')
	else:
		form = CommentForm()
	c = {'form': form}
	c.update(csrf(request))

	return render(request,'app/comment.html',c)
开发者ID:tuesda,项目名称:ref-of-djan,代码行数:23,代码来源:views.py

示例15: api_create_comment

# 需要导入模块: from app.models import Comment [as 别名]
# 或者: from app.models.Comment import save [as 别名]
def api_create_comment(request):
    data = json.loads(request.body.decode('utf-8'))
    file_id = data['id']
    content = data['content']
    # 对流程节点填写审批意见
    user = get_auth(request)
    # 必须为登陆状态下,评论
    if user is None:
        raise APIPermissionError('user')
    # 意见不能为空
    if not content or not content.strip():
        raise APIValueError('content')
    # 查询一下流程id是否有对应的流程
    review = Review.objects.get(file_id=file_id)
    # 没有的话抛出错误
    if review is None:
        raise APIResourceNotFoundError('review')
    # 完成流程的传递
    l = [review.user_name,
        review.proofread_user,
        review.review_user,
        review.countersign_user,
        review.approved_user,
        review.Issued_user,
        'success']
    i = 0
    for i in range(len(l)):
        if l[i] == user.name:
            review.dispose_user = l[i+1]
            review.save()
    file = Myfile.objects.get(pk=file_id)
    file.dispose_user = review.dispose_user
    if review.dispose_user == 'success':
        file.file_display = True
    file.save()
    # 构建一条评论数据
    comment = Comment(review_id=review.id, user_id=user.id, user_name=user.name, content=content.strip())
    # 保存到评论表里
    comment.save()
    return JsonResponse({'comment':comment.toDict()})
开发者ID:mocangli,项目名称:learngit,代码行数:42,代码来源:views.py


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