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


Python Conference.toForm方法代码示例

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


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

示例1: _createConferenceObject

# 需要导入模块: from models import Conference [as 别名]
# 或者: from models.Conference import toForm [as 别名]
    def _createConferenceObject(self, conferenceForm):
        """Create conference object, returns ConferenceForm."""

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

        data = formToDict(conferenceForm, exclude=('websafeKey', 'organizerDisplayName'))
        # add default values for those missing
        for df in DEFAULTS:
            if data[df] in (None, []):
                data[df] = DEFAULTS[df]

        # add organizerUserId before checking the required fields
        data['organizerUserId'] = user_id = getUserId(user)

        # check required fields
        for key in Conference.required_fields_schema:
            if not data[key]:
                raise endpoints.BadRequestException("Conference '%s' field required" % key)

        # convert dates from strings to Date objects; set month based on start_date
        try:
            data['startDate'] = datetime.strptime(data['startDate'][:10], "%Y-%m-%d").date()
            data['endDate'] = datetime.strptime(data['endDate'][:10], "%Y-%m-%d").date()
        except (TypeError, ValueError):
            raise endpoints.BadRequestException("Invalid date format. Please use 'YYYY-MM-DD'")

        if data['startDate'] > data['endDate']:
            raise endpoints.BadRequestException("start date must be before end date")
        data['month'] = data['startDate'].month

        # set seatsAvailable to be same as maxAttendees on creation
        if data["maxAttendees"] > 0:
            data["seatsAvailable"] = data["maxAttendees"]

        # generate Profile Key based on user ID and Conference
        # ID based on Profile key get Conference key from ID
        p_key = ndb.Key(Profile, user_id)
        c_id = Conference.allocate_ids(size=1, parent=p_key)[0]
        c_key = ndb.Key(Conference, c_id, parent=p_key)
        data['key'] = c_key

        # create Conference, send email to organizer confirming
        # creation of Conference & return (modified) ConferenceForm
        conf = Conference(**data)
        conf.put()
        taskqueue.add(
            params={'email': user.email(), 'conferenceInfo': repr(conferenceForm)},
            url='/tasks/send_confirmation_email'
        )
        return conf.toForm()
开发者ID:LuizGsa21,项目名称:p4-conference-central,代码行数:54,代码来源:conference.py


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