本文整理汇总了Python中models.Comment.save方法的典型用法代码示例。如果您正苦于以下问题:Python Comment.save方法的具体用法?Python Comment.save怎么用?Python Comment.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Comment
的用法示例。
在下文中一共展示了Comment.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: new_comment
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import save [as 别名]
def new_comment(request,idnum):
try:
post = request.POST
sentiment = post["sentiment"]
title = post["comment_title"]
text = post["comment_text"]
all = post["images"]
images = map(int,post["images"].split("_")) if all else []
venue = Venue.objects.get(id=idnum)
if sentiment and title and text:
comment = Comment()
comment.set_sentiment_by_index(int(sentiment))
comment.title = title
comment.text = text
comment.venue = venue
comment.user = request.user
comment.save()
for id in images:
image = VenueImage.objects.get(id=id)
image.comment = comment
image.save()
else:
raise Exception("invalid post content")
except Exception, e:
pass
示例2: product_page
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import save [as 别名]
def product_page(request, product_id):
product = Product.objects.get(pk=product_id)
product = get_object_or_404(Product, pk=product_id)
if request.method == 'POST':
form = CommentForm(request.POST)
if form.is_valid():
author_name = form.cleaned_data.get("author_name") or u"Гость"
body = form.cleaned_data.get("body")
c = Comment(author_name=author_name,
body=body,
product=product)
c.save()
return HttpResponseRedirect('/product/' + product_id)
else:
form = CommentForm()
categories = get_categories()
comments = product.comment_set.all().order_by('-date')[:10]
bread_categories = [MainMock()] + product.category.get_path_up()
print(bread_categories)
context_dict = dict(product=product,
categories=categories,
comments=comments,
form=form,
cart=get_cart(request),
bread_categories=bread_categories,
)
return render(request, 'store/product.html', context_dict)
示例3: add_comment
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import save [as 别名]
def add_comment(request, movie_id):
newcomment = Comment(text=request.POST['comment_text'], movie=Movie.objects.filter(id=movie_id)[0])
newcomment.save()
comments = Comment.objects.filter(movie=movie_id)
movie = Movie.objects.filter(id=movie_id)[0]
context = {'comments':comments,'movie':movie}
return render(request, 'movies/movie.html', context)
示例4: comment_add
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import save [as 别名]
def comment_add():
log('发送评论')
user_now = current_user()
form = request.get_json()
print('form, ', form)
c = Comment(form)
blog_id = form.get('blog_id', '')
# 设置是谁发的
c.sender_name = user_now.username
c.blog = Blog.query.filter_by(id=blog_id).first()
# 保存到数据库
c.save()
blog = c.blog
blog.com_count = len(Comment.query.filter_by(blog_id=blog.id).all())
blog.save()
log('写评论')
status = {
'content': c.content,
'sender_name': c.sender_name,
'created_time': formatted_time(c.created_time),
'id': c.id,
}
r = json.dumps(status, ensure_ascii=False)
print('r, ', r)
return r
示例5: newcomment
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import save [as 别名]
def newcomment(request, blog_id):
if request.user.is_authenticated():
comment = Comment(comment=request.POST.get('comment'), blog=Blog(pk=blog_id) )
comment.save()
return HttpResponseRedirect(reverse('Blog:main'))
else:
return HttpResponse("You are not logged in.")
示例6: add_comment
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import save [as 别名]
def add_comment(request, movie_id):
Cmovie = Movie.objects.filter(pk=movie_id)[0]
newcomment = Comment(text=request.POST['comment_text'], movie=Cmovie)
# when making new objects, always remember to save them
newcomment.save()
return HttpResponseRedirect('/movies/' + movie_id)
示例7: test_comment_approved
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import save [as 别名]
def test_comment_approved(self):
post = Post(author=self.me, title="Hi", created_date=timezone.now())
post.save()
comment = Comment(author=self.me.username, post=post)
comment.approve()
comment.save()
assert comment in post.approved_comments()
示例8: get_aritle
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import save [as 别名]
def get_aritle(number):
article = get_aritle_by_number(number)
if article is None or not article.is_public:
return render_template('404.html'), 404
form = CommentForm()
if request.method == 'POST':
if form.validate_on_submit():
try:
month_number = int(form.checker.data)
except ValueError:
month_number = 0
if month_number != datetime.date.today().month:
form.checker.errors = ["Sorry, but please prove you are a human."]
form.checker.data = ""
else:
comment = Comment(
article_number=number,
author=form.author.data,
comment=form.comment.data,
)
comment.save()
return redirect(article.get_absolute_url())
comments = get_comments(number)
return render_template(
'article.html',
article=article,
form=form,
comments=comments,
)
示例9: comment_create
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import save [as 别名]
def comment_create(request):
article_id = int(request.POST["article_id"])
content = request.POST["content"].strip()
to_comment_id = int(request.POST["to_comment_id"])
# print article_id, content, to_comment_id
article = Article.objects.get(id=article_id)
# print article
comment = Comment(block=article.block, article=article,
owner=request.user, content=content,
to_comment_id=to_comment_id
)
comment.save()
if to_comment_id == 0:
owner=article.owner
content=u"有人评论了您的文章 %s" % article.title
else:
owner=comment.to_comment.owner
content=u"有人评论了您的评论 %s" % comment.to_comment.content[:30]
new_message = UserMessage(owner=owner,
content=content,
link=reverse("detail_message", args=[int(article_id), int(comment.id)])
)
new_message.save()
return json_response({})
示例10: event_view
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import save [as 别名]
def event_view(request, event_id, action=''):
event = Event.objects.get(id=event_id)
if action == 'accept':
event_guest = EventGuest.objects.get(event=event, user=request.user)
event_guest.status='a'
event_guest.notify_date = timezone.now()
event_guest.save()
return HttpResponseRedirect('/event/'+str(event_id))
elif action == 'decline':
event_guest = EventGuest.objects.get(event=event, user=request.user)
event_guest.status='d'
event_guest.notify_date = timezone.now()
event_guest.save()
return HttpResponseRedirect('/event/'+str(event_id))
elif action == 'comment':
if 'comment_text' in request.POST and request.POST['comment_text']:
comment = Comment(user=request.user, event=event, text=request.POST['comment_text'])
comment.save()
return HttpResponseRedirect('/event/'+str(event_id))
accepted = [ guest.user for guest in EventGuest.objects.filter(event=event, status='a') ]
pending = [ guest.user for guest in EventGuest.objects.filter(event=event, status='p') ]
declined = [ guest.user for guest in EventGuest.objects.filter(event=event, status='d') ]
t = get_template('event_view.html')
comments = Comment.objects.filter(event=event)
html = t.render( RequestContext(request, ({'user': request.user, 'event': event,
'accepted': accepted, 'pending': pending,
'declined': declined,
'comments': comments
})))
return HttpResponse(html)
示例11: add_comment
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import save [as 别名]
def add_comment(request):
if request.method == 'POST':
subject = request.POST['subject']
content = request.POST['content']
paper_id = request.POST['paper_id']
paper = Paper.objects.get(id=paper_id)
result = paper
try:
userprofile = UserProfile.objects.get(user = request.user)
print userprofile
except:
print sys.exc_info()
obj = Comment(UserProfile_id=userprofile,subject=subject,content=content,paper_id=paper)
obj.save()
url=result.paper_file.url
title = result.title
conference = result.conference
comment_list = get_paper_comments(paper_id)
paper = {'url': url, 'title': title, 'conference' : conference,'comment_list': comment_list,'paper_id': paper_id,'views': result.views, 'rating':int(result.rating)}
#return render(request, 'frame.html',{'paper': paper})
return render(request, 'viewpaper.html',{'paper': paper})
#return HttpResponse(json.dumps({'status': '200'}))
return HttpResponse(json.dumps({'status': 501}))
示例12: route_comment_add
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import save [as 别名]
def route_comment_add(request):
form = request.form()
c = Comment(form)
log('commentAdd c', c)
c.save()
w = Weibo.find(c.weibo_id)
return redirect('/weibo?user_id={}'.format(w.user_id))
示例13: save_comment
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import save [as 别名]
def save_comment():
req = request.form
post_id = req.get('postId')
comment_author = req.get('commentAuthor')
comment_content = req.get('commentContent')
Comment.save(post_id, comment_author, comment_content)
return jsonify(status='200')
示例14: save
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import save [as 别名]
def save(self, blog=None, user=None, ip=None):
if self.cleaned_data['body'] and blog and user:
comment = Comment(body=self.cleaned_data['body'], blog=blog,
user=user)
if ip:
comment.ip = ip
comment.save()
示例15: save_comment
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import save [as 别名]
def save_comment(request):
"""保存评论"""
article_id = request.POST.get("article_id", "").strip()
try:
_int_article_id = int(article_id)
except Exception:
return HttpResponseRedirect("/")
username = request.POST.get("username", "").strip()
content = request.POST.get("content", "").strip()
if len(username) < 4 or len(content) < 4:
return HttpResponseRedirect("/")
comment = Comment()
comment.blog = Blog.objects.get(id=_int_article_id)
comment.blog.comment_times += 1
comment.blog.save()
comment.submit_name = username
comment.content = content
comment.ip = gcommon.get_remote_addr(request) # request.META['REMOTE_ADDR']
comment.save()
return HttpResponseRedirect("/blog/%d.html" % _int_article_id)