本文整理汇总了Python中models.Speaker.query方法的典型用法代码示例。如果您正苦于以下问题:Python Speaker.query方法的具体用法?Python Speaker.query怎么用?Python Speaker.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Speaker
的用法示例。
在下文中一共展示了Speaker.query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_by_speaker
# 需要导入模块: from models import Speaker [as 别名]
# 或者: from models.Speaker import query [as 别名]
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: _getKeyForSpeaker
# 需要导入模块: from models import Speaker [as 别名]
# 或者: from models.Speaker import query [as 别名]
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
示例3: _getSpeakerKey
# 需要导入模块: from models import Speaker [as 别名]
# 或者: from models.Speaker import query [as 别名]
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
示例4: getConferenceSessionsBySpeaker
# 需要导入模块: from models import Speaker [as 别名]
# 或者: from models.Speaker import query [as 别名]
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]
)
示例5: _checkFeaturedSpeaker
# 需要导入模块: from models import Speaker [as 别名]
# 或者: from models.Speaker import query [as 别名]
def _checkFeaturedSpeaker(conf_urlsafekey, speaker_name, speaker_prof):
"""Add Task push queue for checking feature speaker.
When a new session is added to a conference, check the speaker.
If there is more than one session by this speaker at this conference,
also add a new Memcache entry that features the speaker and
session names. """
if (not conf_urlsafekey):
raise endpoints.BadRequestException("Invalid uslsafekey")
conf = ndb.Key(urlsafe=conf_urlsafekey).get()
squery = Session.query(ancestor=conf.key)
# check if Speaker entity has already existed
q_speaker = Speaker.query(Speaker.fullname == speaker_name)
existed_speaker = q_speaker.get()
profession = speaker_prof
if existed_speaker:
if existed_speaker.fullname == speaker_name:
# Search all session from the speaker
squery = Session.query(Session.speakerKey == existed_speaker.key)
featSessions = squery.fetch()
sessNames = [sess.name for sess in featSessions ]
# add a new memcache
fspeaker = FEATURED_SPEAKER_TPL %(speaker_name, sessNames )
memcache.set(MEMCACHE_FEATURED_SPEAKER, fspeaker)
else:
print "speaker does not exist yet"
示例6: getSpeakers
# 需要导入模块: from models import Speaker [as 别名]
# 或者: from models.Speaker import query [as 别名]
def getSpeakers(self, request):
"""Query datastore for all speakers."""
speakers = Speaker.query()
return SpeakerForms(
items = [self._copySpeakerToForm(speaker)
for speaker in speakers]
)
示例7: getSpeakers
# 需要导入模块: from models import Speaker [as 别名]
# 或者: from models.Speaker import query [as 别名]
def getSpeakers(self, request):
"""Return all speakers."""
# returns the speaker objects of all speakers stored in the datastore
speakers = Speaker.query()
return SpeakerForms(
speakers=[self._copySpeakerToForm(speaker) for speaker in speakers]
)
示例8: createSession
# 需要导入模块: from models import Speaker [as 别名]
# 或者: from models.Speaker import query [as 别名]
def createSession(self, request):
"""Create new session."""
# retrieve sessions of the same speaker, to check featured speaker
sessions = Session \
.query(ancestor=ndb.Key(urlsafe=request.websafeConferenceKey)) \
.filter(Session.speakerId == request.speakerEmail)\
.count()
featuredSpeaker = False
if sessions:
# if there is at least one session for this speaker, we will
# set the required announcement
featuredSpeaker = True
# create the session
session = self._createSessionObject(request,
request.websafeConferenceKey)
if featuredSpeaker:
# add featured speaker to memcache using a task
speaker = Speaker.query(Speaker.email==request.speakerEmail).get()
featured_speaker_message = FEATURED_SPEAKER_MESSAGE % speaker.name
taskqueue.add(
params={'key': MEMCACHE_FEATURED_SPEAKER_KEY, 'featured_speaker_message': featured_speaker_message},
url='/tasks/set_featured_speaker')
return self._copySessionToForm(session)
示例9: querySpeakers
# 需要导入模块: from models import Speaker [as 别名]
# 或者: from models.Speaker import query [as 别名]
def querySpeakers(self, request):
"""Query for all speakers."""
speakers = Speaker.query()
# return individual SpeakerForm object per Speaker
return SpeakerForms(items=[self._copySpeakerToForm(speaker) for speaker in speakers])
示例10: getSpeakers
# 需要导入模块: from models import Speaker [as 别名]
# 或者: from models.Speaker import query [as 别名]
def getSpeakers(self, request):
"""Return users who may be assigned as speakers for a conference session."""
speakers = Speaker.query()
# return set of SpeakerForm objects
return SpeakerForms(
speakers=[self.toSpeakerForm(speaker) for speaker in speakers]
)
示例11: _createSpeakerObject
# 需要导入模块: from models import Speaker [as 别名]
# 或者: from models.Speaker import query [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())
示例12: getAllSpeakers
# 需要导入模块: from models import Speaker [as 别名]
# 或者: from models.Speaker import query [as 别名]
def getAllSpeakers(self, request):
"""Get all Speakers"""
user_id = get_current_user_id()
speakers = Speaker.query() # get all speakers
return SpeakerForms(
items=[self._copySpeakerToForm(speaker) for speaker in speakers]
)
示例13: GetAllSpeakers
# 需要导入模块: from models import Speaker [as 别名]
# 或者: from models.Speaker import query [as 别名]
def GetAllSpeakers(self, request):
"""Get all speaker."""
Speakers = Speaker.query().fetch()
# return individual SpeakerForm object per Speaker
return SpeakerForms(
items=[self._copySpeakerToForm(item) for item in Speakers]
)
示例14: get
# 需要导入模块: from models import Speaker [as 别名]
# 或者: from models.Speaker import query [as 别名]
def get(self, confid, secret):
"""Download all speakers and proposals for a conference"""
# Super-Reviewers
committee = []
if confid == 'droidcon-2016':
committee = ['[email protected]',
'[email protected]']
# get conference
conference = Conference.get_by_id(confid)
# check if the provided secret is correct
if conference.secret != secret:
self.response.http_status_message(403)
return
speakers = Speaker.query()
proposals = Proposal.query(ancestor=conference.key)
reviews = Review.query()
speakers_dict = [dict(s.to_dict(), **dict(id=s.key.id()))
for s in speakers]
proposals_dict = []
# create a fast lookup table - reviews by parent
reviews_by_parent = {}
for r in reviews:
parent = r.key.parent()
rlist = reviews_by_parent[parent]
if rlist is None:
rlist = []
rlist.append(r)
reviews_by_parent[parent] = rlist
# crete a fast lookup table - speaker by key
speakers_by_id = {}
for s in speakers:
speakers_by_key[s.key] = s
for p in proposals:
p_dict = p.to_dict()
p_dict['id'] = p.key.id()
p_r = {}
p_sum = 0
for r in reviews_by_parent[p.key]:
p_r[r.key.id()] = r.to_dict()
if r.rating:
if r.key.id() in committee:
# double the rating!
p_sum = p_sum + r.rating
p_sum = p_sum + r.rating
s = speakers_by_key[p.speaker]
if s is not None:
p_dict['speaker-email'] = s.email
p_dict['speaker-name'] = s.name
p_dict['speaker-surname'] = s.surname
if s.rating:
p_sum = p_sum + s.rating
p_dict['reviews'] = p_r
p_dict['rating'] = p_sum
proposals_dict.append(p_dict)
self.response.headers['Content-Type'] = 'application/json'
obj = {
'speakers': speakers_dict,
'proposals': proposals_dict,
}
self.response.out.write(json.dumps(obj, cls=DatastoreEncoder))
示例15: speakerQuery
# 需要导入模块: from models import Speaker [as 别名]
# 或者: from models.Speaker import query [as 别名]
def speakerQuery(self, request):
"""Return speakers by email, name, or query all if no criteria specified."""
# should only return one speaker
if request.email:
speakers = Speaker.query(Speaker.email == request.email)
# can return multiple
elif request.name:
speakers = Speaker.query(Speaker.name == request.name)
# returns all if no email or name specified
else:
speakers = Speaker.query()
# return set of SpeakerForm objects per speaker matched
return SpeakerForms(
items=[self._copySpeakerToForm(speaker) for speaker in speakers]
)