本文整理汇总了Python中models.Speaker类的典型用法代码示例。如果您正苦于以下问题:Python Speaker类的具体用法?Python Speaker怎么用?Python Speaker使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Speaker类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_by_speaker
def get_by_speaker(self, request):
"""
Given a speaker, return all sessions given by this particular speaker,
across all conferences
:param request:
:return:
"""
if request.name and not request.title:
speakers = Speaker.query(Speaker.name == request.name)
elif not request.name and request.title:
speakers = Speaker.query(Speaker.title == request.title)
else:
speakers = Speaker.query(Speaker.name == request.name) \
.filter(Speaker.title == request.title)
speakers.fetch()
all_sessions = []
if speakers:
for speaker in speakers:
sessions = Session.query(
Session.speakerKeys == speaker.key).fetch()
if sessions:
all_sessions += sessions
return SessionForms(items=self.populate_forms(all_sessions))
示例2: _createSpeakerObject
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)
示例3: _createSpeakerObject
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)
示例4: _getKeyForSpeaker
def _getKeyForSpeaker(self, request):
"""
This function gets the key for an existing speaker that has been
requested.
"""
if not request.name:
raise endpoints.BadRequestException("Speaker 'name' field \
required")
# creates new key for Speaker
spkr_key = Speaker().key
# for all noted speakers, make a query
notedSpeakersQuery = Speaker.query()
# lists noted speakers
notedSpeakers = []
for ns in notedSpeakersQuery:
notedSpeakers.append(ns.name)
# When no speaker is found with a name, a NotFoundException is raised.
if request.name not in notedSpeakers:
raise endpoints.NotFoundException(
'No speaker found with name: %s'
% request.name)
# Otherwise, have its key returned.
else:
spkr_key = Speaker.query(Speaker.name == request.name).get().key
return spkr_key
示例5: _getSpeakerKey
def _getSpeakerKey(self, request):
""" Returns the key for a requested speaker, when he exists."""
if not request.name:
raise endpoints.BadRequestException("Speaker 'name' field \
required")
# create a new Speaker.key
spk_key = Speaker().key
# query all existing/known speakers
qryKnownSpeakers = Speaker.query()
# write the names of the known speakers in a list
knownSpeakers = []
for ks in qryKnownSpeakers:
knownSpeakers.append(ks.name)
# If speaker doesn't exist, raise an "Not Found"-exception.
if request.name not in knownSpeakers:
raise endpoints.NotFoundException(
'No speaker found with name: %s'
% request.name)
# Else return its key.
# NOTE: For simplification, it is assumed that a name uniquely
# identifies a speaker.
else:
spk_key = Speaker.query(Speaker.name == request.name).get().key
return spk_key
示例6: _createSpeakerObject
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)
示例7: _createSpeakerObject
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)
示例8: _createSpeakerObject
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
def _createSpeakerObject(self, request):
"""Create Speaker Object, returning SessionForm/request."""
data = {field.name: getattr(request, field.name)
for field in request.all_fields()}
del data['speakerId']
key = Speaker(**data).put()
return self._copySpeakerToForm(key.get())
示例10: createSpeaker
def createSpeaker(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')
if not request.name:
raise endpoints.BadRequestException("Speaker 'name' field required")
if not request.mainEmail:
raise endpoints.BadRequestException("Speaker 'mainEmail' field required")
sp_key = ndb.Key(Speaker, request.mainEmail)
speaker = sp_key.get()
if not speaker:
speaker = Speaker(
key = sp_key,
name = request.name,
mainEmail = request.mainEmail,
)
if request.title:
speaker.title = request.title
if request.bio:
speaker.bio = request.bio
speaker.put()
return request
示例11: _createSpeakerObject
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: getConferenceSessionsBySpeaker
def getConferenceSessionsBySpeaker(self, request):
"""Return Conference sessions by Speaker."""
# make sure user is authed
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException('Authorization required')
# user_id = getUserId(user)
sp_lastName = request.lastName
sp_firstName = request.firstName
if sp_firstName:
# find by first and last name
speaker = Speaker.query(ndb.AND(
Speaker.lastName == sp_lastName,
Speaker.firstName == sp_firstName))
else:
# find by last name only
speaker = Speaker.query(Speaker.lastName == sp_lastName)
speaker_keys = [sp.key for sp in speaker]
# iterate over each key finding all sessions
all_sessions = []
for sp_k in speaker_keys:
sessions = Session.query(Session.speaker == sp_k)
for s in sessions:
all_sessions.append(s)
# return list of sessions that match each of the speaker_keys
return SessionForms(
items=[self._copySessionToForm(sess) for sess in all_sessions]
)
示例13: _createSpeakerObject
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())
示例14: addSpeaker
def addSpeaker(self, request):
"""Get profile from user, take field info for all fields, give key and put into datastore"""
prof=self._getProfileFromUser()
data={field.name:getattr(request, field.name) for field in request.all_fields()}
del data['websafeKey']
speaker=Speaker(**data)
speaker.put()
return self._copySpeakerToForm(speaker)
示例15: _createSessionObject
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