本文整理汇总了Python中models.Profile.allocate_ids方法的典型用法代码示例。如果您正苦于以下问题:Python Profile.allocate_ids方法的具体用法?Python Profile.allocate_ids怎么用?Python Profile.allocate_ids使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Profile
的用法示例。
在下文中一共展示了Profile.allocate_ids方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _createProfileObject
# 需要导入模块: from models import Profile [as 别名]
# 或者: from models.Profile import allocate_ids [as 别名]
def _createProfileObject(self, request):
"""Create Profile object, returning ProfileForm/request."""
# preload necessary data items
user = endpoints.get_current_user()
if not user:
# require authorization to create Profiles
raise endpoints.UnauthorizedException('Authorization required')
user_id = getUserId(user)
# ensure required fields are filled out
if not request.displayName:
raise endpoints.BadRequestException("Display name required")
if not request.mainEmail:
raise endpoints.BadRequestException("Email required")
# copy ProfileForm/ProtoRPC Message into dict
data = {
field.name: getattr(
request, field.name) for field in request.all_fields()
}
del data['websafeKey']
if not data['teeShirtSize']:
data['teeShirtSize'] = str(TeeShirtSize.NOT_SPECIFIED)
confs = Conference.query(Conference.organizerUserId == user_id)
# check that user is a conference owner
if (confs.count() == 0):
raise endpoints.ForbiddenException(
'Only a conference organizer can create user profiles.')
# create Profile key
p_id = Profile.allocate_ids(size=1)[0]
p_key = ndb.Key(Profile, p_id)
data['key'] = p_key
Profile(**data).put()
# return request
return self._copyProfileToForm(p_key.get())