本文整理汇总了Python中models.Comment.user方法的典型用法代码示例。如果您正苦于以下问题:Python Comment.user方法的具体用法?Python Comment.user怎么用?Python Comment.user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Comment
的用法示例。
在下文中一共展示了Comment.user方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: submit_comment_view
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import user [as 别名]
def submit_comment_view(request):
try:
if request.method == 'GET':
paper_id = int(request.GET['id'])
elif request.method == 'POST':
paper_id = int(request.POST['id'])
paper = Paper.objects.filter(id=paper_id).get()
comment = Comment()
comment.paper = paper
comment.user = request.user
if request.method == 'POST':
form = forms.SubmitCommentForm(request.POST, instance=comment)
if form.is_valid():
form.save(paper)
return HttpResponseRedirect("paper?id=%d" % paper_id)
else:
form = forms.SubmitCommentForm()
except (ValueError, KeyError, Paper.DoesNotExist):
paper = None
form = None
return render_to_response("submit_comment.html", RequestContext(request, {
'form' : form,
'paper' : paper,
}))
示例2: submit_comment_view
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import user [as 别名]
def submit_comment_view(request):
import forms
user = UserProfile.objects.get(username=request.user.username)
try:
if request.method == 'GET':
paper_id = int(request.GET['id'])
elif request.method == 'POST':
paper_id = int(request.POST['id'])
paper = Paper.objects.filter(id=paper_id).get()
comment = Comment()
comment.paper = paper
comment.user = user
if request.method == 'POST':
form = forms.SubmitCommentForm(request.POST, instance=comment)
if form.is_valid():
form.save(paper)
return HttpResponseRedirect("paper?id=%s" % paper_id)
else:
form = forms.SubmitCommentForm()
except (ValueError, KeyError, Paper.DoesNotExist):
paper = None
form = None
return render(request, "submit_comment.html", {
'form' : form,
'paper' : paper,
'which_page' : "submit_comment"
})
示例3: new_comment
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import user [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
示例4: detail
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import user [as 别名]
def detail(request, post_id):
"""
:param request:
:param post_id:
:return:
"""
post = get_object_or_404(Post, pk=post_id)
parents = post.item.all()
content = ContentType.objects.get_for_model(Comment)
subs = Comment.objects.filter(content_type=content).filter(is_active=1).filter(parent=post_id)
if request.method == "POST":
form = CommentForm(request.POST)
if form.is_valid():
text = form.cleaned_data["text"]
email = form.cleaned_data["email"]
c_type = request.POST.get("c_type")
obj_id = request.POST.get("replyfor")
if c_type == "Comment":
c_model = Comment
if c_type == "Post":
c_model = Post
con_type = ContentType.objects.get_for_model(c_model)
new_comment = Comment(email=email,
text=text,
content_type=con_type,
parent=post_id,
object_id=obj_id,
pubdate=datetime.now(),
is_active=0)
new_comment.save()
if request.user.is_authenticated():
new_comment.is_active = 1
new_comment.user = request.user
new_comment.save()
else:
if email_check(email):
return redirect('/')
else:
act_code = produce_val()
send_act_code.delay(act_code,
new_comment.email)
new_activation = Activation(conf_code=act_code,
comment=new_comment,
exp_date=datetime.now(), )
new_activation.save()
form = CommentForm()
else:
form = CommentForm()
return render(request, 'blog/deneme.html', {'parents': parents,
'subs': subs, 'post': post,
'r_user': request.user,
'form': form, })
示例5: comment
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import user [as 别名]
def comment(todo_id):
comment_user = current_user()
form = request.form
one_comment = Comment(form)
one_comment.user = comment_user
one_comment.todolist = TodoList.query.filter_by(id=todo_id).first()
#有外键记得把每个外键连上
one_comment.save()
return redirect(url_for('comment_view', todo_id = todo_id))
示例6: comment_add
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import user [as 别名]
def comment_add():
user = current_user()
if user is None:
return redirect(url_for('login_view'))
else:
c = Comment(request.form)
c.user = user
c.save()
# log('comment-post by form:', c.post)
return redirect(url_for('post_view', post_id=c.post_id))
示例7: view_post
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import user [as 别名]
def view_post(id):
form = request.forms
if form.update_comment :
post = Post.get(id=id)
comment = Comment()
comment.post = post # current post
comment.user = User.get(username=form.username)
comment.content = form.content
comment.pub_date = datetime.now()
comment.save()
redirect('/view/post/%d' %(id,))
else :
post = Post.get(id=id)
comments = Comment.filter(post__id = id)
return template('templates/post.html.tpl',post=post,comments=comments)
示例8: comment_add
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import user [as 别名]
def comment_add():
j = request.get_json()
c = Comment(j)
log('comment request.get_json():', j)
c.user = current_user()
c.save()
comment = c.comment_row()
log('新增Comment:', c)
log('comment add, dict: ', comment)
t = comment.get('time', '')
ft = from_now(t)
response_data = {
'id': comment.get('id', ''),
'user_link': comment.get('user_link', ''),
'time': ft,
'content': comment.get('content', ''),
}
return json.dumps(response_data, indent=2)