Пример #1
0
    def createSpeaker(self, request):
        """Create Speaker object, returning SpeakerForm/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("Speaker 'name' field required")
        if not request.mainEmail:
            raise endpoints.BadRequestException("Speaker 'mainEmail' field required")

        sp_key = ndb.Key(Speaker, request.mainEmail)
        speaker = sp_key.get()
        if not speaker:
            speaker = Speaker(
                key = sp_key,
                name = request.name,
                mainEmail = request.mainEmail,
            )
            if request.title:
                speaker.title = request.title
            if request.bio:
                speaker.bio = request.bio
            speaker.put()

        return request