本文整理汇总了Python中models.Activity.allocate_ids方法的典型用法代码示例。如果您正苦于以下问题:Python Activity.allocate_ids方法的具体用法?Python Activity.allocate_ids怎么用?Python Activity.allocate_ids使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Activity
的用法示例。
在下文中一共展示了Activity.allocate_ids方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _createActivityObject
# 需要导入模块: from models import Activity [as 别名]
# 或者: from models.Activity import allocate_ids [as 别名]
def _createActivityObject(self, request):
"""Create or update Activity object, returning ActivityForm/request."""
# preload necessary data items
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException('Authorization required')
user_id = getUserId(user)
if not request.tribe:
raise endpoints.BadRequestException("Activity 'tribe' field required")
# copy ActivityForm/ProtoRPC Message into dict
data = {field.name: getattr(request, field.name) for field in request.all_fields()}
del data['websafeKey']
del data['organizerDisplayName']
# add default values for those missing (both data model & outbound Message)
for df in DEFAULTS:
if data[df] in (None, []):
data[df] = DEFAULTS[df]
setattr(request, df, DEFAULTS[df])
# convert dates from strings to Date objects
if data['date']:
data['date'] = datetime.strptime(data['date'][:10], "%Y-%m-%d").date()
if data['time']:
data['time'] = str(data['time'])+" "+data['ampm']
del data['ampm']
# generate Profile Key based on user ID and Activity
# ID based on Profile key get Activity key from ID
p_key = ndb.Key(Profile, user_id)
a_id = Activity.allocate_ids(size=1, parent=p_key)[0]
a_key = ndb.Key(Activity, a_id, parent=p_key)
data['key'] = a_key
data['organizerUID'] = user_id
data['participants'] = []
# creation of Activity & return (modified) ActivityForm
Activity(**data).put()
return request