本文整理汇总了Python中models.Speaker.allocate_ids方法的典型用法代码示例。如果您正苦于以下问题:Python Speaker.allocate_ids方法的具体用法?Python Speaker.allocate_ids怎么用?Python Speaker.allocate_ids使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Speaker
的用法示例。
在下文中一共展示了Speaker.allocate_ids方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _createSpeakerObject
# 需要导入模块: from models import Speaker [as 别名]
# 或者: from models.Speaker import allocate_ids [as 别名]
def _createSpeakerObject(self, request):
"""Create speaker object, returning speakerForm/request."""
# check the required fields and throw exception is not set
if not request.firstName:
raise endpoints.BadRequestException(
"Session 'firstName' field required")
if not request.familyName:
raise endpoints.BadRequestException(
"Session 'familyName' field required")
# copy SessionForm/ProtoRPC Message into dict
data = {field.name: getattr(request, field.name)
for field in request.all_fields()}
del data['websafeKey']
# generate an ndb key for the new Speaker entry
s_id = Speaker.allocate_ids(size=1)[0]
s_key = ndb.Key(Speaker, s_id)
data['key'] = s_key
# create Speaker & return SpeakerForm
Speaker(**data).put()
return request
示例2: _createSpeakerObject
# 需要导入模块: from models import Speaker [as 别名]
# 或者: from models.Speaker import allocate_ids [as 别名]
def _createSpeakerObject(self, request):
"""Create a Speaker object."""
# preload necessary data items
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException('Authorization required')
user_id = getUserId(user)
if not request.firstName:
raise endpoints.BadRequestException(
"Speaker 'firstName' field required")
if not request.lastName:
raise endpoints.BadRequestException(
"Speaker 'lastName' field required")
# copy SpeakerForm Message into dict
data = {field.name: getattr(request, field.name) for field
in request.all_fields()}
# generate Profile Key based on user ID and Speaker
# ID based on Profile key get Speaker key from ID
p_key = ndb.Key(Profile, user_id)
speaker_id = Speaker.allocate_ids(size=1, parent=p_key)[0]
speaker_key = ndb.Key(Speaker, speaker_id, parent=p_key)
data['key'] = speaker_key
del data['speakerWebSafeKey']
# creation Speaker entity
Speaker(**data).put()
return request
示例3: _createSpeakerObject
# 需要导入模块: from models import Speaker [as 别名]
# 或者: from models.Speaker import allocate_ids [as 别名]
def _createSpeakerObject(self, request):
"""Create Speaker object,
returning SpeakerForm/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.name:
raise endpoints.BadRequestException(
"Speaker 'name' field required")
# copy SpeakerForm/ProtoRPC Message into dict
data = {field.name: getattr(request, field.name) \
for field in request.all_fields()}
del data['websafeKey']
speaker_id = Speaker.allocate_ids(size=1)[0]
speaker_key = ndb.Key(Speaker, speaker_id)
data['key'] = speaker_key
# create Speaker
speaker = Speaker(**data)
speaker.put()
# return the modified SpeakerForm
return self._copySpeakerToForm(speaker)
示例4: _createSpeakerObject
# 需要导入模块: from models import Speaker [as 别名]
# 或者: from models.Speaker import allocate_ids [as 别名]
def _createSpeakerObject(self, request):
"""Create Speaker object, returning SpeakerForm/request."""
user = self._getAuthUser()
user_id = getUserId(user)
if not request.name:
raise endpoints.BadRequestException("Speaker 'name' field required")
if not request.email:
raise endpoints.BadRequestException("Speaker 'email' field required")
# copy SpeakerForm/ProtoRPC Message into dict
data = {field.name: getattr(request, field.name) for field in request.all_fields()}
# create Speaker key
sp_id = Speaker.allocate_ids(size=1)[0]
sp_key = ndb.Key(Speaker, sp_id)
# assign the Speaker key
data['key'] = sp_key
del data['websafeKey']
# create Speaker
speaker = Speaker(**data)
speaker.put()
return self._copySpeakerToForm(speaker)
示例5: _createSpeakerObject
# 需要导入模块: from models import Speaker [as 别名]
# 或者: from models.Speaker import allocate_ids [as 别名]
def _createSpeakerObject(self, request):
"""Create or update Speaker object, returning SpeakerForm/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.name:
raise endpoints.BadRequestException("Speaker 'name' field required")
# copy SpeakerForm/ProtoRPC Message into dict
data = {field.name: getattr(request, field.name) for field in request.all_fields()}
del data['websafeKey']
# generate Profile Key based on user ID and Speaker
# ID based on Profile key get Speaker key from ID
s_id = Speaker.allocate_ids(size=1)[0]
s_key = ndb.Key(Speaker, s_id)
data['key'] = s_key
# creation of Speaker & return (modified) SpeakerForm
Speaker(**data).put()
return self._copySpeakerToForm(request)
示例6: _createSpeakerObject
# 需要导入模块: from models import Speaker [as 别名]
# 或者: from models.Speaker import allocate_ids [as 别名]
def _createSpeakerObject(self, request):
"""Create Speaker object, returning SpeakerForm."""
# check for auth'ed and valid user
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException('Authorization required')
user_id = getUserId(user)
# Speaker name must be filled
if not request.name:
raise endpoints.BadRequestException("Field 'name' required")
# copy SpeakerForm/ProtoRPC Message into dict
data = {field.name: getattr(request, field.name) for field in request.all_fields()}
# allocate new Speaker ID
s_id = Speaker.allocate_ids(size=1)[0]
# make Speaker key from ID
s_key = ndb.Key(Speaker, s_id)
data['key'] = s_key
# create Speaker & return SpeakerForm
speaker = Speaker(**data)
speaker.put()
return self._copySpeakerToForm(speaker)
示例7: _createSpeakerObject
# 需要导入模块: from models import Speaker [as 别名]
# 或者: from models.Speaker import allocate_ids [as 别名]
def _createSpeakerObject(self, request):
"""Create Speaker object, returning SpeakerForm/request."""
# Need to be logged in to create a speaker entity
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException("Authorization required")
user_id = getUserId(user)
# Speaker name is a required property
if not request.name:
raise endpoints.BadRequestException("Speaker 'name' field required")
# Copy SpeakerForm/ProtoRPC Message into dictionary
data = {field.name: getattr(request, field.name) for field in request.all_fields()}
del data["websafeKey"]
# Make the logged in user the parent of the Speaker object.
p_key = ndb.Key(Profile, user_id)
s_id = Speaker.allocate_ids(size=1, parent=p_key)[0]
s_key = ndb.Key(Speaker, s_id, parent=p_key)
data["key"] = s_key
# Create the Speaker entity in the datastore
new_speaker = Speaker(**data)
new_speaker.put()
return self._copySpeakerToForm(new_speaker)
示例8: _createSpeakerObject
# 需要导入模块: from models import Speaker [as 别名]
# 或者: from models.Speaker import allocate_ids [as 别名]
def _createSpeakerObject(self, request):
"""Create or update Speaker object, returning SpeakerForm/request."""
# preload necessary data items
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException('Authorization required')
user_id = getUserId(user)
# name is a required Speaker field
if not request.name:
raise endpoints.BadRequestException("Speaker 'name' field required")
# copy SpeakerForm/ProtoRPC Message into dict
data = {field.name: getattr(request, field.name) \
for field in request.all_fields()}
del data['websafeKey'] # websafeKey not a Speaker attribute
# allocate Speaker id
s_id = Speaker.allocate_ids(size=1)[0]
s_key = ndb.Key(Speaker, s_id)
data['key'] = s_key
# create Session, send email to organizer confirming
# creation of Session & return (modified) SessionForm
speaker = Speaker(**data)
speaker.put()
return self._copySpeakerToForm(speaker)
示例9: _createSpeakerObject
# 需要导入模块: from models import Speaker [as 别名]
# 或者: from models.Speaker import allocate_ids [as 别名]
def _createSpeakerObject(self, request):
"""Create or update Speaker object, returning SpeakerForm."""
if not request.name:
raise endpoints.BadRequestException(
"Speaker 'name' field required")
q = Speaker.query()
q = q.filter(Speaker.name == request.name)
if q.count() != 0:
raise endpoints.BadRequestException(
"Speaker already excists")
# copy SpeakerForm/ProtoRPC Message into dict
data = {field.name: getattr(request, field.name)
for field in request.all_fields()}
# Create session id from parent COnference Key and
# a Session key from that id
s_id = Speaker.allocate_ids(size=1)[0]
s_key = ndb.Key(Speaker, s_id)
data['key'] = s_key
del data['websafeKey']
# Save session and return a SessionForm to the user
Speaker(**data).put()
return self._copySpeakerToForm(s_key.get())
示例10: _createSpeakerObject
# 需要导入模块: from models import Speaker [as 别名]
# 或者: from models.Speaker import allocate_ids [as 别名]
def _createSpeakerObject(self, request):
"""Create or update Speaker object, returning SpeakerForm/request."""
# preload necessary data items
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException('Authorization required')
if not request.displayName:
raise endpoints.BadRequestException("Speaker 'displayName' field required")
# copy ConferenceForm/ProtoRPC Message into dict
data = {field.name: getattr(request, field.name) for field in request.all_fields()}
# this is automatically generated for display but should
# be ignored if it is input.
del data['websafeKey']
# Now create the speaker key.
# NOTE: allocate_ids returns a list, so take the first element.
speaker_id = Speaker.allocate_ids(size=1)[0]
speaker_key = ndb.Key(Speaker, speaker_id)
data['key'] = speaker_key
# create Speaker, send email to creator confirming
# creation of Speaker & return (modified) SpeakerForm
Speaker(**data).put()
taskqueue.add(params={'email': user.email(),
'speakerInfo': repr(request)},
url='/tasks/send_speaker_confirmation_email'
)
return request
示例11: _createSpeakerObject
# 需要导入模块: from models import Speaker [as 别名]
# 或者: from models.Speaker import allocate_ids [as 别名]
def _createSpeakerObject(self, request):
user = endpoints.get_current_user()
# Raise an exception if the user is not logged in
if not user:
raise endpoints.UnauthorizedException('Authorization required')
user_id = getUserId(user)
# Raise an exception if the displayName is not provided
if not request.displayName:
raise endpoints.BadRequestException("dislayName field required")
# Copy SpeakerForm into a dictionary
data = {field.name: getattr(request, field.name)
for field in request.all_fields()}
del data['websafeKey']
# generate Speaker key
sp_id = Speaker.allocate_ids(size=1)[0]
sp_key = ndb.Key(Speaker, sp_id)
data['key'] = sp_key
# Create Speaker and save
sp = Speaker(**data)
sp.put()
return self._copySpeakerToForm(sp)
示例12: _createSessionObject
# 需要导入模块: from models import Speaker [as 别名]
# 或者: from models.Speaker import allocate_ids [as 别名]
def _createSessionObject(request, conference):
"""Create or update Session object, returning SessionForm/request."""
# preload necessary data items
if not request.name:
raise endpoints.BadRequestException("Session 'name' field required")
speaker_wskey = None
if not request.speakerWSKey:
if request.speakerName:
speaker = Speaker.query(Speaker.name == request.speakerName).get()
if speaker:
speaker_wskey = speaker.key.urlsafe()
else:
speaker_id = Speaker.allocate_ids(size=1)[0]
speaker_key = ndb.Key(Speaker, speaker_id)
speaker_wskey = speaker_key.urlsafe()
speaker = Speaker(**{'key': speaker_key,'name': request.speakerName})
speaker.put()
else:
raise endpoints.BadRequestException("Session speaker required")
else:
speaker_wskey = request.speakerWSKey
# copy SessionForm/ProtoRPC Message into dict
data = {field.name: getattr(request, field.name) for field in request.all_fields()}
del data['sessionWSKey']
del data['speakerWSKey']
del data['speakerName']
del data['conferenceWSKey']
del data['startDateHour']
print '1:' + str(data.keys())
# add default values for those missing (both data model & outbound Message)
for df in SESSION_DEFAULTS:
if data[df] in (None, []):
data[df] = SESSION_DEFAULTS[df]
setattr(request, df, SESSION_DEFAULTS[df])
# convert dates from strings to Date objects; set month based on start_date
if data['startDate'] and isinstance(data['startDate'], types.StringType):
data['startDate'] = datetime.strptime(data['startDate'][:10], "%Y-%m-%d").datetime()
session_id = Session.allocate_ids(size=1, parent=conference.key)[0]
session_key = ndb.Key(Session, session_id, parent=conference.key)
data['key'] = session_key
data['speakerKey'] = speaker_wskey
# create Session, send email to organizer confirming creation of Session & return (modified) SessionForm
session = Session(**data)
session.put()
# taskqueue.add(params={'email': user.email(), 'conferenceInfo': repr(request)}, url='/tasks/send_confirmation_email')
return session
示例13: _createSpeakerObject
# 需要导入模块: from models import Speaker [as 别名]
# 或者: from models.Speaker import allocate_ids [as 别名]
def _createSpeakerObject(self, request):
s_id = Speaker.allocate_ids(size=1)[0]
s_key = ndb.Key(Speaker, s_id)
data = {field.name: getattr(request, field.name) for field in request.all_fields()}
if not data["name"]:
raise endpoints.BadRequestException("Speaker 'name' field required")
del data["websafeKey"]
data["key"] = s_key
Speaker(**data).put()
return self._copySpeakerToForm(ndb.Key(Speaker, s_id).get())
示例14: _createSpeaker
# 需要导入模块: from models import Speaker [as 别名]
# 或者: from models.Speaker import allocate_ids [as 别名]
def _createSpeaker(self, request):
"""Creates a new Speaker and converts it to a SpeakerForm"""
speaker = {field.name: getattr(request, field.name) for field in request.all_fields()}
del speaker["websafeSpeakerKey"]
# Generate a unique key for the speaker
s_id = Speaker.allocate_ids(size=1)[0]
s_key = ndb.Key(Speaker, s_id)
speaker["key"] = s_key
Speaker(**speaker).put()
return self.toSpeakerForm(request, None, s_key.urlsafe())
示例15: _createSpeakerObject
# 需要导入模块: from models import Speaker [as 别名]
# 或者: from models.Speaker import allocate_ids [as 别名]
def _createSpeakerObject(self, data):
"""Create Speaker object, return Speaker key"""
# allocate new Speaker ID
speaker_id = Speaker.allocate_ids(size=1)[0]
# make Speaker key fom ID
speaker_key = ndb.Key(Speaker, speaker_id)
# Create Speaker and return Speaker key
speaker = Speaker(name=data,
key=speaker_key)
speaker.put()
return speaker_key