本文整理汇总了Python中models.Server.get_by_short_name方法的典型用法代码示例。如果您正苦于以下问题:Python Server.get_by_short_name方法的具体用法?Python Server.get_by_short_name怎么用?Python Server.get_by_short_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Server
的用法示例。
在下文中一共展示了Server.get_by_short_name方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_home_redirect
# 需要导入模块: from models import Server [as 别名]
# 或者: from models.Server import get_by_short_name [as 别名]
def get_home_redirect(handler, *args, **kwargs):
short_name = kwargs.get('short_name', None)
if not short_name:
return handler.uri_for('main')
server = Server.get_by_short_name(short_name)
if not server:
return handler.uri_for('main')
return handler.uri_for('home', server_key=server.short_name)
示例2: get_server_by_key
# 需要导入模块: from models import Server [as 别名]
# 或者: from models.Server import get_by_short_name [as 别名]
def get_server_by_key(self, key, abort=True):
if key:
try:
server_key = ndb.Key(urlsafe=key)
server = server_key.get()
except Exception:
server = Server.get_by_short_name(key)
else:
server = None
if server is not None and not server.active:
server = None
if abort and not server:
self.abort(404)
self.request.server = server
return self.request.server
示例3: __call__
# 需要导入模块: from models import Server [as 别名]
# 或者: from models.Server import get_by_short_name [as 别名]
def __call__(self, form, field):
server = self.server or form.server
short_name = field.data
key = None
try:
key = ndb.Key(urlsafe=short_name)
except:
pass
if key is not None:
raise validators.ValidationError("Short name can't be a valid key string".format(short_name))
s = Server.get_by_short_name(short_name)
if s is not None:
if server is None or s.key != server.key:
raise validators.ValidationError(
"Short name '{0}' is already assigned to another server".format(short_name)
)