Ejemplo n.º 1
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
Ejemplo n.º 2
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
Ejemplo n.º 3
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
Ejemplo n.º 4
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
 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
Ejemplo n.º 6
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
Ejemplo n.º 7
0
 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 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
Ejemplo n.º 9
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
Ejemplo n.º 10
0
 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."""
     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
Ejemplo n.º 12
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
Ejemplo n.º 13
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
Ejemplo n.º 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):
                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
Ejemplo n.º 15
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
Ejemplo n.º 16
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
Ejemplo n.º 17
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
Ejemplo n.º 18
0
    def _createSessionObject(self, request):
        """Create or update Session object, returning SessionForm/request."""
        # preload necessary data items
        user = endpoints.get_current_user()
        if not user:
            raise endpoints.UnauthorizedException('Authorization required')
        user_id = getUserId(user)

        # get existing conference
        conf = ndb.Key(urlsafe=request.websafeConferenceKey).get()
        # check that conference exists
        if not conf:
            raise endpoints.NotFoundException(
                'No conference found with key: %s' % request.websafeConferenceKey)

        # check that user is owner
        if user_id != conf.organizerUserId:
            raise endpoints.ForbiddenException(
                'Only the owner can a create session.')

        if not request.name:
            raise BadRequestException("Session 'name' field required")

        # generate Conference Key based on conference ID and Session
        # ID based on Profile key get Conference key from ID
        c_key = ndb.Key(Conference, request.websafeConferenceKey)
        s_id = Session.allocate_ids(size=1, parent=c_key)[0]
        s_key = ndb.Key(Session, s_id, parent=c_key)

        # copy SessionForm/ProtoRPC Message into dict
        sf = SessionForm()
        data = {}
        data['key'] = s_key
        setattr(sf, 'sessionKey', s_key.urlsafe())
        for field in sf.all_fields():
            if hasattr(request, field.name):
                attribute = getattr(request, field.name)
                if field.name == 'date':
                    try:
                        datetime.strptime(attribute, "%Y-%m-%d")
                    except:
                        raise BadRequestException(
                            "Session 'date' format is 'yyyy-mm-dd'")
                elif field.name == 'startTime':
                    try:
                        datetime.strptime(attribute, "%H:%M")
                    except:
                        raise BadRequestException(
                            "Session 'startTime' format is 'hh:mm' (24-hour clock)")

                setattr(sf, field.name, attribute)
                data[field.name] = attribute

        del data["sessionKey"]
        Session(**data).put()

        taskqueue.add(params={'speaker': data['speaker']},
                      url='/tasks/update_featured_speaker')

        return sf
Ejemplo n.º 19
0
    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
Ejemplo n.º 20
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
Ejemplo n.º 21
0
 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
Ejemplo n.º 22
0
    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
Ejemplo n.º 23
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':
                 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
Ejemplo n.º 24
0
 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
Ejemplo n.º 25
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):
        """
        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, 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
Ejemplo n.º 28
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' 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
 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
Ejemplo n.º 30
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
 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():
            setattr(sf, field.name, getattr(sess, field.name))

        sf.check_initialized()
        return sf
Ejemplo n.º 33
0
 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
Ejemplo n.º 34
0
 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
Ejemplo n.º 35
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
Ejemplo n.º 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
 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
Ejemplo n.º 38
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
Ejemplo n.º 39
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
Ejemplo n.º 40
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
Ejemplo n.º 42
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):
             #conver Date and DateTime to string and copy others
             if field.name.endswith(('Time', '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())
     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
Ejemplo n.º 44
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
 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
Ejemplo n.º 46
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
Ejemplo n.º 47
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
Ejemplo n.º 48
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
Ejemplo n.º 49
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, 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
 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
Ejemplo n.º 52
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
Ejemplo n.º 53
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
Ejemplo n.º 54
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
Ejemplo n.º 55
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):
             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