def _createSpeakerObject(self, request):
     """Create Speaker Object, returning SessionForm/request."""
     data = {field.name: getattr(request, field.name)
             for field in request.all_fields()}
     del data['speakerId']
     key = Speaker(**data).put()
     return self._copySpeakerToForm(key.get())
Beispiel #2
0
    def delete(self, id = None):
	request = self.wsgi_request
	response = self.wsgi_response
	c = self.context
	if id is None:
	    self.set_body('speaker id is a Must')
	else:
	    speaker = Speaker.get(id)
	    if speaker is None:
		self.set_body('No speakererence with %d exist' % (id))
	    else:
		speaker.delete()
		self.set_body("Deleted Successfully...")
	return self.render()
Beispiel #3
0
    def get(self, id = None):
	request = self.wsgi_request
	response = self.wsgi_response
	c = self.context
	response.headers['content-type'] = 'application/json'

	if id is None:
	    #get all the speakers
	    speakers = [x.to_json(encode = False) for x in Speaker.get_all()]
	    self.set_body(json.dumps(speakers))
	else:
	    speaker = Speaker.get(id)
	    self.set_body(speaker.to_json())
	return self.render()
Beispiel #4
0
    def _createSpeakerObject(self, request):
        user = endpoints.get_current_user()
        if not user:
            raise endpoints.UnauthorizedException('Authorization required')

        # copy SpeakerForm/ProtoRPC Message into dict
        data = {field.name: getattr(request, field.name) for field in request.all_fields()}
        del data["sessionKeysToAttend"]
        data["key"] = ndb.Key(Speaker, data["email"])

        # create Speaker entity
        # creation of Speaker & return new Speaker form
        speaker = Speaker(**data).put()

        return self._copySpeakerToForm(speaker.get())
Beispiel #5
0
    def put(self, id = None):
	request = self.wsgi_request
	response = self.wsgi_response
	c = self.context

	if id is None:
	    self.set_body('speaker id is a Must')
	else:
	    speaker = Speaker.get(id)
	    if request.params.first_name: speaker.first_name = request.params.first_name
	    if request.params.last_name: speaker.last_name = request.params.last_name
	    if request.params.desc: speaker.desc = request.params.desc
	    if request.params.twitter_handle: speaker.twitter_handle = request.params.twitter_handle
	    speaker = speaker.save()
	    self.set_body(speaker.to_json())
	return self.render()
    def _create_speaker_object(self, request):
        """ Creates a Speaker object """

        # Make sure that the user is authenticated
        user = endpoints.get_current_user()
        if not user:
            raise endpoints.UnauthorizedException("Authorization required.")

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

        # Copy SpeakerForm/ProtoRPC Message into dict
        data = {field.name: getattr(request, field.name)
                for field in request.all_fields()}

        speaker_key = Speaker(**data).put()
        return self._copy_speaker_to_form(speaker_key.get())
    def _createSpeakerObject(self, request):
        """ Create or update Speaker object, returning SpeakerForm
        """

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

        # copy SpeakerForm/ProtoRPC Message into dict
        data = {field.name: getattr(request, field.name)
                for field in request.all_fields()}
        del data['websafeKey']

        s_id = Speaker.allocate_ids(size=1)[0]
        s_key = ndb.Key(Speaker, s_id)
        data['key'] = s_key

        spkr_key = Speaker(**data).put()
        return self._copySpeakerToForm(spkr_key.get())
    def _createSpeakerObject(self, request):
        """Create Speaker object, returning SpeakerFormOut."""
        # preload necessary data items
        user_id = get_current_user_id()

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

        # copy SpeakerFormIn/ProtoRPC Message into dict
        data = {field.name: getattr(request, field.name)
                for field in request.all_fields()}

        # generate Profile Key based on user ID, used as parent
        p_key = ndb.Key(Profile, user_id)
        data['parent'] = p_key

        # create Speaker & return (new) SpeakerFormOut
        speaker = Speaker(**data).put()
        return self._copySpeakerToForm(speaker.get())
    def _createSpeakerObject(self, request):
        """ Create or update Speaker object, returning SpeakerForm
        """

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

        # copy SpeakerForm/ProtoRPC Message into dict
        data = {
            field.name: getattr(request, field.name)
            for field in request.all_fields()
        }
        del data['websafeKey']

        s_id = Speaker.allocate_ids(size=1)[0]
        s_key = ndb.Key(Speaker, s_id)
        data['key'] = s_key

        spkr_key = Speaker(**data).put()
        return self._copySpeakerToForm(spkr_key.get())
Beispiel #10
0
    def _createSpeakerObject(self, request):
        """Create or update Speaker object, returning SpeakerForm/request."""
        # ensure user auth
        user, u_id = self._validateUser()

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

        if request.email:
            q = Speaker.query(Speaker.email == request.email)
            entity = q.get()
            if entity:
                raise endpoints.ForbiddenException('Email is already registered with a speaker.')

        # copy SpeakerForm/ProtoRPC Message into dict
        data = {field.name: getattr(request, field.name) for field in request.all_fields()}
        del data['websafeKey']
        s_key = Speaker(**data).put()
        speaker = s_key.get()

        return self._copySpeakerToForm(speaker)
Beispiel #11
0
    def createspeaker(self, request):
        """Create a Speaker object"""
        if not request.name:
            raise endpoints.BadRequestException("Speaker must have a name")

        # check for authorization, valid conference key, and that the current user is the conference orgainizer   # noqa
        user = endpoints.get_current_user()
        if not user:
            raise endpoints.UnauthorizedException("Authorization required")
        # copy SpeakerForm/ProtoRPC Message into dict
        data = {field.name: getattr(request, field.name) for field in request.all_fields()}   # noqa
        del data['websafeSpeakerKey']
     
        # add default values for those missing (both data model & outbound Message)   # noqa
        for df in DEFAULTSPEAKER:
            if data[df] in (None, []):
                data[df] = DEFAULTSPEAKER[df]
                setattr(request, df, DEFAULTSPEAKER[df])

        # creation of Session, record the key to get the item & return (modified) SessionForm   # noqa
        speakerKey = Speaker(**data).put()
        return self._copySpeakerToForm(speakerKey.get())
    def _addSpeakerObject(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.speakerFirst or not request.speakerLast:
            raise endpoints.BadRequestException("Speaker 'name' fields are required")

        # copy SpeakerForm/ProtoRPC Message into dict
        data = {field.name: getattr(request, field.name)\
         for field in request.all_fields()}

        # creation of Speaker with key & return (modified) SpeakerForm
        speaker_key = Speaker(**data).put()
        wsk = speaker_key.urlsafe()

        speaker = speaker_key.get()
        speaker.speakerWSK = wsk
        speaker.put()
        
        return request