当前位置: 首页>>代码示例>>Python>>正文


Python Session.typeOfSession方法代码示例

本文整理汇总了Python中models.Session.typeOfSession方法的典型用法代码示例。如果您正苦于以下问题:Python Session.typeOfSession方法的具体用法?Python Session.typeOfSession怎么用?Python Session.typeOfSession使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Session的用法示例。


在下文中一共展示了Session.typeOfSession方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: createSession

# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import typeOfSession [as 别名]
    def createSession(self, request):
        """ Creates Session from given SESSION_POST_REQUEST_FOR_CONFERENCE and returns a SessionForm."""
        # (SessionForm, websafeConferenceKey) -- open only to the organizer of the conference
        profile = self._getProfileFromUser()
        conf = ndb.Key(urlsafe=request.websafeConferenceKey).get()
        if not conf:
            raise endpoints.NotFoundException(
                'No conference found with key: %s' % request.websafeConferenceKey)
        if conf.key.parent().get() != profile:
            raise endpoints.UnauthorizedException('Session creation is open only to the organizer of the conference!')

        # copy SESSION_POST_REQUEST_FOR_CONFERENCE/ProtoRPC Message into dict
        data = {field.name: getattr(request, field.name) for field in request.all_fields()}
        session = Session(name=data['name'],parent=conf.key)

        # convert dates from strings to Date objects; set month based on start_date
        if data['dateTime']:
            session.date = data['dateTime'].date()
            session.time = data['dateTime'].time()
        if data['highlights']:
            session.highlights = data['highlights']
        if data['typeOfSession']:
            session.typeOfSession = data['typeOfSession']
        if data['duration']:
            session.duration = data['duration']
        if data['speakers']:
            session.speakers = data['speakers']

        session.put()
        
        if data['speakers']:
            session.speakers = data['speakers']
            logging.debug("Creating session with speakers, adding task to taskqueue.", str(session))
            taskqueue.add(url='/tasks/add_featured_speaker', params={'sessionKeyUrlSafe': session.key.urlsafe()})
        return self._copySessionToForm(session)
开发者ID:harymitchell,项目名称:udacityConferenceApp,代码行数:37,代码来源:conference.py

示例2: _createSessionObject

# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import typeOfSession [as 别名]
 def _createSessionObject(self, request):
     """
     :param request: the endpoint request
     :return: session_form, message of the newly created session
     """
     user = endpoints.get_current_user()
     if not user:
         raise endpoints.UnauthorizedException('Authorization required.')
     user_id = getUserId(user)
     # make sure we're given a websafe conference key
     conference_key = validate_websafe_key(request.websafeConferenceKey,
                                           'Conference')
     # if we're given a websafe speaker key, make sure it's valid
     if request.speaker:
         validate_websafe_key(request.speaker, 'Speaker')
     # get the conference
     conference = conference_key.get()
     # make sure the user can edit this conference
     if conference.organizerUserId != user_id:
         raise endpoints.BadRequestException(
             'You cannot edit this conference.')
     # create a session object
     session = Session()
     # list the fields we want to exclude
     exclusions = ['websafeConferenceKey', 'typeOfSession']
     # use our handy copy function to copy the other fields
     session = message_to_ndb(request, session, exclusions)
     # deal with typeOfSession and get the enum value
     if request.typeOfSession:
         session.typeOfSession = str(SessionType(request.typeOfSession))
     else:
         session.typeOfSession = str(SessionType.NOT_SPECIFIED)
     # allocate an id and create the key
     session_id = Session.allocate_ids(size=1, parent=conference_key)[0]
     session.key = ndb.Key(Session, session_id, parent=conference_key)
     # save the session to ndb
     session.put()
     # kick off the featured speaker task
     taskqueue.add(url='/tasks/set_featured_speaker',
                   params={'conference_key': conference_key.urlsafe()})
     # return the newly created session
     return self._copySessionToForm(session)
开发者ID:kirklink,项目名称:udacity-fullstack-p4,代码行数:44,代码来源:conference.py

示例3: createSessionObject

# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import typeOfSession [as 别名]
    def createSessionObject(self, request):
        """Create or update Session object, returning SessionForm/request."""
        # check if user is logged in
        user = endpoints.get_current_user()
        if not user:
            raise endpoints.UnauthorizedException('Authorization required')
        user_id = getUserId(user)

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

        # check that user is owner of conference
        if user_id != conf.organizerUserId:
            raise endpoints.ForbiddenException(
                'Only the owner can update the conference.')

        # convert date string to date object
        date_convert = request.date
        if date_convert:
            date_convert = datetime.strptime(date_convert[:10], "%Y-%m-%d").date()
        # saving variables in the request to Session()
        sess = Session()
        sess.name = request.name
        sess.highlights = request.highlights
        sess.speaker = request.speaker
        sess.duration = request.duration
        sess.typeOfSession = request.typeOfSession
        sess.date = date_convert
        #sess.websafeConferenceKey = request.websafeConferenceKey
        #sess.conferenceName = conf.name
        sess.startTime = request.startTime
        sess.endTime = request.endTime

        # getting sessionkey with conference as parent
        c_key = ndb.Key(urlsafe=request.websafeConferenceKey)
        s_id = Session.allocate_ids(size=1, parent=c_key)[0]
        s_key = ndb.Key(Session, s_id, parent=c_key)
        sess.key = s_key
        sess.websafeKey = s_key.urlsafe()
        sess.put()

        # calling cacheFeaturedSpeaker using taskqueue
        taskqueue.add(
            params={
                'speaker': request.speaker,
                'websafeConferenceKey': request.websafeConferenceKey
                },
            url='/tasks/set_featured_speaker'
            )
        return self._copySessionToForm(sess)
开发者ID:angelovila,项目名称:Conference-Central,代码行数:56,代码来源:conference.py

示例4: createSession

# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import typeOfSession [as 别名]
    def createSession(self, request):
        """Create Session object, returning SessionForm/request."""

        # preload necessary data items
        user = endpoints.get_current_user()
        if not user:
            raise endpoints.UnauthorizedException('Authorization required')

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

        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)

        session = s_key.get()
        if not session:
            session = Session(
                key = s_key,
                name = request.name,
                speakerId = request.speakerId,
            )
            if request.highlights:
                session.highlights = request.highlights
            if request.duration:
                session.duration = request.duration
            if request.typeOfSession:
                session.typeOfSession = request.typeOfSession
            if request.date:
                session.date = datetime.strptime(request.date, "%Y-%m-%d").date()
            if request.startTime:
                session.startTime = datetime.strptime(request.startTime, "%H:%M:%S").time()
            session.put()

        taskqueue.add(params={'confKey': request.websafeConferenceKey, 'sessionKey': session.key.urlsafe(), 'speakerId': request.speakerId},
            url='/tasks/set_feature_speaker'
        )

        return self._copySessionToForm(session)
开发者ID:TimHack,项目名称:P4-ConferenceCentral,代码行数:43,代码来源:conference.py

示例5: _createSessionObject

# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import typeOfSession [as 别名]
    def _createSessionObject(self, request):
        """Creates a new Session object from the request."""

        # fetch the user
        user = endpoints.get_current_user()
        if not user:
            raise endpoints.UnauthorizedException('Authorization required.')

        user_id = getUserId(user)

         # build the conference key
        wsck = request.websafeConferenceKey
        conference = ndb.Key(urlsafe=wsck).get()

        if not conference:
            raise endpoints.BadRequestException('The conference does not exist.')

        p_key = ndb.Key(Profile, user_id)

        # make sure the conference was created by the current user
        if p_key != conference.key.parent():
            raise endpoints.ForbiddenException('You may only create sessions for your own conferences.')

        # create the session and add the required and optional fields
        session = Session()

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

        session.name = request.name

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

        session.speaker = request.speaker

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

        session.date = datetime.strptime(request.date, '%Y-%m-%d').date()

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

        session.startTime = datetime.strptime(request.startTime, '%H:%M').time()

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

        session.duration = int(request.duration)

        if request.typeOfSession:
            session.typeOfSession = request.typeOfSession

        if request.highlights:
            session.highlights = request.highlights

        # generate a key based on the parent conference
        s_id = Session.allocate_ids(size=1, parent=conference.key)[0]
        s_key = ndb.Key(Session, s_id, parent=conference.key)

        session.key = s_key

        # store the new session
        session.put()

        # add a new task to update the featured speaker
        taskqueue.add(params={'speaker': session.speaker,
            'websafeConferenceKey': wsck},
            url='/tasks/update_featured_speaker'
        )

        return self._copySessionToForm(session)
开发者ID:fknx,项目名称:udacity-conference,代码行数:75,代码来源:conference.py


注:本文中的models.Session.typeOfSession方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。