本文整理汇总了Python中models.Activity.query方法的典型用法代码示例。如果您正苦于以下问题:Python Activity.query方法的具体用法?Python Activity.query怎么用?Python Activity.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Activity
的用法示例。
在下文中一共展示了Activity.query方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: queryActivities
# 需要导入模块: from models import Activity [as 别名]
# 或者: from models.Activity import query [as 别名]
def queryActivities(self, request):
"""Query for activities."""
activities = Activity.query()
if request.fil:
activities = Activity.query(Activity.tribe==request.fil)
# need to fetch organiser displayName from profiles
# get all keys and use get_multi for speed
organisers = [(ndb.Key(Profile, acti.organizerUID)) for acti in activities]
profiles = ndb.get_multi(organisers)
# put display names in a dict for easier fetching
names = {}
for profile in profiles:
names[profile.key.id()] = profile.displayName
# return individual ActivityForm object per Activity
return ActivityForms(
items=[self._copyActivityToForm(acti, names[acti.organizerUID]) for acti in \
activities]
)
示例2: getActivitiesCreated
# 需要导入模块: from models import Activity [as 别名]
# 或者: from models.Activity import query [as 别名]
def getActivitiesCreated(self, request):
"""Return activities created by user."""
# make sure user is authed
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException('Authorization required')
user_id = getUserId(user)
# create ancestor query for all key matches for this user
actis = Activity.query(ancestor=ndb.Key(Profile, user_id))
prof = ndb.Key(Profile, user_id).get()
# return set of ActivityForm objects per Activity
return ActivityForms(
items=[self._copyActivityToForm(acti, getattr(prof, 'displayName')) for acti in actis]
)