def _copySessionToForm(self, session): """Copies the given Session object to a SessionForm object.""" sessionForm = SessionForm() sessionForm.name = session.name sessionForm.speaker = session.speaker sessionForm.date = str(session.date) sessionForm.startTime = str(session.startTime) sessionForm.duration = session.duration sessionForm.typeOfSession = session.typeOfSession sessionForm.highlights = session.highlights sessionForm.websafeKey = session.key.urlsafe() return sessionForm
def _copySessionToForm(self, session): """ Converts a session object into a session_form message :param session: A session object :return: session_form """ session_form = SessionForm() exclusions = ['typeOfSession', 'speaker'] session_form = ndb_to_message(session, session_form, exclusions) if session.typeOfSession: session_form.typeOfSession = SessionType(session.typeOfSession) if session.speaker: session_form.speaker = self._getSpeakerFormFromWsKey( session.speaker) session_form.check_initialized() return session_form
def _copySessionToForm(self, session): """Copy relevant fields from Session to SessionForm""" # create a new entity first sf = SessionForm() # convert Session properties to SessionForm fields sf.name = session.name sf.highlights = session.highlights sf.speakerKeys = session.speakerKeys sf.duration = session.duration sf.typeOfSession = getattr(SessionTypes, session.typeOfSession) sf.date = str(session.date) sf.startTime = int('%s%s' % (str(session.startTime)[:2], str(session.startTime)[3:5])) sf.websafeKey = session.key.urlsafe() # check and return sf.check_initialized() return sf
def _copySessionToForm(self, session): """Copy relevant fields from Session to SessionForm""" # create a new entity first sf = SessionForm() # convert Session properties to SessionForm fields sf.name = session.name sf.highlights = session.highlights sf.speakerKeys = session.speakerKeys sf.duration = session.duration sf.typeOfSession = getattr(SessionTypes, session.typeOfSession) sf.date = str(session.date) sf.startTime = int( '%s%s' % (str(session.startTime)[:2], str(session.startTime)[3:5])) sf.websafeKey = session.key.urlsafe() # check and return sf.check_initialized() return sf
def _copySessionToForm(self, session): """Copy the relavent fields from Session to SessionForm.""" sf = SessionForm() for field in sf.all_fields(): # Need special treatment for `date` and `startTime` fields. if field.name in ("date", "startTime", "duration"): setattr(sf, field.name, str(getattr(session, field.name))) elif field.name == "typeOfSession": sf.typeOfSession = SessionType(session.typeOfSession) elif field.name == "websafeKey": sf.websafeKey = session.key.urlsafe() elif field.name == "websafeConferenceKey": sf.websafeConferenceKey = session.key.parent().urlsafe() elif hasattr(session, field.name): # name, highlights and speaker. setattr(sf, field.name, getattr(session, field.name)) else: raise endpoints.InternalServerErrorException( "Unexpected field name '%s'." % field.name) sf.check_initialized() return sf
def _copySessionToForm(self, session): """Copy relevant fields from Session to SessionForm""" # create a new entity first sf = SessionForm() # convert Session properties to SessionForm fields sf.sessionName = session.sessionName sf.highlights = session.highlights sf.speaker = session.speaker sf.duration = session.duration #logging.debug("copySession :: About to set typeOfSession") #logging.debug("copySession :: type of Session type is %s", type(session.typeOfSession)) sf.typeOfSession = getattr(SessionType,session.typeOfSession) sf.sessionDate = str(session.sessionDate) sf.startTime = int('%s%s' % (str(session.startTime)[:2], str(session.startTime)[3:5])) sf.websafeKey = session.key.urlsafe() # check and return sf.check_initialized() return sf