本文整理汇总了Python中indico.modules.events.Event.find_first方法的典型用法代码示例。如果您正苦于以下问题:Python Event.find_first方法的具体用法?Python Event.find_first怎么用?Python Event.find_first使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类indico.modules.events.Event
的用法示例。
在下文中一共展示了Event.find_first方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_object_from_args
# 需要导入模块: from indico.modules.events import Event [as 别名]
# 或者: from indico.modules.events.Event import find_first [as 别名]
def get_object_from_args(args=None):
"""Retrieves an event object from request arguments.
This utility is meant to be used in cases where the same controller
can deal with objects attached to various parts of an event which
use different URLs to indicate which object to use.
:param args: The request arguments. If unspecified,
``request.view_args`` is used.
:return: An ``(object_type, event, object)`` tuple. The event is
always the :class:`Event` associated with the object.
The object may be an `Event`, `Session`, `Contribution`
or `SubContribution`. If the object does not exist,
``(object_type, None, None)`` is returned.
"""
if args is None:
args = request.view_args
object_type = args['object_type']
event = Event.find_first(id=args['confId'], is_deleted=False)
if event is None:
obj = None
elif object_type == 'event':
obj = event
elif object_type == 'session':
obj = Session.query.with_parent(event).filter_by(id=args['session_id']).first()
elif object_type == 'contribution':
obj = Contribution.query.with_parent(event).filter_by(id=args['contrib_id']).first()
elif object_type == 'subcontribution':
obj = SubContribution.find(SubContribution.id == args['subcontrib_id'], ~SubContribution.is_deleted,
SubContribution.contribution.has(event=event, id=args['contrib_id'],
is_deleted=False)).first()
else:
raise ValueError('Unexpected object type: {}'.format(object_type))
if obj is not None:
return object_type, event, obj
else:
return object_type, None, None