本文整理汇总了Python中models.Page.objects方法的典型用法代码示例。如果您正苦于以下问题:Python Page.objects方法的具体用法?Python Page.objects怎么用?Python Page.objects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Page
的用法示例。
在下文中一共展示了Page.objects方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: show_pages
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import objects [as 别名]
def show_pages():
if request.method == "POST" and g.site.domain == g.user:
name = request.form['name']
if name:
p = Page()
p.name = name
p.slug = slugify(name)
p.site = g.site.domain
p.save()
return redirect(url_for(".edit_page", slug=p.slug))
pages = Page.objects(site=g.site.domain)
return render_template('pages.html', pages=pages)
示例2: rebuild_url_lookup
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import objects [as 别名]
def rebuild_url_lookup():
''' Rebuld URL lookup data'''
print "Rebuilding URL"
env = __open_env()
urls = env.open_db('urls')
with env.begin(db=urls, write=True) as txn:
cursor = txn.cursor()
for k, v in cursor:
txn.delete(k)
for item in Page.objects():
t = item.url.encode('utf-8')
txn.put(t, '1')
print "Done"
env.close()
示例3: search
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import objects [as 别名]
def search(query, field, start=0, size=100, recommend=False, fuzzy=False, highlight=None):
'''
Perform Elasticsearch index lookup for documents with given parameters
:param query: text to be searched for
:type query: str
:param field: field to be searched
:type field: str
:param start: offset for results presentation
:type start: int
:param size: how many documents to present
:type size: int
:param recommend: fill in document's recommendations
:type recommend: bool
:param fuzzy: perform fuzzy search
:type fuzzy: bool
:param highlight: highlight query in result document
:type highlight: bool
:returns: number of results and results
:rtype: tuple (nrOfResults, results)
'''
body = {
"from": start,
'query': {}
}
if size > 0:
body['size'] = size
query = re.sub(r'[/:]', '\\/', query)
body['query']['query_string'] = {"fields": [field], "query": query, "default_operator": "AND"}
if fuzzy:
body['query']['query_string']['fuzziness'] = 'AUTO' # is default - can be ommited
else:
body['query']['query_string']['fuzziness'] = 0 # or 1 - both should be ok
if highlight and len(highlight) is 2:
body['highlight'] = {
"pre_tags": [highlight[0]],
"post_tags": [highlight[1]],
"fields": {
field: {}
}
}
# print body
res = Elasticsearch().search(index=INDEX_NAME, body=body)
# print res
pres = []
for r in res['hits']['hits']:
hit = Page.objects(id=r['_source']['_id']).first()
if hit:
if highlight and len(highlight) is 2:
hit.btext = '<br><br>'.join(r['highlight']['btext'])
pres.append(hit)
fin = []
for page in pres:
tmp = []
if recommend:
if page.parent:
for r in page.parent.recs:
x = [r.url, r.title]
tmp.append(x)
else:
for r in page.recs:
x = [r.url, r.url]
tmp.append(x)
fin.append([page, tmp])
return (res['hits']['total'], fin)