def _createSessionSpeakerObject(self, name, email): """Create or update SessionSpeaker object, return its key""" speaker = SessionSpeaker.query(SessionSpeaker.email == email).get() if not speaker: speaker = SessionSpeaker(name=name, email=email) else: speaker.name = name return speaker.put()
def _addFeaturedSpeakerToMemcache(websafeConfKey, speakerEmail): """Check if the speaker with specified speaker email can be a featured speaker. If yes, add this speaker to list of featured speakers in memcache Args: websafeConfKey: conference key speakerEmail: speaker's email """ # Check if conference exists conference = ndb.Key(urlsafe=websafeConfKey).get() if not conference: return # Check if speaker exists speaker = SessionSpeaker.query(SessionSpeaker.email == speakerEmail).get() if not speaker: return # Check if that speaker has at least 2 sessions in the conference sessions = Session.query(Session.speakerEmail == speakerEmail, ancestor=conference.key) if sessions.count() < 2: return # Add speaker to memcache featuredSpeakers = memcache.get(MEMCACHE_FEATURED_SPEAKER_KEY) if not featuredSpeakers: memcache.set(MEMCACHE_FEATURED_SPEAKER_KEY, [speakerEmail]) else: if not speakerEmail in featuredSpeakers: featuredSpeakers.append(speakerEmail) memcache.set(MEMCACHE_FEATURED_SPEAKER_KEY, featuredSpeakers)
def getFeaturedSpeaker(self, request): """Return all featured speakers from Memcache""" featuredSpeakers = memcache.get(MEMCACHE_FEATURED_SPEAKER_KEY) speakerForms = [] for speakerEmail in featuredSpeakers: speaker = SessionSpeaker.query(SessionSpeaker.email == speakerEmail).get() speakerForm = SpeakerForm() speakerForm.name = speaker.name speakerForm.email = speaker.email speakerForm.check_initialized() speakerForms.append(speakerForm) return SpeakerForms(items=speakerForms)
def _copySessionToForm(self, session): """Copy relevant fields from Session to SessionForm.""" sf = SessionForm() for field in sf.all_fields(): if field.name == 'startTime': sf.startTime = str(session.startTime) elif hasattr(session, field.name): setattr(sf, field.name, getattr(session, field.name)) speakerEmail = session.speakerEmail speaker = SessionSpeaker.query(SessionSpeaker.email == speakerEmail).get() if not speaker: sf.speakerName = "Not Found" sf.speakerEmail = "Not Found" else: sf.speakerEmail = speakerEmail sf.speakerName = speaker.name sf.websafeConferenceKey = session.key.parent().urlsafe() sf.websafeSessionKey = session.key.urlsafe() sf.check_initialized() return sf