示例#1
0
    def _copySessionToForm(self, session):
        """ Copy relevant fields from Session to SessionForm."""

        sessionForm = SessionForm()

        for field in sessionForm.all_fields():

            if field.name == "speakerKey":
                speaker = session.speaker.get()
                if speaker:
                    setattr(sessionForm, "speakerKey", speaker.key.urlsafe())

            elif field.name == "date":
                setattr(sessionForm, "date", str(session.date.date()))

            elif field.name == "startTime":
                setattr(sessionForm, "startTime", str(session.startTime.time()))

            elif field.name == "endTime":
                setattr(sessionForm, "endTime", str(session.endTime.time()))

            elif field.name == "duration":
                setattr(sessionForm, "duration", duration(session.startTime, session.endTime))

            elif field.name == "websafeKey":
                setattr(sessionForm, field.name, session.key.urlsafe())

            elif hasattr(session, field.name):
                setattr(sessionForm, field.name, getattr(session, field.name))

        sessionForm.check_initialized()
        return sessionForm
    def _copySessionToForm(self, session):
        """
        Input:
            session: Session object
        Returns:
            SessionForm
        Description:
            This method takes a session object with values defined from client
            side and returns the SessionFrom after copying the relevant fields in
            it which can be returned to client as ProRPC Message.
        """
        sessionform = SessionForm()
        for field in sessionform.all_fields():
            if hasattr(session, field.name):
                # convert Date to date string; just copy others
                if field.name.endswith("date"):
                    setattr(sessionform, field.name, str(getattr(session, field.name)))
                else:
                    setattr(sessionform, field.name, getattr(session, field.name))
            # Checks if the field is websafeSessionKey, then converts it into
            # urlsafe key
            elif field.name == "websafeSessionKey":
                setattr(sessionform, field.name, session.key.urlsafe())

        sessionform.check_initialized()
        return sessionform
    def _copySessionToForm(self, sess):
        """Copy relevant fields from Session to SessionForm."""
        sf = SessionForm()
        for field in sf.all_fields():
            if hasattr(sess, field.name):
                if field.name == 'speaker':
                    sf.speaker = SpeakerForm(
                        name=sess.speaker.name,
                        email=sess.speaker.email,
                        websafeSpeakerKey=sess.speaker.websafeSpeakerKey,
                    )

                # convert sessionType string to Enum
                elif field.name == 'sessionType':
                    setattr(
                        sf,
                        field.name,
                        getattr(SessionType, getattr(sess, field.name))
                    )
                # convert Date to date string
                elif field.name == 'date':
                    setattr(sf, field.name, str(getattr(sess, field.name)))
                # just copy others
                else:
                    setattr(sf, field.name, getattr(sess, field.name))
            # get the websafe session key
            elif field.name == 'websafeKey':
                setattr(sf, field.name, sess.key.urlsafe())
        sf.check_initialized()
        return sf
 def _copySessionToForm(self, session, name=None):
     """Copy relevant fields from Session to SessionForm."""
     sf = SessionForm()
     for field in sf.all_fields():
         if hasattr(session, field.name):
             if field.name == "dateTime":
                 s_date = getattr(session, field.name)
                 if s_date:
                     setattr(sf, 'dateTime', s_date.strftime('%y-%m-%d'))
                     setattr(sf, 'startTime', s_date.strftime('%H:%M'))
             elif field.name == "speaker":
                 speakerID = getattr(session, field.name)
                 # get speaker object if there is one assigend
                 if speakerID == None:
                     setattr(sf, 'speakerDisplayName', 'NONE ASSIGNED')
                 else:
                     speak = Speaker.get_by_id(speakerID)
                     setattr(sf, 'speakerDisplayName', speak.name)
             #set typeOfSession
             #if there is no typeOfSession then set it to 'NOT_SPECIFIED'
             elif field.name == "typeOfSession":
                 currentType = getattr(session, field.name)
                 if currentType:
                     setattr(sf, field.name,
                             getattr(SessionType, str(currentType)))
                 else:
                     setattr(sf, field.name,
                             getattr(SessionType, 'NOT_SPECIFIED'))
             else:
                 setattr(sf, field.name, getattr(session, field.name))
     sf.check_initialized()
     return sf
 def _copySessionToForm(self, session):
     """ Copy relevant fields from Session to SessionForm
     """
     sf = SessionForm()
     for field in sf.all_fields():
         if hasattr(session, field.name):
             # XXX Save an endTime when startTime and duration is
             # both given
             if field.name in ('date', 'startTime'):
                 # convert Date and Time to date and time string
                 setattr(sf, field.name, str(getattr(session, field.name)))
             elif field.name == 'typeOfSession':
                 # convert typeOfSession string to Enum
                 setattr(sf, field.name, getattr(SessionType,
                         getattr(session, field.name)))
             elif field.name == 'speakers':
                 setattr(sf, field.name, [str(speaker)
                         for speaker in getattr(session, field.name)])
             else:
                 # just copy the others
                 setattr(sf, field.name, getattr(session, field.name))
         elif field.name == "websafeKey":
             setattr(sf, field.name, session.key.urlsafe())
     sf.check_initialized()
     return sf
 def _copySessionToForm(self, sess):
     """Copy relevant fields from Session to SessionForm."""
     sf = SessionForm()
     for field in sf.all_fields():
         if hasattr(sess, field.name):
             # convert t-shirt string to Enum; just copy others
             if field.name == 'typeOfSession':
                 setattr(sf, field.name, getattr(TypeOfSession, getattr(
                     sess, field.name)))
             # convert date to date string
             elif field.name == 'date':
                 setattr(sf, field.name, str(getattr(sess, field.name)))
             # convert startTime to time string
             elif field.name.endswith('Time'):
                 setattr(sf, field.name, str(getattr(sess, field.name)))
             # convert startTime to time string
             elif field.name == 'duration':
                 setattr(sf, field.name, str(getattr(sess, field.name)))
             # convert Speaker keys as list to strings as a list
             elif field.name == 'speakers':
                 setattr(sf, field.name,
                         [str(s.get().name) for s in sess.speakers])
             # just copy the other fields
             else:
                 setattr(sf, field.name, getattr(sess, field.name))
         elif field.name == 'websafeKey':
             setattr(sf, field.name, sess.key.urlsafe())
         elif field.name == 'websafeConfKey':
             setattr(sf, field.name, sess.key.parent().urlsafe())
     sf.check_initialized()
     return sf
 def _copySessionToForm(self, session, name=None):
     """Copy relevant fields from Session to SessionForm."""
     sf = SessionForm()
     for field in sf.all_fields():
         if hasattr(session, field.name):
             if field.name == "dateTime":
                 s_date = getattr(session,field.name)
                 if s_date:
                     setattr(sf, 'dateTime', s_date.strftime('%y-%m-%d'))
                     setattr(sf, 'startTime', s_date.strftime('%H:%M'))
             elif field.name == "speaker":
                 speakerID = getattr(session,field.name)
                 # get speaker object if there is one assigend
                 if speakerID == None:
                     setattr(sf, 'speakerDisplayName', 'NONE ASSIGNED')
                 else:
                     speak = Speaker.get_by_id(speakerID)
                     setattr(sf, 'speakerDisplayName', speak.name)
             #set typeOfSession
             #if there is no typeOfSession then set it to 'NOT_SPECIFIED'
             elif field.name == "typeOfSession":
                 currentType = getattr(session,field.name)
                 if currentType:
                     setattr(sf, field.name, getattr(SessionType, 
                         str(currentType)))
                 else:
                     setattr(sf, field.name, getattr(SessionType, 
                         'NOT_SPECIFIED'))
             else:
                 setattr(sf, field.name, getattr(session,field.name))
     sf.check_initialized()
     return sf
 def _copySessionToForm(self, session):
     """Copy relevant fields from Session to SessionForm."""
     sf = SessionForm()
     for field in sf.all_fields():
         if hasattr(session, field.name):
             # convert Date to date string; just copy others
             if field.name.endswith('Date') or \
                field.name.endswith('Time') or \
                field.name == 'duration':
                 setattr(sf, field.name, str(getattr(session, field.name)))
             elif field.name == 'typeOfSession':
                 value = getattr(session, field.name)
                 if value:
                     value = str(getattr(session, field.name))
                 else:
                     value = 'NOT_SPECIFIED'
                 setattr(sf, field.name, getattr(SessionType, value))
             else:
                 setattr(sf, field.name, getattr(session, field.name))
         elif field.name == 'websafeKey':
             setattr(sf, field.name, session.key.urlsafe())
         elif field.name == 'conferenceWebsafeKey':
             key = session.key.parent()
             if key:
                 setattr(sf, field.name, key.urlsafe())
     sf.check_initialized()
     return sf
示例#9
0
    def _copySessionToForm(self, sess):
        """Sets the fields from Session to SessionForm"""
        sf = SessionForm()

        for field in sf.all_fields():
            if hasattr(sess, field.name):
                # If the field is the session date 'stringity' it's value
                if field.name.endswith('date'):
                    setattr(sf, field.name, str(getattr(sess, field.name)))
                elif field.name.endswith('startTime') and getattr(sess, field.name):
                    # Transform the float type of the startTime field into a
                    # string
                    if not type(getattr(sess, field.name)) is str:
                        time = str(getattr(sess, field.name)).split('.')
                        startTime = str(int((float(time[1]) / 100) * 60))[:2]
                        setattr(sf, field.name, str(time[0] + ':' + startTime))
                    else:
                        setattr(sf, field.name, str(getattr(sess, field.name)))
                else:
                    setattr(sf, field.name, getattr(sess, field.name))
            elif field.name == "websafeKey":
                # If the name is websakeKey set the urlsafe
                setattr(sf, field.name, sess.key.urlsafe())
        sf.check_initialized()
        return sf
示例#10
0
    def _copySessionToForm(self, session, name=None):
        """Copy fields from Session to SessionForm."""
        sf = SessionForm()
        for field in sf.all_fields():
            if hasattr(session, field.name):
                # convert typeOfSession to enum SessionTypes; just copy others
                if field.name == 'typeOfSession':
                    setattr(sf, field.name, getattr(SessionTypes,
                            str(getattr(session, field.name))))
                else:
                    setattr(sf, field.name, getattr(session, field.name))
            elif field.name == "websafeKey":
                setattr(sf, field.name, session.key.urlsafe())
            elif field.name == "speakerDisplayName":
                setattr(sf, field.name, name)

            # convert startDateTime from session
            # model to date and startTime for session Form
            startDateTime = getattr(session, 'startDateTime')
            if startDateTime:
                if field.name == 'date':
                    setattr(sf, field.name, str(startDateTime.date()))
                str_dt = startDateTime.time().strftime('%H:%M')
                f_nam = field.name
                if hasattr(session, 'startDateTime') and f_nam == 'startTime':
                    setattr(sf, field.name, str(str_dt))
        sf.check_initialized()
        return sf
示例#11
0
    def _copySessionToForm(self, sess):
        """Copy relevant fields from Session to SessionForm."""

        sf = SessionForm()
        for field in sf.all_fields():
            if hasattr(sess, field.name):
                if field.name == 'date':
                    sf.date = str(sess.date)
                elif field.name == 'timeStart':
                    sf.timeStart = str(sess.timeStart)
                elif field.name == 'timeEnd':
                    sf.timeEnd = str(sess.timeEnd)
                elif field.name == 'duration':
                    sf.timeEnd = str(sess.timeEnd)
                elif field.name == 'typeOfSession':
                    try:
                        setattr(
                            sf, field.name,
                            getattr(SessionType, getattr(sess, field.name)))
                    except AttributeError:
                        setattr(sf, field.name,
                                getattr(SessionType, 'NOT_SPECIFIED'))
                else:
                    setattr(sf, field.name, getattr(sess, field.name))
        sf.websafeKey = sess.key.urlsafe()
        sf.check_initialized()

        return sf
示例#12
0
    def _copySessionToForm(self, session):
        """Copy relevant fields from Session to SessionForm."""
        sform = SessionForm()
        print session
        setattr(sform, 'sessionWebsafeKey', session.key.urlsafe() )
        # get speaker properties
        speaker = getattr(session, 'speakerKey').get()

        if speaker:
            setattr(sform, 'speakerName', str(speaker.fullname) )
            setattr(sform, 'speakerProfession', str(speaker.profession) )
        else:
            setattr(sform, 'speakerName', "None" )
            setattr(sform, 'speakerProfession', "None" )

        for field in sform.all_fields():
            if hasattr(session, field.name):
                if field.name.endswith('date') or field.name.endswith('startTime'):
                    setattr(sform, field.name, str(getattr(session, field.name)))
                elif field.name.endswith('speakerKey'):
                    # extract the name entity to string
                    print "Speaker KEy found"
                    fullname = session.speakerKey.get().fullname
                    profession = session.speakerKey.get().profession
                    setattr(sform, 'speakerName', "Test1234")
                    setattr(sform, 'speakerProfession', str(getattr(session, profession)))
                else:
                    setattr(sform, field.name, getattr(session, field.name))

        sform.check_initialized()
        return sform
示例#13
0
    def _copySessionToForm(self, sess):
        """Copy relevant fields from Session to SessionForm."""
        sf = SessionForm()
        for field in sf.all_fields():
            if hasattr(sess, field.name):
                if field.name == 'speaker':
                    sf.speaker = SpeakerForm(
                        name=sess.speaker.name,
                        email=sess.speaker.email,
                        websafeSpeakerKey=sess.speaker.websafeSpeakerKey,
                    )

                # convert sessionType string to Enum
                elif field.name == 'sessionType':
                    setattr(sf, field.name,
                            getattr(SessionType, getattr(sess, field.name)))
                # convert Date to date string
                elif field.name == 'date':
                    setattr(sf, field.name, str(getattr(sess, field.name)))
                # just copy others
                else:
                    setattr(sf, field.name, getattr(sess, field.name))
            # get the websafe session key
            elif field.name == 'websafeKey':
                setattr(sf, field.name, sess.key.urlsafe())
        sf.check_initialized()
        return sf
示例#14
0
 def _copySessionToForm(self, sess):
     """Copy relevant fields from Session to SessionForm."""
     sf = SessionForm()
     for field in sf.all_fields():
         if hasattr(sess, field.name):
             # convert t-shirt string to Enum; just copy others
             if field.name == 'typeOfSession':
                 setattr(sf, field.name,
                         getattr(TypeOfSession, getattr(sess, field.name)))
             # convert date to date string
             elif field.name == 'date':
                 setattr(sf, field.name, str(getattr(sess, field.name)))
             # convert startTime to time string
             elif field.name.endswith('Time'):
                 setattr(sf, field.name, str(getattr(sess, field.name)))
             # convert startTime to time string
             elif field.name == 'duration':
                 setattr(sf, field.name, str(getattr(sess, field.name)))
             # convert Speaker keys as list to strings as a list
             elif field.name == 'speakers':
                 setattr(sf, field.name,
                         [str(s.get().name) for s in sess.speakers])
             # just copy the other fields
             else:
                 setattr(sf, field.name, getattr(sess, field.name))
         elif field.name == 'websafeKey':
             setattr(sf, field.name, sess.key.urlsafe())
         elif field.name == 'websafeConfKey':
             setattr(sf, field.name, sess.key.parent().urlsafe())
     sf.check_initialized()
     return sf
示例#15
0
 def _copySessionToForm(self, sess):
     """Copy relevant fields from Session to SessionForm."""
     sf = SessionForm()
     for field in sf.all_fields():
         if hasattr(sess, field.name):
             # Convert Date to string
             # Convert Time to string in HH:MM only
             # else convert others as is
             if field.name.endswith('date'):
                 setattr(sf, field.name, str(getattr(sess, field.name)))
             elif field.name.endswith('Time'):
                 setattr(sf, field.name,
                         str(getattr(sess, field.name).strftime("%H:%M")))
             else:
                 setattr(sf, field.name, getattr(sess, field.name))
         elif field.name == "sessionWebSafeKey":
             setattr(sf, field.name, sess.key.urlsafe())
         elif field.name == "speakerName":
             try:
                 speaker = sess.speaker.get()
                 speakerName = "%s %s" % (getattr(speaker, "firstName"),
                                          getattr(speaker, "lastName"))
                 setattr(sf, 'speakerName', speakerName)
             except:
                 pass
     sf.check_initialized()
     return sf
    def _copyConferenceSessionToForm(self, session):
        """Copy relevant fields from Session to SessionForm."""

        sf = SessionForm()
        
        for field in sf.all_fields():
        
            if hasattr(session, field.name):
        
                # Convert date and startTime fields to strings
                if field.name == 'date' or field.name == 'startTime':
        
                    setattr(sf, field.name, str(getattr(session, field.name)))
        
                # Convert typeOfSession to enum
                elif field.name == 'typeOfSession':
                    
                    # set typeOfSession equal to enum 
                    setattr(
                        sf, field.name, getattr(
                            SessionType, getattr(session, field.name)))
                
                else:
                
                    setattr(sf, field.name, getattr(session, field.name))
            
            # Convert DataStore keys to URLSafe keys
            elif field.name == 'parentKey' or field.name == 'speakerKey':
            
                setattr(sf, field.name, session.key.urlsafe())
        
        sf.check_initialized()
        
        return sf
 def _copySessionToForm(self, sess):
     """Copy relevant fields from sessions to SessionsForm."""
     sf = SessionForm()
     s_key = sess.key.urlsafe()
     c_key = ""
     if sess.key.parent():
         c_key = sess.key.parent().urlsafe()
     for field in sf.all_fields():
         if hasattr(sess, field.name):
             # convert Date to date string; just copy others
             if field.name.endswith('date'):
                 # convert Date object to string                    
                 date = str(getattr(sess, field.name))
                 setattr(sf, field.name, date)
             elif field.name.endswith('startTime'):
                 # convert Time object to string
                 time = str(getattr(sess, field.name))
                 setattr(sf, field.name, time)
             elif field.name.endswith('duration'):
                 # convert duration to string
                 duration = str(getattr(sess, field.name))
                 setattr(sf, field.name, duration)
             else:
                 setattr(sf, field.name, getattr(sess, field.name))
         elif field.name == "websafeConferenceKey":
             setattr(sf, field.name, c_key)
         elif field.name == "websafeSessionKey":
             setattr(sf, field.name, s_key)
     sf.check_initialized()
     return sf
 def _copySessionToForm(self, _session):
     """Copy relevant fields from Session to SessionForm."""
     sf = SessionForm()
     for field in sf.all_fields():
         if hasattr(_session, field.name):
             if (field.name == 'date' or field.name == 'startTime'):
                 setattr(sf, field.name, str(getattr(_session, field.name)))
             elif (field.name == 'speaker'):
                 if (getattr(_session, 'speaker')):
                     speaker = getattr(_session, 'speaker').get()
                     setattr(sf, 'speakerName', speaker.displayName)
                     setattr(
                         sf,
                         field.name,
                         getattr(_session, 'speaker').urlsafe()
                     )
                 else:
                     setattr(sf, 'speakerName', 'TBA')
                     setattr(sf, field.name, None)
             else:
                 setattr(sf, field.name, getattr(_session, field.name))
         elif field.name == "websafeKey":
             setattr(sf, field.name, _session.key.urlsafe())
     sf.check_initialized()
     return sf
示例#19
0
    def _copySessionToForm(self, sess):
        """
        Copy relevant fields from Session to SessionForm.

        :param sess: Session object
        :return: SessionForm
        """
        # Get empty SessionForm
        sf = SessionForm()

        # Copy fields from Session to SessionForm
        for field in sf.all_fields():
            if hasattr(sess, field.name):

                # Convert data into appropriate format
                if field.name == 'sess_time':
                    setattr(sf, 'sess_time',
                            str(getattr(sess, 'sess_time'))[:5])
                elif field.name == 'sess_date':
                    setattr(sf, 'sess_date',
                            str(getattr(sess, 'sess_date'))[:10])
                else:
                    setattr(sf, field.name, getattr(sess, field.name))
        sf.check_initialized()
        return sf
    def _copySessionToForm(self, session):
        """Copies relevant fields from a Session to a SessionForm.
        """
        # copy relevant fields from Session to SessionForm
        session_form = SessionForm()
        for field in session_form.all_fields():
            if hasattr(session, field.name):
                if field.name in ('date', 'startTime', 'duration'):
                    setattr(session_form, field.name,
                            str(getattr(session, field.name)))
                elif field.name == 'typeOfSession':
                    setattr(session_form, field.name,
                            getattr(SessionType, getattr(session, field.name)))
                elif field.name == 'speakers':
                    setattr(session_form, field.name,
                            [str(s.get().name) for s in session.speakers])
                else:
                    setattr(session_form, field.name,
                            getattr(session, field.name))
            elif field.name == "websafeKey":
                setattr(session_form, field.name,
                        session.key.urlsafe())
            elif field.name == "websafeConferenceKey":
                setattr(session_form, field.name,
                        session.key.parent().urlsafe())

        session_form.check_initialized()

        return session_form
    def _copySessionToForm(self, session):
        """ Copy relevant fields from Session to SessionForm.
        Set the speakerName using the second passed argument.
    """
        sf = SessionForm()
        date = getattr(session, "date")
        startTime = getattr(session, "startTime")
        endTime = getattr(session, "endTime")

        # copy duration
        if startTime and endTime:
            duration = (endTime.hour * 60 + endTime.minute) \
                      - (startTime.hour * 60 + startTime.minute)
        else:
            duration = 0

        # copy other fields
        setattr(sf, "name", getattr(session, "name"))
        setattr(sf, "highlights", getattr(session, "highlights"))
        setattr(sf, "typeOfSession",
                getattr(SessionType, getattr(session, "typeOfSession")))
        setattr(sf, "speaker", getattr(session, "speaker"))
        setattr(sf, "date", str(date))
        setattr(sf, "startTime", str(startTime))
        setattr(sf, "duration", duration)
        setattr(sf, "wssk", session.key.urlsafe())
        sf.check_initialized()
        return sf
示例#22
0
    def _copySessionToForm(self, sess):
        """Copy relevant fields from Session to SessionForm."""
        sf = SessionForm()
        for field in sf.all_fields():
            if hasattr(sess, field.name):
                # convert Date to date string; just copy others
                if field.name in ["startTime", "date"]:
                    setattr(sf, field.name, str(getattr(sess, field.name)))
                # get the websafe key from session to display
                elif field.name == "speakerKeys":
                    spkrs = getattr(sess, field.name)
                    spkrs = [s.urlsafe() for s in spkrs]
                    setattr(sf, field.name, spkrs)
                else:
                    setattr(sf, field.name, getattr(sess, field.name))
            # show's the speaker's names
            if field.name == "speakerNames":
                spkrs = getattr(sess, "speakerKeys")
                spkrs = [s.get().name for s in spkrs]
                setattr(sf, field.name, spkrs)
            if field.name == "websafeSessionKey":
                webKey = sess.key.urlsafe()
                setattr(sf, field.name, webKey)

        sf.check_initialized()
        return sf
 def _copySessionToForm(self, session):
     """Copy relevant fields from Session to SessionForm."""
     sf = SessionForm()
     for field in sf.all_fields():
         if hasattr(session, field.name):
             # convert date and time to strings;
             if field.name.endswith('date'):
                 setattr(sf, field.name, str(getattr(session, field.name)))
             elif field.name.endswith('startTime'):
                 setattr(sf, field.name, str(getattr(session, field.name)))
             # convert Speaker url safe key to speaker name
             elif field.name.endswith('speaker'):
                 speaker_key = getattr(session, field.name)
                 if speaker_key is not None:
                     speaker = speaker_key.get()
                     setattr(sf, field.name, speaker.name)
                 else:
                     setattr(sf, field.name, None)
             # just copy others
             else:
                 setattr(sf, field.name, getattr(session, field.name))
         # convert key to urlsafe
         elif field.name == "websafeConferenceKey":
             setattr(sf, field.name, session.key.parent().urlsafe())
         elif field.name == "websafeKey":
             setattr(sf, field.name, session.key.urlsafe())
     sf.check_initialized()
     return sf
    def _copySessionToForm(self, session):
        """
        Input:
            session: Session object
        Returns:
            SessionForm
        Description:
            This method takes a session object with values defined from client
            side and returns the SessionFrom after copying the relevant fields in
            it which can be returned to client as ProRPC Message.
        """
        sessionform = SessionForm()
        for field in sessionform.all_fields():
            if hasattr(session, field.name):
                # convert Date to date string; just copy others
                if field.name.endswith('date'):
                    setattr(sessionform, field.name,
                            str(getattr(session, field.name)))
                else:
                    setattr(sessionform, field.name,
                            getattr(session, field.name))
            # Checks if the field is websafeSessionKey, then converts it into
            # urlsafe key
            elif field.name == "websafeSessionKey":
                setattr(sessionform, field.name, session.key.urlsafe())

        sessionform.check_initialized()
        return sessionform
示例#25
0
 def _copySessionToForm(self, session):
     """Copy relevant fields from Session to SessionForm."""
     # copy relevant fields from Session to SessionForm
     form = SessionForm()
     setattr(form, 'websafeKey', session.key.urlsafe())
     for field in form.all_fields():
         if hasattr(session, field.name):
             # convert session type enum to string; just copy others
             if field.name == 'typeOfSession':
                 if getattr(session, field.name) == '' or getattr(session, field.name) is None:
                     setattr(form, field.name, 'Other')
                 else:
                     setattr(form, field.name, getattr(SessionType, 
                         getattr(session, field.name)))
             elif field.name == 'conferenceKey' or field.name == 'speakerKey':
                 value = getattr(session, field.name)
                 if value is not None:
                     setattr(form, field.name, 
                         getattr(session, field.name).urlsafe())
                 else:
                     setattr(form, field.name, '')
             elif field.name == 'startTime' or field.name == 'date':
                 setattr(form, field.name, 
                     str(getattr(session, field.name)))
             else:
                 setattr(form, field.name, 
                     getattr(session, field.name))
     form.check_initialized()
     return form
 def _copySessionToForm(self, session):
     """ Copy relevant fields from Session to SessionForm
     """
     sf = SessionForm()
     for field in sf.all_fields():
         if hasattr(session, field.name):
             # XXX Save an endTime when startTime and duration is
             # both given
             if field.name in ('date', 'startTime'):
                 # convert Date and Time to date and time string
                 setattr(sf, field.name, str(getattr(session, field.name)))
             elif field.name == 'typeOfSession':
                 # convert typeOfSession string to Enum
                 setattr(sf, field.name,
                         getattr(SessionType, getattr(session, field.name)))
             elif field.name == 'speakers':
                 setattr(sf, field.name, [
                     str(speaker)
                     for speaker in getattr(session, field.name)
                 ])
             else:
                 # just copy the others
                 setattr(sf, field.name, getattr(session, field.name))
         elif field.name == "websafeKey":
             setattr(sf, field.name, session.key.urlsafe())
     sf.check_initialized()
     return sf
示例#27
0
    def _copySessionToForm(self, session_object):
        """Copy relevant fields from Session to SessionForm."""
        sf = SessionForm()
        for field in sf.all_fields():
            if hasattr(session_object, field.name):
                # convert Date/Time to date/time string; just copy others
                if field.name.endswith('date') or field.name == 'start_time':
                    setattr(sf, field.name,
                            str(getattr(session_object, field.name)))
                elif field.name == "speaker_key":
                    setattr(sf, field.name,
                            session_object.speaker_key.urlsafe())
                    speaker = session_object.speaker_key.get()
                    setattr(sf, "speaker_name", speaker.name)
                else:
                    setattr(sf, field.name,
                            getattr(session_object, field.name))
            elif field.name == "websafe_key":
                setattr(sf, field.name, session_object.key.urlsafe())
        if session_object.speaker_key:
            speaker = session_object.speaker_key.get()
            setattr(sf, 'speaker_name', speaker.name)

        sf.check_initialized()
        return sf
示例#28
0
    def _copySessionToForm(self, sess):
        """Copy relevant fields from Session to SessionForm."""
        sf = SessionForm()
        for field in sf.all_fields():
            if hasattr(sess, field.name):
                # convert Date to date string; just copy others
                if field.name in ['startTime', 'date']:
                    setattr(sf, field.name, str(getattr(sess, field.name)))
                #get the websafe key from session to display
                elif field.name == 'speakerKeys':
                    spkrs = getattr(sess, field.name)
                    spkrs = [s.urlsafe() for s in spkrs]
                    setattr(sf, field.name, spkrs)
                else:
                    setattr(sf, field.name, getattr(sess, field.name))
            #show's the speaker's names
            if field.name == 'speakerNames':
                spkrs = getattr(sess, 'speakerKeys')
                spkrs = [s.get().name for s in spkrs]
                setattr(sf, field.name, spkrs)
            if field.name == 'websafeSessionKey':
                webKey = sess.key.urlsafe()
                setattr(sf, field.name, webKey)

        sf.check_initialized()
        return sf
 def _copySessionToForm(self, session, conf):
     """ Copy items from the Session object to the SessionForm object """
     sf = SessionForm()
     speaker = ndb.Key(urlsafe=session.speaker_key).get()
     print "This is the session's speaker: ", speaker
     for field in sf.all_fields():
         print "This is the field: ", field.name
         if hasattr(session, field.name):
             # convert t-shirt string to Enum; just copy others
             if field.name == 'date':
                 setattr(sf, field.name, getattr(session, field.name).strftime("%Y-%m-%d"))
             elif field.name == 'start_time':
                 setattr(sf, field.name, getattr(session, field.name).strftime("%H:%M"))
             elif field.name == 'type_of_session':
                 try:
                     setattr(sf, field.name, getattr(TypeOfSession, getattr(session, field.name)))
                 except AttributeError:
                     setattr(sf, field.name, getattr(TypeOfSession, 'NOT_SPECIFIED'))
             else:
                 setattr(sf, field.name, getattr(session, field.name))
         elif field.name == "conf_websafekey":
             setattr(sf, field.name, conf.key.urlsafe())
         elif field.name == "sess_websafekey":
             setattr(sf, field.name, session.key.urlsafe())
         elif field.name == 'speaker_name':
             setattr(sf, field.name, speaker.name)
         elif field.name == 'speaker_email':
             setattr(sf, field.name, speaker.email)
         elif field.name == 'speaker_speciality':
             setattr(sf, field.name, speaker.speciality)
     sf.check_initialized()
     return sf
 def _copySessionToForm(self, session):
     """Copy relevant fields from Session to SessionForm."""
     # copy relevant fields from Session to SessionForm
     form = SessionForm()
     setattr(form, 'websafeKey', session.key.urlsafe())
     for field in form.all_fields():
         if hasattr(session, field.name):
             # convert session type enum to string; just copy others
             if field.name == 'typeOfSession':
                 setattr(form, field.name,
                         getattr(SessionType, getattr(session, field.name)))
             elif field.name == 'conferenceId':
                 setattr(form, field.name,
                         str(getattr(session, field.name).id()))
             elif field.name == 'speaker':
                 setattr(form, field.name,
                         getattr(session, field.name).get().name)
             elif field.name == 'startTime':
                 setattr(form, field.name, str(getattr(session,
                                                       field.name)))
             elif field.name == 'date':
                 setattr(form, field.name, str(getattr(session,
                                                       field.name)))
             else:
                 setattr(form, field.name, getattr(session, field.name))
     form.check_initialized()
     return form
    def _copySessionToForm(self, sess):
        """Copy relevant fields from Session to SessionForm."""
        sf = SessionForm()
        for field in sf.all_fields():
            setattr(sf, field.name, getattr(sess, field.name))

        sf.check_initialized()
        return sf
 def _copySessionToForm(self, ss):
     """Copy relevant fields from Session to SessionForm."""
     sForm = SessionForm()
     for field in sForm.all_fields():
         if hasattr(ss, field.name):
                 setattr(sForm, field.name, getattr(ss, field.name))
     
     sForm.check_initialized()
     return sForm
 def _copySessionToForm(self, session):
     """Makes a SessionForm from a Session"""
     sf = SessionForm()
     for field in sf.all_fields():
         if hasattr(session, field.name):
             # convert Date to date string; just copy others
             setattr(sf, field.name, getattr(session, field.name))
     sf.check_initialized()
     return sf
示例#34
0
    def _copySessionToForm(self, session):
        sf = SessionForm()
        setattr(sf, 'sessionKey', session.key.urlsafe())
        for field in sf.all_fields():
            if hasattr(session, field.name):
                setattr(sf, field.name, getattr(session, field.name))

        sf.check_initialized()
        return sf
 def _copySessionToForm(self, session):
     """Copy relevant fields from Session to SessionForm."""
     sf = SessionForm()
     for field in sf.all_fields():
         if hasattr(session, field.name):
            setattr(sf, field.name, getattr(session, field.name))
         elif field.name == "websafeSessionKey":
             setattr(sf, field.name, session.key.urlsafe())
     sf.check_initialized()
     return sf
示例#36
0
 def _copySessionRequestToForm(self, request):
     """Copy relevant fields from Session to SessionForm."""
     sf = SessionForm()
     for field in sf.all_fields():
         if hasattr(request, field.name):
             rval = getattr(request, field.name)
             if rval:
                 setattr(sf, field.name, rval)
     sf.check_initialized()
     return sf
示例#37
0
 def _copySessionToForm(self, sess):
     """Copy relevant fields from Session to SessionForm."""
     cf = SessionForm()
     for field in cf.all_fields():
         if hasattr(sess, field.name):
             if field.name.endswith('Time') or field.name.endswith('date'):
                 setattr(cf, field.name, str(getattr(sess, field.name)))
             else:
                 setattr(cf, field.name, getattr(sess, field.name))
     cf.check_initialized()
     return cf
示例#38
0
 def _copySessionFeaturedSpeakerToForm(self, sess):
   """ copy the featured speaker name to the form before returning it as a response """
   sf = SessionForm()
   for field in sf.all_fields():
     if hasattr(sess, field.name):
       if field.name == "speaker":
         setattr(sf, field.name, getattr(sess, field.name))
       if field.name == "name":
         setattr(sf, field.name, str(getattr(sess, field.name)))
   sf.check_initialized()
   return sf
示例#39
0
 def _copySessionToForm(self, session):
     """Copy relevant fields from Session to SessionForm"""
     sf = SessionForm()
     for field in sf.all_fields():
         if hasattr(session, field.name):
             setattr(sf, field.name, str(getattr(session, field.name)))
         #Generate a Session, urlsafe key, in order to query sessions etc
         elif field.name == 'urlsafeKey':
             setattr(sf, field.name, session.key.urlsafe())
     sf.check_initialized()
     return sf
示例#40
0
 def _copySessionToForm(self, sess):
     """Copy relevant fields from Session to SessionForm."""
     cf = SessionForm()
     for field in cf.all_fields():
         if hasattr(sess, field.name):
             if field.name.endswith('Time') or field.name.endswith('date'):
                 setattr(cf, field.name, str(getattr(sess, field.name)))
             else:
                 setattr(cf, field.name, getattr(sess, field.name))
     cf.check_initialized()
     return cf
示例#41
0
 def _copySessionToForm(self, sess):
     """Copy relevant fields from Session to SessionForm."""
     sf = SessionForm()
     for field in sf.all_fields():
         if hasattr(sess, field.name):
             # convert Date to date string; just copy others
             if field.name.endswith('Date'):
                 setattr(sf, field.name, str(getattr(sess, field.name)))
             else:
                 setattr(sf, field.name, getattr(sess, field.name))
     sf.check_initialized()
     return sf
 def _copySessionToForm(self, sess):
     """Copy fields from Session to SessionForm"""
     sf = SessionForm()
     for field in sf.all_fields():
         if hasattr(sess, field.name):
             #convert all to string, except duration
             if field.name != "duration":
                 setattr(sf, field.name, str(getattr(sess, field.name)))
         elif field.name == "websafeSessionKey":
             setattr(sf, field.name, sess.key.urlsafe())
     sf.check_initialized()
     return sf
 def _copySessionToForm(self, session):
     form = SessionForm()
     for field in form.all_fields():
         if hasattr(session, field.name):
             if field.name == 'startTime':
                 setattr(form, 'startTime',
                         str(getattr(session, 'startTime')))
             else:
                 setattr(form, field.name, getattr(session, field.name))
     # set urlsafe id
     setattr(form, "urlsafe_id", session.key.urlsafe())
     form.check_initialized()
     return form
示例#44
0
 def _copySessionToForm(self, request):
     sf = SessionForm()
     data = {field.name: getattr(request, field.name) for field in sf.all_fields()}
     for field in sf.all_fields():
         if hasattr(request, field.name):
             if field.name == 'date':
                 setattr(sf, field.name, str(getattr(request, field.name)))
             elif field.name == 'startTime':
                     if data['startTime']:
                         setattr(sf, field.name, int(getattr(request, field.name)))
             else:
                 setattr(sf, field.name, getattr(request, field.name))
     sf.check_initialized()
     return sf
示例#45
0
 def _copySessionToForm(self, session):
     """copy model Session to SessionForm"""
     s = SessionForm()
     for field in s.all_fields():
         if hasattr(session, field.name):
             # convert DATE and Time property  to string
             if field.name in ['date', 'startTime']:
                 setattr(s, field.name, str(getattr(session, field.name)))
             else:
                 setattr(s, field.name, getattr(session, field.name))
         elif field.name == "websafeSessionKey":
             setattr(s, field.name, session.key.urlsafe())
     s.check_initialized()
     return s
示例#46
0
 def _copySessionToForm(self, session):
     """Copy relevant fields from Session to SessionForm."""
     sf = SessionForm()
     for field in sf.all_fields():
         if hasattr(session, field.name):
             # convert Date and Time to date string; just copy others
             if field.name in ['startTime', 'date']:
                 setattr(sf, field.name, str(getattr(session, field.name)))
             else:
                 setattr(sf, field.name, getattr(session, field.name))
         elif field.name == "websafeKey":
             setattr(sf, field.name, session.key.urlsafe())
     sf.check_initialized()
     return sf
 def _copySessionToForm(self, session):
     """Copy relevant fields from Session to SessionForm."""
     ss = SessionForm()
     for field in ss.all_fields():
         if hasattr(session, field.name):
             # convert Date to date string; just copy others
             if field.name.endswith('date') or field.name.endswith('startTime'):
                 setattr(ss, field.name, str(getattr(session, field.name)))
             else:
                 setattr(ss, field.name, getattr(session, field.name))
         elif field.name == "sessionSafeKey":
             setattr(ss, field.name, session.key.urlsafe())
     ss.check_initialized()
     return ss
示例#48
0
 def _copySessionToForm(self, sess):
     """Copy relevant fields from Session to SessionForm"""
     sf = SessionForm()
     for field in sf.all_fields():
         if hasattr(sess, field.name):
             # convert date/time/duration to string; just copy others
             if field.name in ('date', 'startTime', 'duration'):
                 setattr(sf, field.name, str(getattr(sess, field.name)))
             else:
                 setattr(sf, field.name, getattr(sess, field.name))
         elif field.name == "websafeKey":
             setattr(sf, field.name, sess.key.urlsafe())
     sf.check_initialized()
     return sf
示例#49
0
 def _copySessionToForm(self, session):
     """Copy relevant fields from Session to SessionForm."""
     sf = SessionForm()
     logging.debug(type(session))
     for field in sf.all_fields():
         if hasattr(session, field.name):
             # convert Date to date string; just copy others
             if field.name.endswith('Date'):
                 setattr(sf, field.name, str(getattr(session, field.name)))
             else:
                 setattr(sf, field.name, getattr(session, field.name))
         elif field.name == "websafeSessionKey":
             setattr(sf, field.name, session.key.urlsafe())
     sf.check_initialized()
     return sf
 def _copySessionToForm(self, sess):
     """Copy relevant fields from Conference to ConferenceForm."""
     sf = SessionForm()
     for field in sf.all_fields():
         if hasattr(sess, field.name):
             # convert Date to date string; just copy others
             if field.name.endswith('data'):
                 setattr(sf, field.name, str(getattr(sess, field.name)))
             if field.name.endswith('time'):
                 setattr(sf, field.name, str(getattr(sess, field.name)))
             else:
                 setattr(sf, field.name, getattr(sess, field.name))
     setattr(sf, 'sess_key', sess.key.urlsafe())
     sf.check_initialized()
     return sf
示例#51
0
 def _copySessionToForm(self, sess):
     """Copy relevant fields from Session to SessionForm."""
     sf = SessionForm()
     # set fields of form with attributes
     for field in sf.all_fields():
         if hasattr(sess, field.name):
             # convert Date to date string; just copy others
             if (field.name.endswith('date')) or (field.name.endswith('Time')):
                 setattr(sf, field.name, str(getattr(sess, field.name)))
             else:
                 setattr(sf, field.name, getattr(sess, field.name))
         elif field.name == "websafeKey":
                 setattr(sf, field.name, sess.key.urlsafe())
     sf.check_initialized()
     return sf
 def _copySessionToForm(self, session):
     """Copy relevant fields from Conference to ConferenceForm."""
     # copy relevant fields from Sesson to SessionForm
     sf = SessionForm()
     for field in sf.all_fields():
         if hasattr(session, field.name):
             # convert typeOfSession; just copy others
             if field.name == "typeOfSession":
                 setattr(
                     sf, field.name,
                     getattr(TypeOfSession, getattr(session, field.name)))
             else:
                 setattr(sf, field.name, getattr(session, field.name))
     sf.check_initialized()
     return sf
示例#53
0
    def _copySessionToForm(self, sess):
        """Copy relevant fields from Session to SessionForm."""
        sf = SessionForm()
        for field in sf.all_fields():
            if hasattr(sess, field.name):
                # convert Date to date string; just copy others
                if field.name.endswith('date') or field.name.endswith('Time'):
                    setattr(sf, field.name, str(getattr(sess, field.name)))
                else:
                    setattr(sf, field.name, getattr(sess, field.name))

        # set the websafeKey to the Session Form so it can be returned with a websafeKey that the user can use
        setattr(sf, 'websafeKey', sess.key.urlsafe())
        sf.check_initialized()
        return sf
示例#54
0
 def _copySessionToForm(self, mysession):
     """Copy relevant fields from Session to SessionForm."""
     cf = SessionForm()
     for field in cf.all_fields():
         if hasattr(mysession, field.name):
             # convert Date to date string; just copy others
             if field.name.endswith('Date'):
                 setattr(cf, field.name, str(getattr(mysession,
                                                     field.name)))
             else:
                 setattr(cf, field.name, getattr(mysession, field.name))
         elif field.name == "websafeKey":
             setattr(cf, field.name, mysession.key.urlsafe())
     cf.check_initialized()
     return cf
示例#55
0
    def _copySessionToForm(self, session):
        """Copy relevant fields from Session to SessionForm."""
        sf = SessionForm()
        for field in sf.all_fields():
            if hasattr(session, field.name):

                if field.name == 'date':
                    setattr(sf, field.name, str(getattr(session, field.name)))
                elif field.name == 'startTime':
                    setattr(sf, field.name, str(getattr(session, field.name)))
                else:
                    setattr(sf, field.name, getattr(session, field.name))
            elif field.name == "websafeKey":
                setattr(sf, field.name, session.key.urlsafe())
        sf.check_initialized()
        return sf
 def _copySessionToForm(self, sess):
     """Copy relevant fields from Session to SessionForm."""
     sf = SessionForm()
     for field in sf.all_fields():
         if hasattr(sess, field.name):
             setattr(sf, field.name, getattr(sess, field.name))
         elif field.name == "websafeSessionKey":
             setattr(sf, field.name, sess.key.urlsafe())
     # convert Date to date string
     if hasattr(sess, 'date') and hasattr(sess, 'time'):
         date = getattr(sess, 'date')
         time = getattr(sess, 'time')
         if date and time:
             setattr(sf, 'dateTime', datetime.combine(date, time))
     sf.check_initialized()
     return sf