本文整理汇总了Python中models.Page.query方法的典型用法代码示例。如果您正苦于以下问题:Python Page.query方法的具体用法?Python Page.query怎么用?Python Page.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Page
的用法示例。
在下文中一共展示了Page.query方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import query [as 别名]
def get(self):
template = JINJA_ENVIRONMENT.get_template('blog.html')
if self.request.get('id'):
pages = Page.query(Page.allowed == 0,
Page.slug == self.request.get('id')).fetch(1)
else:
pages = Page.query(Page.allowed == 0).order(-Page.when).fetch(10)
self.response.write(
template.render({'pages':pages})
)
示例2: post
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import query [as 别名]
def post(self,slug):
page = Page.query(Page.slug == slug).get()
if page:
page.slug = slug
page.title = self.request.get('title')
page.text = self.request.get('text')
page.prev = self.request.get('prev')
page.next = self.request.get('next')
page.doc = self.request.get('doc')
page.allowed = int(self.request.get('level'))
page.put()
self.redirect('/content/{}'.format(slug))
else:
page = Page(title = self.request.get('title'),
slug = slug,
author = users.get_current_user(),
text = self.request.get('text'),
prev = self.request.get('prev'),
next = self.request.get('next'),
doc = self.request.get('doc'),
allowed = int(self.request.get('level'))
)
page.put()
self.redirect('/content/{}'.format(slug))
示例3: get
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import query [as 别名]
def get(self, story_id, page_id):
story, page = self.story_page(story_id, page_id, is_author=True)
pages = list(Page.query(ancestor=story.key))
self.render_html('edit.html',
story=story,
page=page,
pages=pages)
示例4: get
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import query [as 别名]
def get(self, locale_id):
page = Page.query(Page.locale==ndb.Key(Locale, locale_id), Page.menu==ndb.Key(Menu, "the-manor")).fetch()
if len(page) == 0:
self.abort(404)
self.redirect('/{0}/{1}'.format(locale_id, page[0].key.id()))
示例5: get_pages
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import query [as 别名]
def get_pages(self, locale_id):
pages = memcache.get("pages {0}".format(locale_id))
if pages is None:
pages = Page.query(Page.locale==ndb.Key(Locale, locale_id)).fetch()
if not pages:
return None
memcache.set(key="pages {0}".format(locale_id), value=pages)
return pages
示例6: fetch_pages
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import query [as 别名]
def fetch_pages(self):
queue = taskqueue.Queue('facebook')
keys = Page.query().fetch(keys_only=True)
for key in keys:
task = taskqueue.Task(
url='/worker/fetch_page',
params={
'key': key.urlsafe(),
}
)
queue.add(task)
示例7: get_navigation_pages
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import query [as 别名]
def get_navigation_pages(self):
"""Returns the pages to be included in the navigation bar"""
navigation_pages = memcache.get('navigation_pages')
if navigation_pages is not None:
return navigation_pages
else:
query = Page.query(Page.appear_in_navigation == True)
#TODO: Change the fetch limit or document that it'll only fetch 10
navigation_pages = query.fetch()
if not memcache.set('navigation_pages', navigation_pages):
logging.error('Write to memcache failed!')
return navigation_pages
示例8: get
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import query [as 别名]
def get(self):
q = Page.query()
logging.info('Starting Dispatch process')
for page in q.iter():
logging.info('Adding task to the queue to proccess '
'%s Web Page' % page.name)
logging.info('urlsafe key %s' % page.key.urlsafe())
taskqueue.add(url='/task/ping',
queue_name='ping',
params={'key': page.key.urlsafe()})
示例9: store_pages
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import query [as 别名]
def store_pages(self, route_handlers):
"""Stores information on each handler in the datastore and returns a list
of routes for the Router.
:param routes_handler:
A list of FrameworkHandler subclasses which identify routes and
their meta data.
:returns:
A list of webapp2.Route instance.
"""
memcache.delete('navigation_pages')
routes = []
new_key_set = set()
for route_handler in route_handlers:
# Checks if datastore entry exits and uses if it is.
query = Page.query(Page.url == route_handler.url)
datastore_list = query.fetch(1)
if datastore_list:
datastore_entity = datastore_list[0]
else:
datastore_entity = Page()
datastore_entity.url = route_handler.url
datastore_entity.page_title = route_handler.page_title
datastore_entity.appear_in_navigation = route_handler.appear_in_navigation
#TODO: Not write to the datastore if there are no changes to be made
datastore_entity.put()
new_key_set.add(datastore_entity.key)
# Creates a route for each handler and adds it to the routes list
routes.append(webapp2.Route(route_handler.url, route_handler))
# The following removes old pages from the datastore
old_key_set = set(Page.query().fetch(keys_only=True))
ndb.delete_multi(list(old_key_set - new_key_set))
return routes
示例10: process_text_admin
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import query [as 别名]
def process_text_admin(text):
# Process the small markup here.
slugs = re.findall(r"#(\w+)",text)
replacements = list()
for slug in slugs:
page = Page.query(Page.slug == slug).fetch(1)
if page:
replacements.append('content')
replacements.append('<i class="fa fa-external-link-square"></i>')
else:
replacements.append('content')
replacements.append('<i class="fa fa-edit"></i>')
newtext = re.sub(r"#(\w+)", '<a href="/{}/\g<1>">{}</a>', text)
return newtext.format(*replacements)
示例11: get
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import query [as 别名]
def get(self):
sources = Page.query().fetch()
self.render_template('sources.html', sources=sources)