本文整理汇总了Python中models.BlogPost.query方法的典型用法代码示例。如果您正苦于以下问题:Python BlogPost.query方法的具体用法?Python BlogPost.query怎么用?Python BlogPost.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.BlogPost
的用法示例。
在下文中一共展示了BlogPost.query方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_subscribe
# 需要导入模块: from models import BlogPost [as 别名]
# 或者: from models.BlogPost import query [as 别名]
def test_subscribe(self):
expected = {
"hub.mode": "subscribe",
"hub.topic": "fake feed url",
"hub.callback": "http://localhost/fake/notify/foo.com",
"format": "json",
"retrieve": "true",
}
item_a = {"permalinkUrl": "A", "content": "a http://a.com a"}
item_b = {"permalinkUrl": "B", "summary": "b http://b.com b"}
feed = json.dumps({"items": [item_a, {}, item_b]})
self.expect_requests_post(superfeedr.PUSH_API_URL, feed, data=expected, auth=mox.IgnoreArg())
self.mox.ReplayAll()
superfeedr.subscribe(self.source, self.handler)
posts = list(BlogPost.query())
self.assert_entities_equal(
[
BlogPost(id="A", source=self.source.key, feed_item=item_a, unsent=["http://a.com"]),
BlogPost(id="B", source=self.source.key, feed_item=item_b, unsent=["http://b.com"]),
],
posts,
ignore=("created", "updated"),
)
tasks = self.taskqueue_stub.GetTasks("propagate-blogpost")
self.assert_equals(
[{"key": posts[0].key.urlsafe()}, {"key": posts[1].key.urlsafe()}],
[testutil.get_task_params(t) for t in tasks],
)
示例2: assert_blogposts
# 需要导入模块: from models import BlogPost [as 别名]
# 或者: from models.BlogPost import query [as 别名]
def assert_blogposts(self, expected):
got = list(BlogPost.query())
self.assert_entities_equal(expected, got, ignore=('created', 'updated'))
tasks = self.taskqueue_stub.GetTasks('propagate-blogpost')
self.assert_equals([{'key': post.key.urlsafe()} for post in expected],
[testutil.get_task_params(t) for t in tasks])
示例3: test_subscribe
# 需要导入模块: from models import BlogPost [as 别名]
# 或者: from models.BlogPost import query [as 别名]
def test_subscribe(self):
expected = {
'hub.mode': 'subscribe',
'hub.topic': 'fake feed url',
'hub.callback': 'http://localhost/fake/notify/foo.com',
'format': 'json',
'retrieve': 'true',
}
item_a = {'permalinkUrl': 'A', 'content': 'a http://a.com a'}
item_b = {'permalinkUrl': 'B', 'summary': 'b http://b.com b'}
feed = json.dumps({'items': [item_a, {}, item_b]})
self.expect_requests_post(superfeedr.PUSH_API_URL, feed,
data=expected, auth=mox.IgnoreArg())
self.mox.ReplayAll()
superfeedr.subscribe(self.source, self.handler)
posts = list(BlogPost.query())
self.assert_entities_equal(
[BlogPost(id='A', source=self.source.key, feed_item=item_a,
unsent=['http://a.com']),
BlogPost(id='B', source=self.source.key, feed_item=item_b,
unsent=['http://b.com']),
], posts,
ignore=('created', 'updated'))
tasks = self.taskqueue_stub.GetTasks('propagate-blogpost')
self.assert_equals([{'key': posts[0].key.urlsafe()},
{'key': posts[1].key.urlsafe()}],
[testutil.get_task_params(t) for t in tasks])
示例4: get
# 需要导入模块: from models import BlogPost [as 别名]
# 或者: from models.BlogPost import query [as 别名]
def get(self, slug):
blog_post = BlogPost.query(BlogPost.slug == slug).get()
# markdown
markdowner = markdown2.Markdown()
blog_post.text = markdowner.convert(blog_post.text)
params = {"blog": blog_post}
self.render_template('blogpost.html', params)
示例5: test_handle_feed_unwraps_t_umblr_com_links
# 需要导入模块: from models import BlogPost [as 别名]
# 或者: from models.BlogPost import query [as 别名]
def test_handle_feed_unwraps_t_umblr_com_links(self):
item = {
'permalinkUrl': 'A',
'id': 'A',
'content': 'x <a href="http://t.umblr.com/redirect?z=http%3A%2F%2Fwrap%2Fped&t=YmZkMzQy..."></a> y',
}
superfeedr.handle_feed(json.dumps({'items': [item]}), self.source)
posts = list(BlogPost.query())
self.assert_blogposts([BlogPost(id='A', source=self.source.key,
feed_item=item, unsent=['http://wrap/ped'])])
示例6: test_preprocess_superfeedr_item
# 需要导入模块: from models import BlogPost [as 别名]
# 或者: from models.BlogPost import query [as 别名]
def test_preprocess_superfeedr_item(self):
self.mox.StubOutWithMock(self.source, 'preprocess_superfeedr_item')
def add_link(item):
item['content'] += '\nhttp://added/by/preprocess'
self.source.preprocess_superfeedr_item(self.item).WithSideEffects(add_link)
self.mox.ReplayAll()
superfeedr.handle_feed(self.feed, self.source)
self.assertEquals(['http://added/by/preprocess'], BlogPost.query().get().unsent)
示例7: test_handle_feed_cleans_links
# 需要导入模块: from models import BlogPost [as 别名]
# 或者: from models.BlogPost import query [as 别名]
def test_handle_feed_cleans_links(self):
item = {
'permalinkUrl': 'A',
'id': 'A',
'content': 'x <a href="http://abc?source=rss----12b80d28f892---4',
}
superfeedr.handle_feed(json.dumps({'items': [item]}), self.source)
posts = list(BlogPost.query())
self.assert_blogposts([BlogPost(id='A', source=self.source.key,
feed_item=item, unsent=['http://abc'])])
示例8: test_handle_feed
# 需要导入模块: from models import BlogPost [as 别名]
# 或者: from models.BlogPost import query [as 别名]
def test_handle_feed(self):
item_a = {'permalinkUrl': 'A',
'content': 'a http://a.com http://foo.com/self/link b'}
superfeedr.handle_feed(json.dumps({'items': [item_a]}), self.source)
posts = list(BlogPost.query())
self.assert_entities_equal(
[BlogPost(id='A', source=self.source.key, feed_item=item_a,
unsent=['http://a.com'])], # self link should be discarded
posts,
ignore=('created', 'updated'))
tasks = self.taskqueue_stub.GetTasks('propagate-blogpost')
self.assertEqual(1, len(tasks))
self.assert_equals(posts[0].key.urlsafe(),
testutil.get_task_params(tasks[0])['key'])
示例9: test_handle_feed
# 需要导入模块: from models import BlogPost [as 别名]
# 或者: from models.BlogPost import query [as 别名]
def test_handle_feed(self):
item_a = {"permalinkUrl": "A", "content": "a http://a.com http://foo.com/self/link b"}
superfeedr.handle_feed(json.dumps({"items": [item_a]}), self.source)
posts = list(BlogPost.query())
self.assert_entities_equal(
[
BlogPost(id="A", source=self.source.key, feed_item=item_a, unsent=["http://a.com"])
], # self link should be discarded
posts,
ignore=("created", "updated"),
)
tasks = self.taskqueue_stub.GetTasks("propagate-blogpost")
self.assertEqual(1, len(tasks))
self.assert_equals(posts[0].key.urlsafe(), testutil.get_task_params(tasks[0])["key"])
示例10: template_vars
# 需要导入模块: from models import BlogPost [as 别名]
# 或者: from models.BlogPost import query [as 别名]
def template_vars(self):
vars = super(UserHandler, self).template_vars()
vars.update({
'source': self.source,
'EPOCH': util.EPOCH,
'REFETCH_HFEED_TRIGGER': models.REFETCH_HFEED_TRIGGER,
'RECENT_PRIVATE_POSTS_THRESHOLD': RECENT_PRIVATE_POSTS_THRESHOLD,
})
if not self.source:
return vars
if isinstance(self.source, instagram.Instagram):
auth = self.source.auth_entity
vars['indieauth_me'] = (
auth.id if isinstance(auth, indieauth.IndieAuth)
else self.source.domain_urls[0] if self.source.domain_urls
else None)
# Blog webmention promos
if 'webmention' not in self.source.features:
if self.source.SHORT_NAME in ('blogger', 'tumblr', 'wordpress'):
vars[self.source.SHORT_NAME + '_promo'] = True
else:
for domain in self.source.domains:
if ('.blogspot.' in domain and # Blogger uses country TLDs
not Blogger.query(Blogger.domains == domain).get()):
vars['blogger_promo'] = True
elif (domain.endswith('tumblr.com') and
not Tumblr.query(Tumblr.domains == domain).get()):
vars['tumblr_promo'] = True
elif (domain.endswith('wordpress.com') and
not WordPress.query(WordPress.domains == domain).get()):
vars['wordpress_promo'] = True
# Responses
if 'listen' in self.source.features:
vars['responses'] = []
query = Response.query().filter(Response.source == self.source.key)
# if there's a paging param (responses_before or responses_after), update
# query with it
def get_paging_param(param):
val = self.request.get(param)
try:
return util.parse_iso8601(val) if val else None
except:
msg = "Couldn't parse %s %r as ISO8601" % (param, val)
logging.exception(msg)
self.abort(400, msg)
before = get_paging_param('responses_before')
after = get_paging_param('responses_after')
if before and after:
self.abort(400, "can't handle both responses_before and responses_after")
elif after:
query = query.filter(Response.updated > after).order(Response.updated)
elif before:
query = query.filter(Response.updated < before).order(-Response.updated)
else:
query = query.order(-Response.updated)
query_iter = query.iter()
for i, r in enumerate(query_iter):
r.response = json.loads(r.response_json)
r.activities = [json.loads(a) for a in r.activities_json]
if (not self.source.is_activity_public(r.response) or
not all(self.source.is_activity_public(a) for a in r.activities)):
continue
elif r.type == 'post':
r.activities = []
r.actor = r.response.get('author') or r.response.get('actor', {})
for a in r.activities + [r.response]:
if not a.get('content'):
a['content'] = a.get('object', {}).get('content')
if not r.response.get('content'):
phrases = {
'like': 'liked this',
'repost': 'reposted this',
'rsvp-yes': 'is attending',
'rsvp-no': 'is not attending',
'rsvp-maybe': 'might attend',
'rsvp-interested': 'is interested',
'invite': 'is invited',
}
r.response['content'] = '%s %s.' % (
r.actor.get('displayName') or '',
phrases.get(r.type) or phrases.get(r.response.get('verb')))
# convert image URL to https if we're serving over SSL
image_url = r.actor.setdefault('image', {}).get('url')
if image_url:
r.actor['image']['url'] = util.update_scheme(image_url, self)
# generate original post links
r.links = self.process_webmention_links(r)
r.original_links = [util.pretty_link(url, new_tab=True)
#.........这里部分代码省略.........
示例11: assert_blogposts
# 需要导入模块: from models import BlogPost [as 别名]
# 或者: from models.BlogPost import query [as 别名]
def assert_blogposts(self, count):
self.assertEquals(count, BlogPost.query().count())
self.assertEquals(count, len(self.taskqueue_stub.GetTasks('propagate-blogpost')))
示例12: template_vars
# 需要导入模块: from models import BlogPost [as 别名]
# 或者: from models.BlogPost import query [as 别名]
def template_vars(self):
if not self.source:
return {}
vars = super(UserHandler, self).template_vars()
vars.update({
'source': self.source,
'epoch': util.EPOCH,
})
# Blog webmention promos
if 'webmention' not in self.source.features:
if self.source.SHORT_NAME in ('blogger', 'tumblr', 'wordpress'):
vars[self.source.SHORT_NAME + '_promo'] = True
else:
for domain in self.source.domains:
if ('.blogspot.' in domain and # Blogger uses country TLDs
not Blogger.query(Blogger.domains == domain).get()):
vars['blogger_promo'] = True
elif (domain.endswith('tumblr.com') and
not Tumblr.query(Tumblr.domains == domain).get()):
vars['tumblr_promo'] = True
elif (domain.endswith('wordpress.com') and
not WordPress.query(WordPress.domains == domain).get()):
vars['wordpress_promo'] = True
# Responses
if 'listen' in self.source.features:
vars['responses'] = []
for i, r in enumerate(Response.query()
.filter(Response.source == self.source.key)\
.order(-Response.updated)):
r.response = json.loads(r.response_json)
if r.activity_json: # handle old entities
r.activities_json.append(r.activity_json)
r.activities = [json.loads(a) for a in r.activities_json]
if (not gr_source.Source.is_public(r.response) or
not all(gr_source.Source.is_public(a) for a in r.activities)):
continue
r.actor = r.response.get('author') or r.response.get('actor', {})
if not r.response.get('content'):
phrases = {
'like': 'liked this',
'repost': 'reposted this',
'rsvp-yes': 'is attending',
'rsvp-no': 'is not attending',
'rsvp-maybe': 'might attend',
'invite': 'is invited',
}
r.response['content'] = '%s %s.' % (
r.actor.get('displayName') or '',
phrases.get(r.type) or phrases.get(r.response.get('verb')))
# convert image URL to https if we're serving over SSL
image_url = r.actor.setdefault('image', {}).get('url')
if image_url:
r.actor['image']['url'] = util.update_scheme(image_url, self)
# generate original post links
r.links = self.process_webmention_links(r)
vars['responses'].append(r)
if len(vars['responses']) >= 10 or i > 200:
break
# Publishes
if 'publish' in self.source.features:
publishes = Publish.query().filter(Publish.source == self.source.key)\
.order(-Publish.updated)\
.fetch(10)
for p in publishes:
p.pretty_page = util.pretty_link(
p.key.parent().id(), a_class='original-post', new_tab=True)
vars['publishes'] = publishes
if 'webmention' in self.source.features:
# Blog posts
blogposts = BlogPost.query().filter(BlogPost.source == self.source.key)\
.order(-BlogPost.created)\
.fetch(10)
for b in blogposts:
b.links = self.process_webmention_links(b)
try:
text = b.feed_item.get('title')
except ValueError:
text = None
b.pretty_url = util.pretty_link(b.key.id(), text=text,
a_class='original-post', max_length=40,
new_tab=True)
# Blog webmentions
webmentions = BlogWebmention.query()\
.filter(BlogWebmention.source == self.source.key)\
.order(-BlogWebmention.updated)\
.fetch(10)
for w in webmentions:
w.pretty_source = util.pretty_link(w.source_url(), a_class='original-post',
#.........这里部分代码省略.........
示例13: get
# 需要导入模块: from models import BlogPost [as 别名]
# 或者: from models.BlogPost import query [as 别名]
def get(self, slug):
post = BlogPost.query(BlogPost.slug == slug).get()
comments = Comment.query(Comment.blog_post == post.key).fetch(limit=10)
self.render_response("display_post.html", post=post, comments=comments)