def _getSessions(self, webSafeKey): """Get all sessions from a conference.""" confkey = ndb.Key(urlsafe=webSafeKey) # check if this key belongs to an actual conference if not confkey: raise endpoints.NotFoundException('No conference found with this key.') # retrieve all sessions from ancestor conferences, using # an ndb class method actual query is faster return Session.get_session_by_conferencekey(confkey)
def _setFeaturedSpeaker(speaker, webSafeKey): """This will check if the speaker is featured in more than one session then it will create an anouncement assigning it to memcache. """ # get all existing sessions confkey = ndb.Key(urlsafe=webSafeKey) all_sessions = Session.get_session_by_conferencekey(confkey) # check to see if speaker is present already in other sessions speaker_sessions = all_sessions.filter(Session.speaker == speaker) if speaker_sessions.count() > 1: announcement = '%s %s %s %s' % ( 'This speaker is very popular:', speaker, '. He is featured in these sessions:', ', '.join(sess.name for sess in speaker_sessions)) memcache.set(FEATURED_SPEAKER_SESSIONS_KEY, announcement) else: # delete the memcache announcements entry announcement = "" memcache.delete(FEATURED_SPEAKER_SESSIONS_KEY) return announcement