python - GAE: Can't use imported class with Endpoints API method -


i have class containing method writes datastore. able use write datastore web, can't figure out how use api post well.

datastorewrite.py:

from endpoints_proto_datastore.ndb import endpointsmodel google.appengine.ext import ndb  def person_timestamp_key(person_timestamp): return ndb.key('person timestamp', person_timestamp)  class person(endpointsmodel):     name = ndb.stringproperty(indexed=false)     timestamp = ndb.datetimeproperty(auto_now_add=true)  def do_insert(self, name):     person_timestamp = 'person_timestamp'     # sets entity     person = person(parent=person_timestamp_key(person_timestamp))      person.name = name      person.put() 

webapp.py - adds entry datastore when submitted webapp:

def post(self):      name = self.request.get('name')      person = datastorewrite.person()      if name , not name.isspace():         person.do_insert(name)          self.redirect('/') 

api.py - i've tried hundred different things here. have currently. results in "badvalueerror: expected string, got person()":

class api(remote.service):    @person.method(path='api', http_method='post', name='person.insert')   def personinsert(self, person):        person = datastorewrite.person()        person.do_insert(person)        return person 

update: attempt - fails error "badvalueerror: expected string, got person(name=u'atlas')":

@datastorewrite.person.method(path='healthsecure', http_method='post', name='person.insert')   def personinsert(self, name):        person = datastorewrite.person()        person.do_insert(name)        return person 

do_insert function has signature def do_insert(self, name) requires name parameter string , sending person parameter person.do_insert(person).

solution :

@datastorewrite.person.method(path='healthsecure', http_method='post', name='person.insert') def personinsert(self, person):    person.do_insert(person.name)    return person 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -