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


Python Session.parent方法代码示例

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


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

示例1: _createSessionObject

# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import parent [as 别名]
    def _createSessionObject(self, request):
        """
        Create Session object, returning SessionFormOut.
        """
        # preload necessary data items
        user_id = get_current_user_id()

        # load conference
        conf = ndb.Key(urlsafe=request.websafeConferenceKey)
        if conf.kind() != "Conference":
            raise endpoints.BadRequestException(
                "Conference key expected")

        # check if the conference has the right owner
        if conf.get().organizerUserId != user_id:
            raise endpoints.BadRequestException(
                "Only the conference owner can add sessions")

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

        # copy SessionFormIn/ProtoRPC Message into dict
        data = {field.name: getattr(request, field.name)
                for field in request.all_fields()}
        # The speaker field will be dealt with specially
        del data['speaker_key']
        # delete websafeConferenceKey
        del data['websafeConferenceKey']
        # we have to adjust the typeOfSession
        if data['typeOfSession']:
            data['typeOfSession'] = (
                str(getattr(request, 'typeOfSession')))

        # add default values for those missing
        # (both data model & outbound Message)
        for df in DEFAULTS_SESS:
            if data[df] in (None, []):
                data[df] = DEFAULTS_SESS[df]
                setattr(request, df, DEFAULTS_SESS[df])

        # add speakers
        speaker_keys = []
        for speakerform in getattr(request, 'speaker_key'):
            speaker_key = ndb.Key(urlsafe=speakerform)
            if speaker_key.kind() != "Speaker":
                raise endpoints.BadRequestException(
                    "Speaker key expected")
                # we try to get the data - is the speaker existing?
            speaker = speaker_key.get()
            if speaker is None:
                raise endpoints.BadRequestException("Speaker not found")
            speaker_keys.append(speaker_key)
        data['speaker'] = speaker_keys

        # convert dates from strings to Date objects,
        # times from strings to Time objects
        if data['date']:
            data['date'] = datetime.strptime(data['date'][:10],
                                             "%Y-%m-%d").date()
        if data['startTime']:
            data['startTime'] = datetime.strptime(data['startTime'][:5],
                                                  "%H:%M").time()

        # set session parent to conference
        data['parent'] = conf

        # create Session, search for featured speaker in a task
        session = Session(**data).put()
        taskqueue.add(
            params=
                {
                    'sessionId': str(session.id()),
                    'websafeConferenceKey': session.parent().urlsafe()
                },
            url='/tasks/search_featured_speakers'
            )

        return self._copySessionToForm(session.get())
开发者ID:liuderchi,项目名称:fsnd_P4_Conference_Org,代码行数:81,代码来源:conference.py


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