本文整理汇总了Python中models.Page.get_by方法的典型用法代码示例。如果您正苦于以下问题:Python Page.get_by方法的具体用法?Python Page.get_by怎么用?Python Page.get_by使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Page
的用法示例。
在下文中一共展示了Page.get_by方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: wiki
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import get_by [as 别名]
def wiki(user_slug, wiki_slug):
""" Renders a wiki's main page.
-> user's slugified name; wiki's slugified title
"""
try:
user = User.get_by(name_slug=user_slug)
except NoResultFound:
flash("This user does not exist,<br />\
and consequently, their wiki does not either.")
return redirect(url_for('main'))
try:
wiki = user.wiki_by_slug(wiki_slug)
except NoResultFound:
if user_slug == g.user.name_slug:
flash("This wiki does not exist.")
else:
flash("This wiki either is private or does not exist.")
return redirect(url_for('main'))
if request.method == 'POST':
title = request.form['title']
try:
Page.get_by(title_slug=slugify(title))
except NoResultFound:
page = Page(wiki=wiki, title=title, title_slug=slugify(title),
content="<h1>%s</h1><p></p>" % title)
models.session.commit()
return redirect(url_for('wiki_page', user_slug=user.name_slug,
wiki_slug=wiki.title_slug, page_slug=slugify(title)))
else:
page = wiki.page_by_slug(wiki_slug)
if wiki.permission_to_view(g.user):
return render_template('page.html', user=user, wiki=wiki, page=page)
else:
flash("This wiki either is private or doesn't exist.")
return redirect(url_for('main'))
示例2: dynamic_page
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import get_by [as 别名]
def dynamic_page(self, slug, lang):
""" dynamiczna strona """
page = Page.get_by(slug, lang)
if page is None:
self.abort(404, detail='page not found')
content = page.render_content(dynamic=True)
if not content:
self.abort(404, detail='couldn''t render content')
return content
示例3: refresh_content
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import get_by [as 别名]
def refresh_content(self, slug, lang):
""" wywolywane do odswiezenia strony przy braku w cache """
page = Page.get_by(slug, lang)
if page is None:
self.abort(404)
ok = page.update_cache_content()
if ok:
return self.redirect('/c/%s-%s'%(slug,lang))
else:
self.abort(400)
示例4: static_content
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import get_by [as 别名]
def static_content(self, slug, lang):
""" just return page content """
assert self.app.local, 'powinno dzialac tylko przy local server!'
key = "content-%s-%s"%(slug, lang)
body = memcache.get(key) #@UndefinedVariable
if body:
return body
page = Page.get_by(slug, lang)
if page is None:
self.abort(404)
memcache.set(key, page.content) #@UndefinedVariable
return page.content
示例5: update_index
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import get_by [as 别名]
def update_index(user_slug, wiki_slug):
""" Update the order of pages in the index after a page is moved.
-] page - the name of the moved page
previously_preceding_page - the page that used to be behind 'page'
new_preceding_page - the page that is now behind 'page'
<- a string denoting success
"""
user = User.get_by(name_slug=user_slug)
if user != g.user:
return False
wiki = user.wiki_by_slug(wiki_slug)
f = request.form
ppp_name = f['previously_preceding']
page_name = f['page']
new_preceding_page_name = f['new_preceding']
try:
previously_preceding_page = Page.get_by(wiki=wiki, title=ppp_name)
except NoResultFound:
pass
page = Page.get_by(wiki=wiki, title=page_name)
try:
new_preceding_page = Page.get_by(wiki=wiki,
title=new_preceding_page_name)
except NoResultFound:
pass
if page.id == wiki.first_page_id:
wiki.first_page_id = page.next_page_id
else:
previously_preceding_page.next_page_id = page.next_page_id
if new_preceding_page:
page.next_page_id = new_preceding_page.next_page_id
new_preceding_page.next_page_id = page.id
else:
page.next_page_id = wiki.first_page_id
wiki.first_page_id = page.id
models.session.commit()
return "Success!"
示例6: static_page
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import get_by [as 别名]
def static_page(self, slug, lang):
""" prosto z cache albo odswiezenie cache """
assert self.app.local, 'powinno dzialac tylko przy local server!'
key = "%s-%s"%(slug, lang)
body = memcache.get(key) #@UndefinedVariable
if body:
return body
page = Page.get_by(slug, lang)
if page is None:
self.abort(404)
ok, content = page.update_cache()
if ok:
return content
else:
self.abort(400)
示例7: wiki_settings
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import get_by [as 别名]
def wiki_settings(user_slug, wiki_slug):
""" Updates the settings of a wiki.
-> user's slugified name; wiki's slugified title
"""
try:
user = User.get_by(name_slug=user_slug)
except NoResultFound:
return "error! user does not exist"
if user != g.user:
return "error! unauthorized user"
try:
wiki = user.wiki_by_slug(wiki_slug)
except NoResultFound:
return "error! wiki does not exist"
if request.method == 'POST':
f = request.form
main_page = Page.get_by(wiki=wiki, title=wiki.title)
wiki.title = f['title'] or "Untitled"
wiki.title_slug = slugify(f['title'])
main_page.title = wiki.title
main_page.title_slug = wiki.title_slug
title_start = 4
title_end = 4 + len(main_page.title)
title = re.compile(r"(<h1>)(.*)(</h1>)")
main_page.content = title.sub(r"\1%s\3" % wiki.title,
main_page.content)
publicity = {
'private': 0,
'hidden': 1,
'public': 2
}
if f['publicity'] == 'public' and not user.verified:
wiki.publicity = publicity['hidden']
else:
wiki.publicity = publicity[f['publicity']]
wiki.autosave = 1 if f['autosave'] == 'on' else 0
models.session.commit()
return slugify(f['title'])
else:
publicity = [False]*3
publicity[wiki.publicity] = True
return render_template('settings.html', user=user, wiki=wiki,
publicity=publicity, settings=True)
示例8: save
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import get_by [as 别名]
def save(user_slug, wiki_slug, page_slug):
""" Saves page changes in the database.
-] patch - array of changed content blocks; 'undefined' if unchanged
<- slugified page title
"""
user = User.get_by(name_slug=user_slug)
if user != g.user:
return False
wiki = user.wiki_by_slug(wiki_slug)
try:
page = wiki.page_by_slug(page_slug)
except NoResultFound:
old_last_page = Page.get_by(wiki=wiki, next_page_id=-1)
page = Page(wiki=wiki, title="", title_slug="",
content="<h1>Untitled</h1>", next_page_id=-1)
models.session.commit()
old_last_page.next_page_id = page.id
patch = request.form.getlist('patch')
block = re.compile('<(?:h1|h2|h3|p)>.*?</(?:h1|h2|h3|p)>')
content_blocks = block.findall(page.content)
# If the page's title has been changed in the content...
new_title = page.title
if len(patch) and patch[0] != 'undefined':
new_title = patch[0][4:-5]
newline = re.compile('\n')
new_title = re.sub(newline, "", new_title)
if page.title != new_title:
# ..if a page exists with this title, append " (alternative)" to it.
try:
same_title_page = Page.get_by(title=new_title)
except NoResultFound:
pass
if same_title_page:
stp = same_title_page
header_end = 4 + len(stp.title)
stp.title += " (alternative)"
stp.title_slug = slugify(stp.title)
stp.content = stp.content[:header_end] + " (alternative)" + \
stp.content[header_end:]
# ..if the page with changed title was the main page, make a new one.
if page.title == wiki.title:
try:
if new_title:
second_page = page
else:
second_page = Page.get_by(id=page.next_page_id)
next_page_id = second_page.id
except NoResultFound:
next_page_id = -1
new_main_page = Page(wiki=wiki, title=wiki.title,
title_slug=slugify(wiki.title),
content="<h1>%s</h1><p></p>" % wiki.title,
next_page_id=next_page_id)
models.session.commit()
wiki.first_page_id = new_main_page.id
# ..change the page's title in the database.
page.title = new_title
page.title_slug = slugify(new_title)
# Replace content with patched content.
for i, block in enumerate(patch):
if block != 'undefined':
if i < len(content_blocks):
content_blocks[i] = block
else:
content_blocks.append(block)
# Sanitize unsafe angle brackets.
content = ''.join(content_blocks)
unsafe_lt = re.compile(r"<(?!/?(h1|h2|h3|p|b|i|u)>)")
content = re.sub(unsafe_lt, '<', content)
# The content is reversed to get around regex lookbehind limitation.
unsafe_gt = re.compile(r">(?!(1h|2h|3h|p|b|i|u)/?<)")
content = re.sub(unsafe_gt, ';tg&', content[::-1])
page.content = content[::-1]
# If the title is blank, delete the page.
deleted = False
blank_title = re.compile('<h1>(<br>)*</h1>')
if blank_title.match(page.content):
try:
previous_page = Page.get_by(wiki=wiki, next_page_id=page.id)
previous_page.next_page_id = page.next_page_id
except NoResultFound:
pass
page.delete()
deleted = True
# Update the wiki's update date.
wiki.update_date = datetime.now()
# Commit to database!
models.session.commit()
if not deleted:
return slugify(page.title)
else:
return "untitled!"
示例9: edit_page
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import get_by [as 别名]
def edit_page(self, slug, lang):
""" pomocnicza edycja strone z iframe z google-docs """
page = Page.get_by(slug, lang)
return self.render('admin/edit_page.html', page=page)
示例10: update_page
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import get_by [as 别名]
def update_page(self, slug, lang):
""" odswiezenie contentu jednej strony """
page = Page.get_by(slug, lang)
page.update_content()
self.set_flash(u'Treść zakutalizowana i cache odświeżony.')
return self._redirect_to_pages()
示例11: dynamic_content
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import get_by [as 别名]
def dynamic_content(self, slug, lang):
page = Page.get_by(slug, lang)
return page.content