本文整理汇总了Python中models.Page.get_edit_or_404方法的典型用法代码示例。如果您正苦于以下问题:Python Page.get_edit_or_404方法的具体用法?Python Page.get_edit_or_404怎么用?Python Page.get_edit_or_404使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Page
的用法示例。
在下文中一共展示了Page.get_edit_or_404方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: editor
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import get_edit_or_404 [as 别名]
def editor(page_id):
page = Page.get_edit_or_404(page_id)
user = users.get_current_user()
client_id = 'page-%d-%s-%s' % (page_id, user.user_id(), b32encode(os.urandom(10)))
token = gae_channels.create_channel(client_id)
channel = PageChannel(user=user, page=page, token=token, client_id=client_id)
channel.put()
return render_template('editor.html', page=page, channel_token=token)
示例2: page_rpc
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import get_edit_or_404 [as 别名]
def page_rpc(page_id):
page = Page.get_edit_or_404(page_id)
try:
message = json.loads(request.form.get("message", ""))
except Exception:
abort(400)
data = message.get("data", None)
token = message.get("from", None)
if not token or not data:
logging.warn("RPC received no token or data.")
abort(400)
cmd = data.get("cmd", None)
if not cmd:
logging.warn("RPC received no cmd.")
abort(400)
channel = PageChannel.gql("WHERE token=:1", token).get()
if not channel:
# We've timed out the channel. User should refresh the page.
logging.debug("Could not find token: %s", token)
return dict(cmd="refresh")
channel.dt_last_update = datetime.utcnow()
channel.put()
# Commands
if cmd == "open":
page.add_channel(channel)
page.update_locks()
return "OK"
elif cmd == "claimLock":
page.clean_channels()
page.add_channel_first(channel)
page.update_locks()
return "OK"
elif cmd == "save":
style_id = data.get("style_id", "")
style = Style.get_edit_or_404(style_id)
if not style.preview_rev:
preview_rev = StyleRevision(parent=style, rev=style.published_rev.rev + 1)
preview_rev.put()
style.preview_rev = preview_rev
style.put()
log = style.preview_rev.update(data.get("scss", ""))
publish = data.get("fPublish", False)
preview = not publish
if publish:
style.published_rev = style.preview_rev
style.preview_rev = None
style.put()
page_key = str(page.key())
memcache.delete(page_key + "-css")
memcache.delete(page_key + "-css-etag")
page.queue_refresh()
return jsonify({"css": page.compressed_css(preview), "log": log})
else:
logging.warn("Got a bad command: %s", cmd)
abort(400) # Bad cmd
示例3: page_rpc
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import get_edit_or_404 [as 别名]
def page_rpc(page_id):
page = Page.get_edit_or_404(page_id)
try:
message = json.loads(request.form.get('message', ''))
except Exception:
abort(400)
data = message.get('data', None)
token = message.get('from', None)
if not token or not data:
logging.warn('RPC received no token or data.')
abort(400)
cmd = data.get('cmd', None)
if not cmd:
logging.warn('RPC received no cmd.')
abort(400)
channel = PageChannel.gql('WHERE token=:1', token).get()
if not channel:
# We've timed out the channel. User should refresh the page.
logging.debug('Could not find token: %s', token)
return dict(cmd='refresh')
channel.dt_last_update = datetime.utcnow()
channel.put()
# Commands
if cmd == 'open':
page.add_channel(channel)
page.update_locks()
return 'OK'
elif cmd == 'claimLock':
page.clean_channels()
page.add_channel_first(channel)
page.update_locks()
return 'OK'
elif cmd == 'save':
style_id = data.get('style_id', '')
style = Style.get_edit_or_404(style_id)
if not style.preview_rev:
preview_rev = StyleRevision(parent=style, rev=style.published_rev.rev + 1)
preview_rev.put()
style.preview_rev = preview_rev
style.put()
log = style.preview_rev.update(data.get('scss', ''))
publish = data.get('fPublish', False)
preview = not publish
if publish:
style.published_rev = style.preview_rev
style.preview_rev = None
style.put()
page_key = str(page.key())
memcache.delete(page_key + '-css')
memcache.delete(page_key + '-css-etag')
page.queue_refresh()
return jsonify({'css': page.compressed_css(preview), 'log': log})
else:
logging.warn('Got a bad command: %s', cmd)
abort(400) # Bad cmd
示例4: page_import
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import get_edit_or_404 [as 别名]
def page_import(page_id):
page = Page.get_edit_or_404(page_id)
if request.method == 'POST':
if 'fOk' in request.form:
queue_import(page, first_time=True)
return redirect(url_for('page_import', page_id=page_id))
else:
return redirect(url_for('editor', page_id=page_id))
else:
if page.import_state == IMPORT_DONE:
page.import_state = CAN_IMPORT
page.put()
return redirect(url_for('editor', page_id=page_id))
return render_template('page_import.html', page=page)
示例5: page_styles
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import get_edit_or_404 [as 别名]
def page_styles(page_id):
page = Page.get_edit_or_404(page_id)
return Response(page.styles_json(), content_type='application/json')
示例6: page_preview
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import get_edit_or_404 [as 别名]
def page_preview(page_id):
page = Page.get_edit_or_404(page_id)
if page.preview_img:
return _send_file(page.preview_img, 'image/png')
else:
return redirect('/static/img/loading-preview.png')