本文整理汇总了Python中models.Speaker.populate方法的典型用法代码示例。如果您正苦于以下问题:Python Speaker.populate方法的具体用法?Python Speaker.populate怎么用?Python Speaker.populate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Speaker
的用法示例。
在下文中一共展示了Speaker.populate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _createSessionObject
# 需要导入模块: from models import Speaker [as 别名]
# 或者: from models.Speaker import populate [as 别名]
def _createSessionObject(self, request):
"""Create or update Session object, returning SessionForm/request."""
# Get the user saved in session
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException('Authorization required')
user_id = getUserId(user)
if not request.name:
raise endpoints.BadRequestException(
"Session 'name' field required")
c_key = ndb.Key(urlsafe=request.websafeConfKey)
# Check that the name is unique within the conference
name_check = Session.query(ancestor=c_key)
name_check = name_check.filter(Session.name==request.name).get()
if name_check:
raise endpoints.BadRequestException(
"Entity with name '%s' already exists" % request.name)
# Check that the conference exists
conf = c_key.get()
if not conf:
raise endpoints.NotFoundException(
'No conf with key: %s' % request.websafeConferenceKey)
# Check that the user is the conference organizer
if user_id != conf.organizerUserId:
raise endpoints.ForbiddenException(
'Only the organizer may update the conference')
# Copy SessionForm/ProtoRPC Message into dict
data = {field.name: getattr(request, field.name)
for field in request.all_fields()}
# Delete unnecessary fields from the form
del data['displayName']
del data['websafeConfKey']
del data['sessionKey']
# Convert date from string into Date object;
if data['date']:
data['date'] = datetime.strptime(
data['date'][:10], "%Y-%m-%d").date()
# Convert times from string into Time objects
if data['startTime']:
data['startTime'] = datetime.strptime(
data['startTime'][:5], "%H:%M").time()
if data['duration']:
try:
datetime.strptime(
data['duration'][:5], "%H:%M").time()
except:
raise endpoints.BadRequestException("Duration Must be in 'HH:MM' format")
s_id = Session.allocate_ids(size=1, parent=c_key)[0]
s_key = ndb.Key(Session, s_id, parent=c_key)
data['key'] = s_key
if data['speaker']:
print 'In createSession, there is a speaker...'
# Check to see if the speaker already exists
speaker = Speaker.query(Speaker.name == data['speaker']).get()
# If the speaker doesn't exist, create a Speaker entity for them
if not speaker:
speaker_id = Speaker.allocate_ids(size=1)[0]
speaker_key = ndb.Key(Speaker, speaker_id)
speaker = Speaker()
speaker.populate(
key=speaker_key,
name=data['speaker']
)
speaker.put()
else:
speaker_key = speaker.key
# Set the session speaker to the speaker's urlsafe key
data['speaker'] = speaker_key.urlsafe()
#Put the session in the database
Session(**data).put()
# Use the TaskQueue to check whether the new session's
# speaker should be the next featured speaker.
taskqueue.add(
params={'sessionKey': s_key.urlsafe()},
url='/tasks/set_featured_speaker'
)
else:
#Put the session in the database
Session(**data).put()
#.........这里部分代码省略.........