本文整理汇总了Python中models.Comment.query方法的典型用法代码示例。如果您正苦于以下问题:Python Comment.query方法的具体用法?Python Comment.query怎么用?Python Comment.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Comment
的用法示例。
在下文中一共展示了Comment.query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: comment_list
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import query [as 别名]
def comment_list(self, offset_count):
index = 0
viewer = self.user_model
# Need to see if user has friends, if not - Query using viewer.friends will break #
if viewer.friends:
comments = Comment.query(Comment.root==True, ndb.OR(Comment.sender_key.IN(viewer.friends),
Comment.recipient_key.IN(viewer.friends), Comment.sender_key == viewer.key)).order(-Comment.time).fetch(10, offset=offset_count)
else:
comments = Comment.query(Comment.root==True, Comment.sender_key == viewer.key).order(-Comment.time).fetch(10, offset=offset_count)
more = len(comments)
while index < len(comments):
children = Comment.query(Comment.parent == comments[index].key).fetch()
index += 1
comments[index:index] = children
return comments, more
示例2: get_comments_html
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import query [as 别名]
def get_comments_html(theme, owner, result="", level=0, item_template='comment', margin=SUBCOMMENT_LEFT_MARGIN, desc=False):
comments = Comment.query().filter(owner=owner)
if desc:
comments = comments.order_by('-created')
for comment in comments:
result += get_comments_html(theme, comment, get_single_comment_html(comment, level, theme, item_template, margin), level+1, item_template, margin, desc) #recursively render subcomments
return result
示例3: get
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import query [as 别名]
def get(self, album_id):
user = get_user()
album = Album.get_by_id(
int(album_id),
DEFAULT_DOMAIN_KEY
)
if album:
upload_url = blobstore.create_upload_url('/album/%s/upload-photo' % album_id)
photo_query = Photo.query(
ancestor=album.key
)
comments_query = Comment.query(
Comment.parent == album.key
).order(-Comment.date_created)
template_values = {
'user': user,
'album': album,
'photos': photo_query.fetch(None),
'comments': comments_query.fetch(None),
'upload_url': upload_url,
}
self.render_template('view_album.html', template_values)
else:
self.raise_error(404)
示例4: get
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import query [as 别名]
def get(self, post_urlsafe_key):
post = self.get_by_urlsafe(post_urlsafe_key, Post)
comments = Comment.query(ancestor=post.key).fetch()
if self.format == 'html':
self.render('post.html', post=post, comments=comments)
else:
self.render_json(d=post.serialize)
示例5: comment_list
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import query [as 别名]
def comment_list(self, request):
"""
Returns:
An instance of CommentListResponse.
"""
items = [entity.to_message() for entity in Comment.query()]
return CommentListResponse(items=items)
示例6: getArticleComments
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import query [as 别名]
def getArticleComments(self, request):
"""Return all comments for an article"""
# check that websafeArticleKey is a Article key and it exists
a_key = self._checkKey(request.websafeArticleKey, 'Article')
comments = Comment.query(ancestor=a_key)
return CommentForms(items=[self._copyCommentToForm(comment, article_key=a_key) for comment in comments])
示例7: get
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import query [as 别名]
def get(self, forum_id, post_reference):
user = self.user_model
post = ForumPost.query(ForumPost.forum_name == forum_id, ForumPost.reference == post_reference).get()
comments = Comment.query(Comment.parent==post.key).fetch()
# Get nested Comments
index = 0
while index < len(comments):
children = Comment.query(Comment.parent == comments[index].key).fetch()
index +=1
comments[index:index] = children
if user == None:
override_base = "visitorBase.html"
else:
override_base = "base.html"
self.response.out.write(template.render('views/forumComments.html',
{'override_base':override_base, 'viewer': user, 'post':post,
'forum_name':forum_id, 'comments':comments, 'post_reference':post_reference}))
示例8: getComment
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import query [as 别名]
def getComment(article_id, comment_id):
return serialize(
Comment.query(
ndb.AND(
Comment.article == ndb.Key(Article, article_id),
Comment.key == ndb.Key(Comment, comment_id)
)
).get()
)
示例9: sharepoint_delete
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import query [as 别名]
def sharepoint_delete(self, sharepoint):
""" Delete the sharepoint with the entityKey, plus all the associated comments"""
if not sharepoint.from_datastore:
raise endpoints.NotFoundException("No Sharepoint found for the given key")
children = Comment.query(Comment.sharepoint_key == sharepoint.key)
for comment in children:
comment.key.delete()
sharepoint.key.delete()
return Sharepoint(title="deleted")
示例10: get
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import query [as 别名]
def get(self):
archive = memcache.get('archive')
if archive is not None:
self.response.out.headers['Content-Type'] = 'application/json'
self.response.out.write(json.dumps({'articles':archive}))
else:
more = True
archive = OrderedDict()
curs = None
while more:
articles, curs, more = Article.query().order(
-Article.when).fetch_page(
50,
start_cursor=curs,
projection=[Article.title,
Article.when,
Article.keywords])
for article in articles:
article_key = article.key.urlsafe()
if article_key in archive:
archive[article_key]['keywords'].extend(
article.keywords)
else:
archive[article_key] = {
'title': article.title,
'when': article.when.strftime("%d/%m/%Y %H:%M:%S"),
'keywords': article.keywords,
'key': article_key,
'ncomments': 0}
more = True
curs = None
while more:
page, curs, more = Comment.query().fetch_page(
100,
start_cursor = curs)
for comment in page:
parent_key = comment.key.parent().urlsafe()
if parent_key in archive:
archive[parent_key]['ncomments'] += 1
memcache.add('archive',
[a for a in archive.itervalues()],
time=86400)
self.response.out.headers['Content-Type'] = 'application/json'
self.response.out.write(json.dumps(
{'articles':[a for a in archive.itervalues()]}
))
示例11: get
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import query [as 别名]
def get(self):
self.response.headers['Content-Type'] = 'application/json'
self.response.out.write("[")
# pull the id parameter from the query string
# this holds the urlsafe key for a specific parking lot
lot_id = self.request.get('lot_id')
lot_key = ndb.Key(urlsafe=lot_id)
# get account
acc = self.get_account()
# check if lot is in favorites
if lot_key not in acc.parking_lots:
acc.parking_lots.append(lot_key)
acc.put()
# get comments on lot
comments = Comment.query(
Comment.lot_key == lot_key,
# filter out any comments older than a day
Comment.date > datetime.utcnow() - timedelta(days=1)
).order(-Comment.date)
for c in comments:
seconds_passed = (datetime.now() - c.date).total_seconds()
passed = ""
end = ""
# recent is no older than 15 minutes (ie < 16 minutes)
if seconds_passed < 60 * 16:
c.recent = True
# compute seconds when under a minute has passed
if seconds_passed < 60:
passed = str(int(seconds_passed))
end = " seconds ago"
# compute minutes when under an hour has passed
elif seconds_passed < 3600:
passed = str(int(seconds_passed / 60))
end = " minutes ago"
if seconds_passed < 120:
end = " minute ago"
# compute hours when under a day has passed
elif seconds_passed < 3600 * 24:
passed = str(int(seconds_passed) / 3600)
end = " hours ago"
if seconds_passed < 7200:
end = " hour ago"
else:
passed = str(int(seconds_passed) / (3600*24))
end = " days ago"
if seconds_passed < 3600 * 48:
end = " day ago"
c.time = passed + end
self.response.out.write(serialize(c) + ",")
self.response.out.write("{}")
self.response.out.write("]")
示例12: get
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import query [as 别名]
def get(self):
post_id = int(self.request.get('id'))
post = Post.get_by_id(post_id)
comment_query = Comment.query().filter(Comment.post==post.key).order(-Comment.time).fetch()
output = ''
for comment in comment_query:
output += '<div class="ui-bar ui-bar-a"><h3>'
output += comment.author
output += ' said...</h3></div>'
output += '<div class="ui-body ui-body-a"><p>'
output += comment.content
output += '</p></div><br>'
self.response.out.write(output)
示例13: comment_search
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import query [as 别名]
def comment_search(self, request):
"""
Arguments:
CommentRequestMessage, with content used for search
Returns:
An instance of CommentListResponse.
"""
term = request.content or ""
comment_search = search.Index(SEARCH_INDEX).search(term)
comment_keys = [ndb.Key(Comment, int(x.doc_id)) for x in comment_search.results]
q = Comment.query().filter(Comment._key.IN(comment_keys))
items = [entity.to_message() for entity in q.iter()]
return CommentListResponse(items=items)
示例14: getMyComments
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import query [as 别名]
def getMyComments(self, request):
"""Return comments created by current user"""
author = self._getAuthorFromUser()
if not author:
raise endpoints.UnauthorizedException('%s is not an author of any articles or comments' % user.nickname())
comments = Comment.query().filter(Comment.authorID==author.authorID)
# return set of CommentForm objects per Comment
return CommentForms(
items=[self._copyCommentToForm(comment, author=author) for comment in comments]
)
示例15: postComment
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import query [as 别名]
def postComment(article_id):
article = Article.get_by_id(article_id)
if not article:
return "", 404, {"Content-Type": "application/json"}
data = request.get_json()
if not data:
return "Missing data", 400
comment = Comment()
comment.article = article.key
comment.author_name = escape(data.get("author_name"))
comment.author_email = escape(data.get("author_email"))
comment.content = escape(data.get("content"))
comment.put()
comments = Comment.query().order(Comment.date).fetch(keys_only=True)
if len(comments) >= 10:
comments[0].delete()
return serialize(comment)