本文整理汇总了Python中models.Comment类的典型用法代码示例。如果您正苦于以下问题:Python Comment类的具体用法?Python Comment怎么用?Python Comment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Comment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_parse_comments
def test_parse_comments(self):
response = '''{"response":[6,
{"cid":2505,"uid":16271479,"date":1298365200,"text":"Добрый день , кароче такая идея когда опросы создаешь вместо статуса - можно выбрать аудитории опрашиваемых, например только женский или мужской пол могут участвовать (то бишь голосовать в опросе)."},
{"cid":2507,"uid":16271479,"date":1286105582,"text":"Это уже не практично, имхо.<br>Для этого делайте группу и там опрос, а в группу принимайте тех, кого нужно.","reply_to_uid":16271479,"reply_to_cid":2505},
{"cid":2547,"uid":2943,"date":1286218080,"text":"Он будет только для групп благотворительных организаций."}]}
'''
group = GroupFactory.create(remote_id=OWNER_ID)
post = PostFactory.create(remote_id=TR_POST_ID, wall_owner=group)
instance = CommentFactory.create(post=post)
author = UserFactory.create(remote_id=16271479)
instance.parse(json.loads(response)['response'][1])
instance.save()
self.assertEqual(instance.remote_id, '201164356_2505')
self.assertEqual(instance.text, u'Добрый день , кароче такая идея когда опросы создаешь вместо статуса - можно выбрать аудитории опрашиваемых, например только женский или мужской пол могут участвовать (то бишь голосовать в опросе).')
self.assertEqual(instance.author, author)
self.assertTrue(isinstance(instance.date, datetime))
instance = Comment(post=post)
instance.parse(json.loads(response)['response'][2])
instance.save()
self.assertEqual(instance.remote_id, '201164356_2507')
self.assertEqual(instance.reply_for.remote_id, 16271479)
示例2: get
def get(self):
# see if there is a key
comment = None
status = None
try:
comment = Comment.get( self.request.get('key') )
status = self.request.get('status')
except db.BadKeyError:
pass
if comment is None:
# show all the 'new' comments
comments = Comment.all().filter('status =', 'new').order('inserted').fetch(page_count+1)
more = True if len(comments) > page_count else False
comments = comments[:page_count]
vals = {
'comments' : comments,
'more' : more,
}
self.template( 'comment-list.html', vals, 'admin' )
else:
comment.status = status_map[status]
comment.put()
comment.node.regenerate()
self.redirect('./')
return
示例3: api_create_comment
def api_create_comment(id):
cookie_str = request.cookies.get(COOKIE_NAME)
user = {}
if cookie_str:
user = cookie2user(cookie_str)
if user is None:
r=jsonify({'error':'Please signin first'})
r.content_type = 'application/json'
return r
if not request.json['content'] or not request.json['content'].strip():
r=jsonify({'error':'no content'})
r.content_type = 'application/json'
return r
blog = Blog.query.filter(Blog.id==id).first()
reprint = Reprint.query.filter(Reprint.id==id).first()
b_id = ''
if blog is not None:
b_id = blog.id
if reprint is not None:
b_id = reprint.id
if not b_id:
r = jsonify({'error':'no blog'})
r.content_type = 'application/json'
return r
comment = Comment(blog_id=b_id, user_id=user.id, user_name=user.name, user_image=user.image, content=request.json['content'].strip())
db.session.add(comment)
db.session.commit()
a = comment.to_dict()
r = jsonify(a)
r.content_type = 'application/json;charset=utf-8'
return r
示例4: _post_comment
def _post_comment(self, index_url, comment_str, auther_ip, user):
title=urlparse(index_url).netloc
print comment_str, user
logger.debug('Auther_ip:' + auther_ip
+ ' User:' + str(user)
+ ' Title:' + title
+ ' Index_url:' + index_url
+ ' Comment_str:' + comment_str)
comment_board, created = CommentBoard.objects.get_or_create(
url=index_url,
title=urlparse(index_url).netloc)
comment_board.save() if created else None
if user.is_authenticated():
comment = Comment(
time_added=datetime.datetime.utcnow().replace(
tzinfo=utc),
comment_str=comment_str,
comment_board=comment_board,
auther_ip=auther_ip,
user=user) # 以后换成auther,现在先用user
else:
'''
Annoymous User access the site.
'''
comment = Comment(
time_added=datetime.datetime.utcnow().replace(
tzinfo=utc),
comment_str=comment_str,
comment_board=comment_board,
auther_ip=auther_ip)
comment.save()
示例5: post
def post(self, post_id):
session = get_current_session()
if session.has_key('user'):
message = helper.sanitizeHtml(self.request.get('message'))
user = session['user']
key = self.request.get('comment_key')
if len(message) > 0 and key == keys.comment_key:
try:
post = Post.all().filter('nice_url =', helper.parse_post_id( post_id ) ).get()
if post == None: #If for some reason the post doesn't have a nice url, we try the id. This is also the case of all old stories
post = db.get( helper.parse_post_id( post_id ) )
post.remove_from_memcache()
comment = Comment(message=message,user=user,post=post)
comment.put()
helper.killmetrics("Comment","Root", "posted", session, "",self)
vote = Vote(user=user, comment=comment, target_user=user)
vote.put()
Notification.create_notification_for_comment_and_user(comment,post.user)
self.redirect('/noticia/' + post_id)
except db.BadKeyError:
self.redirect('/')
else:
self.redirect('/noticia/' + post_id)
else:
self.redirect('/login')
示例6: submit_comment_view
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,
}))
示例7: review_comment
def review_comment():
commid = request.json['commid']
review = request.json['review']
user = User.current()
if not user.anonymous:
Comment.approve(commid, review, user)
return jsonify(success=True)
示例8: get
def get(self):
post_id = int(self.request.get('id'))
post = Post.get_by_id(post_id)
post.comment += 1
post.put()
comment = Comment(post=post.key, content=self.request.get("content"))
comment.put()
示例9: test_parse_comment
def test_parse_comment(self):
response = u'''{"attrs": {"flags": "l,s"},
"author_id": "538901295641",
"date": "2014-04-11 12:53:02",
"id": "MTM5NzIwNjM4MjQ3MTotMTU5NDE6MTM5NzIwNjM4MjQ3MTo2MjUwMzkyOTY2MjMyMDox",
"like_count": 123,
"liked_it": false,
"reply_to_comment_id": "MTM5NzIwNjMzNjI2MTotODE0MzoxMzk3MjA2MzM2MjYxOjYyNTAzOTI5NjYyMzIwOjE=",
"reply_to_id": "134519031824",
"text": "наверное и я так буду делать!",
"type": "ACTIVE_MESSAGE"}'''
comment = CommentFactory(id='MTM5NzIwNjMzNjI2MTotODE0MzoxMzk3MjA2MzM2MjYxOjYyNTAzOTI5NjYyMzIwOjE=')
author = UserFactory(id=134519031824)
discussion = DiscussionFactory()
instance = Comment(discussion=discussion)
instance.parse(json.loads(response))
instance.save()
self.assertEqual(instance.id, 'MTM5NzIwNjM4MjQ3MTotMTU5NDE6MTM5NzIwNjM4MjQ3MTo2MjUwMzkyOTY2MjMyMDox')
self.assertEqual(instance.object_type, 'ACTIVE_MESSAGE')
self.assertEqual(instance.text, u"наверное и я так буду делать!")
self.assertEqual(instance.likes_count, 123)
self.assertEqual(instance.liked_it, False)
self.assertEqual(instance.author, User.objects.get(pk=538901295641))
self.assertEqual(instance.reply_to_comment, comment)
self.assertEqual(instance.reply_to_author, User.objects.get(pk=134519031824))
self.assertTrue(isinstance(instance.date, datetime))
self.assertTrue(isinstance(instance.attrs, dict))
示例10: post
def post(self):
photo_id = int(self.request.get('pid'))
Author = self.request.get('comment-name')
comment = self.request.get('comment')
photo = Image.get_Detail(photo_id)
logging.error("Author is" + Author)
logging.error(comment)
if Author == '' or comment == '':
pic_id = "/Home#" + str(photo_id)
self.redirect(pic_id)
else:
if photo:
try:
comment = Comment(
Author=Author,
Comment=comment, Image=photo.key)
comment.put()
logging.info("Horray, a comment is saved.")
except:
logging.error("Error saving comment in datastore.")
finally:
pic_id = "/Home#" + str(photo_id)
render = template.render('templates/redirect.html',
{'link': pic_id, 'message': 'Commented'})
self.response.write(render)
示例11: add_comment
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)
示例12: product_page
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)
示例13: add_comment
def add_comment(post_id):
comment = Comment(request.form['text'])
comment.author_id = current_user().id
comment.post_id = post_id
db.session.add(comment)
db.session.commit()
return redirect('/post/' + str(post_id))
示例14: newcomment
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.")
示例15: post_comment
def post_comment(request):
user = request.POST.get('user')
content = request.POST.get('content')
email = request.POST.get('email')
blog_id = request.POST.get('blog_id')
quote = request.POST.get("quote", "").split("###")
#过滤content里面的JS字符
content = content.replace("<", "<").replace(">", "> ")
blog = get_object_or_404(Article, pk=blog_id)
if len(quote) == 3 and \
Comment.objects.filter(pk=quote[2]):
content = u"""
<p>
引用来自<code>%s楼-%s</code>的发言
</p>""" % (quote[0], quote[1]) + content
comment = Comment(
article=blog,
email=email,
name=user,
content=content)
comment.save()
return HttpResponse("%d" % comment.id)