I advanced another step on my Flex and Python Test project. Now it is able to insert new objects in the data store and to retrieve them.
The Python client has some new abilities:
client.py test
Runs an Echo test against the server. This is the result:
test TEST 1
client.py insert code name
This command inserts new objects on the data store. For instance:
client.py insert 10 "Project Ten" client.py insert 12 "Project Twelve"
client.py get code
This command gets an object by one of its fields (code). For instance:
client.py get 10
Results in:
Project code = 10, name = Project Ten, created at 2008-07-17 00:20:32
The data is returned as an object.
client.py all
Retrieves all objects as a list:
Project code = 10, name = Project Ten, created at 2008-07-17 00:20:32 Project code = 12, name = Project Twelve, created at 2008-07-17 00:20:55
Some code highlights:
in server/services/ProjectService.py:
class ProjectService:
def get(self, code):
project = Project.gql("WHERE code = :1", code).get()
return project
def insert(self, code, name):
project = Project()
project.code = code
project.name = name
project.put()
def get_all(self):
return Project.all().fetch(1000)
in python-client/client.py:
def insert(code, name):
gw = RemotingService('http://localhost:8080/')
service = gw.getService('ProjectService')
service.insert(int(code), name)
def get(code):
gw = RemotingService('http://localhost:8080/')
service = gw.getService('ProjectService')
project = service.get(int(code))
if project == None:
print "Project %s not found." % (code)
else:
print_project(project)
def all():
gw = RemotingService('http://localhost:8080/')
service = gw.getService('ProjectService')
projects = service.get_all()
for project in projects:
print_project(project)
My next step will be to add these abilities to the Flex client as well.
The project is hosted in github. Comments are most welcome.
[...] Inserting and retrieving objects using PyAMF with GAE [...]
Pingback by Example of RIA in the cloud « Fernando Correia’s Weblog — October 4, 2008 @ 9:47 am