本文整理汇总了Python中models.Session.speaker方法的典型用法代码示例。如果您正苦于以下问题:Python Session.speaker方法的具体用法?Python Session.speaker怎么用?Python Session.speaker使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Session
的用法示例。
在下文中一共展示了Session.speaker方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: createSessionObject
# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import speaker [as 别名]
def createSessionObject(self, request):
"""Create or update Session object, returning SessionForm/request."""
# check if user is logged in
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException('Authorization required')
user_id = getUserId(user)
# get conference object using websafeConferenceKey
conf = ndb.Key(urlsafe=request.websafeConferenceKey).get()
if not conf:
raise endpoints.NotFoundException(
'No conference found with key: %s' % request.websafeConferenceKey
)
# check that user is owner of conference
if user_id != conf.organizerUserId:
raise endpoints.ForbiddenException(
'Only the owner can update the conference.')
# convert date string to date object
date_convert = request.date
if date_convert:
date_convert = datetime.strptime(date_convert[:10], "%Y-%m-%d").date()
# saving variables in the request to Session()
sess = Session()
sess.name = request.name
sess.highlights = request.highlights
sess.speaker = request.speaker
sess.duration = request.duration
sess.typeOfSession = request.typeOfSession
sess.date = date_convert
#sess.websafeConferenceKey = request.websafeConferenceKey
#sess.conferenceName = conf.name
sess.startTime = request.startTime
sess.endTime = request.endTime
# getting sessionkey with conference as parent
c_key = ndb.Key(urlsafe=request.websafeConferenceKey)
s_id = Session.allocate_ids(size=1, parent=c_key)[0]
s_key = ndb.Key(Session, s_id, parent=c_key)
sess.key = s_key
sess.websafeKey = s_key.urlsafe()
sess.put()
# calling cacheFeaturedSpeaker using taskqueue
taskqueue.add(
params={
'speaker': request.speaker,
'websafeConferenceKey': request.websafeConferenceKey
},
url='/tasks/set_featured_speaker'
)
return self._copySessionToForm(sess)
示例2: _createSessionObject
# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import speaker [as 别名]
def _createSessionObject(self, request):
"""Creates a new Session object from the request."""
# fetch the user
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException('Authorization required.')
user_id = getUserId(user)
# build the conference key
wsck = request.websafeConferenceKey
conference = ndb.Key(urlsafe=wsck).get()
if not conference:
raise endpoints.BadRequestException('The conference does not exist.')
p_key = ndb.Key(Profile, user_id)
# make sure the conference was created by the current user
if p_key != conference.key.parent():
raise endpoints.ForbiddenException('You may only create sessions for your own conferences.')
# create the session and add the required and optional fields
session = Session()
if not request.name:
raise endpoints.BadRequestException("Session 'name' field required.")
session.name = request.name
if not request.speaker:
raise endpoints.BadRequestException("Session 'speaker' field required.")
session.speaker = request.speaker
if not request.date:
raise endpoints.BadRequestException("Session 'date' field required")
session.date = datetime.strptime(request.date, '%Y-%m-%d').date()
if not request.startTime:
raise endpoints.BadRequestException("Session 'startTime' field required.")
session.startTime = datetime.strptime(request.startTime, '%H:%M').time()
if not request.duration:
raise endpoints.BadRequestException("Session 'duration' field required.")
session.duration = int(request.duration)
if request.typeOfSession:
session.typeOfSession = request.typeOfSession
if request.highlights:
session.highlights = request.highlights
# generate a key based on the parent conference
s_id = Session.allocate_ids(size=1, parent=conference.key)[0]
s_key = ndb.Key(Session, s_id, parent=conference.key)
session.key = s_key
# store the new session
session.put()
# add a new task to update the featured speaker
taskqueue.add(params={'speaker': session.speaker,
'websafeConferenceKey': wsck},
url='/tasks/update_featured_speaker'
)
return self._copySessionToForm(session)