本文整理汇总了Python中models.Speaker.id方法的典型用法代码示例。如果您正苦于以下问题:Python Speaker.id方法的具体用法?Python Speaker.id怎么用?Python Speaker.id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Speaker
的用法示例。
在下文中一共展示了Speaker.id方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _createSessionObject
# 需要导入模块: from models import Speaker [as 别名]
# 或者: from models.Speaker import id [as 别名]
def _createSessionObject(self, request):
"""Create Session object, returning SessionForm/request."""
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException('Authorization required')
user_id = getUserId(user)
# check to see that the current user is the conference organizer
conf_key = ndb.Key(urlsafe=request.websafeConferenceKey)
if conf_key.parent().get().mainEmail != user_id:
raise endpoints.UnauthorizedException(
'Only the organizer of the conference can create sessions')
if not request.name:
raise endpoints.BadRequestException("Session 'name' field required")
# copy SessionForm/ProtoRPC Message into dictionary
data = {field.name: getattr(request, field.name) for field in request.all_fields()}
# delete the unneeded values
del data['websafeKey']
del data['websafeConferenceKey']
del data['speaker_name']
del data['speaker_email']
del data['speaker_gender']
# Format date and startTime, ie. 2015-08-18 and 16:00
if data['date']:
data['date'] = datetime.strptime(data['date'][:10], "%Y-%m-%d").date()
if data['startTime']:
data['startTime'] = datetime.strptime(data['startTime'][:10], "%H:%M").time()
# if speaker email was submitted, get or create a speaker
if request.speaker_email:
# check to see if this speaker exists
speaker = Speaker.query(Speaker.email == request.speaker_email).get()
# if so, use this speaker's values
if speaker:
# Update speaker from request
speaker.name = request.speaker_name
speaker.gender = request.speaker_gender
speaker.put()
speaker_key = speaker.key
else:
# create the speaker
speaker_data = {
'name': request.speaker_name,
'email': request.speaker_email,
'gender': request.speaker_gender
}
speaker_key = Speaker(**speaker_data).put()
data['speakerId'] = speaker_key.id()
sesh_id = Session.allocate_ids(size=1, parent=conf_key)[0]
sesh_key = ndb.Key(Session, sesh_id, parent=conf_key)
data['key'] = sesh_key
Session(**data).put()
# check to see if we should create a featured speaker
if speaker:
# get all sessions for this conference with this speaker
sessions = Session.query(Session.speakerId == data['speakerId'], ancestor=conf_key)
# create a comma-delimited string of session names
session_names = ', '.join(session.name for session in sessions)
# if this speaker is speaking in more than one session for this
# conference then pass his name and session names to the task queue
if sessions.count() > 1:
taskqueue.add(
params={'speaker_name': speaker.name,
'session_names': session_names},
url='/tasks/set_featured_speaker'
)
return self._copySessionToForm(sesh_key.get())