本文整理汇总了Python中model.Task.get_by_key_name方法的典型用法代码示例。如果您正苦于以下问题:Python Task.get_by_key_name方法的具体用法?Python Task.get_by_key_name怎么用?Python Task.get_by_key_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.Task
的用法示例。
在下文中一共展示了Task.get_by_key_name方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_task
# 需要导入模块: from model import Task [as 别名]
# 或者: from model.Task import get_by_key_name [as 别名]
def get_task(domain, task):
"""Gets a task in a domain.
Args:
domain: The domain identifier
task: The task key id or name. Can either be an int
or a string.
Returns:
A task instance or None if no task exists.
"""
domain_key = Domain.key_from_name(domain)
try:
task_id = int(task)
return Task.get_by_id(task_id, parent=domain_key)
except ValueError:
return Task.get_by_key_name(task, parent=domain_key)
示例2: get_task
# 需要导入模块: from model import Task [as 别名]
# 或者: from model.Task import get_by_key_name [as 别名]
def get_task(domain_identifier, task_identifier):
"""Gets a task in a domain.
Args:
domain: The domain identifier
task: The task identifier, as an int or string.
This argument can also be None, in which
case None will be returned.
Returns:
A task instance or None if no task exists. If
|task_identifier| was set to None, None will always be
returned.
"""
if not task_identifier:
return None
domain_key = Domain.key_from_name(domain_identifier)
try:
task_id = int(task_identifier)
return Task.get_by_id(task_id, parent=domain_key)
except ValueError:
return Task.get_by_key_name(task_identifier, parent=domain_key)