Server / Client-gtk app

5 views
Skip to first unread message

M3nt0r3

unread,
Nov 8, 2009, 5:06:34 PM11/8/09
to sqlalchemy
Hi , i am sorry for my english, i am trying ti make a Server/Client
app. Until now client-gtk mapped the db and spoked directly with the
db ( sqlite and postgresql atm) . I wrote a small wsgi server based
on werkzeug, and it basically make the same thing of the client-gtk
but in pure web style. If received a request it render html with
template engine and response the html-code.

Now with client-gtk i am trying to use something like:

def getRecord(self,id=None):
""" Restituisce un record ( necessita di un ID )"""
if id:
params = {}
params["dao_class"] = self.DaoModule.__module__
params["dao_name"] = self.DaoModule.__name__
params["filter"] = id
params["method"] = "getRecord"
paramss = urllib.urlencode(params)
f = urllib.urlopen("http://localhost:8080/gtk", paramss)
dati_uncompress = zlib.decompress(f.read())
dati= loads(dati_uncompress)
return dati

It is for get.

Server side this is the function to handler:

def gtk_(req, static=None, SUB=None, subdomain=None):
values = req.form.to_dict()
dao_name = values["dao_name"]
dao_class = values["dao_class"]
method = values["method"]
filtri = values["filter"]
exec "from %s import %s" %(dao_class.replace("promogest", "core"),
dao_name)
if method =="select" or method =="getRecord":
exec "d = %s().%s(filtri=%s)" %(dao_name,method, filtri)
dumped = dumps(d)
if method=="nuovo":
exec "d = %s" %(dao_name)
dumped = dumps(d)
compressed = zlib.compress(dumped)
return Response(compressed)

""" exec create something like: User().getRecord(filter=22) """

For example for user table:

class User(Dao):
""" User class provides to make a Users dao""
def __init__(self, req=None,arg=None):
Dao.__init__(self, entity=self)

std_mapper = mapper(User,user, properties={
"per_giu" :relation(PersonaGiuridica_, backref='cliente_'),
}, order_by=user.c.username)

It works until i need to work with a new istance:

i don't know how to have an istance in the client , to build there or
have it from a response from the server.

SA serializer loads need a metadata and a session ... but i don't
have a db in the client ...
I suppose to use merge() server side, when i have to return the object
with the value assigned for each column client side ...

I hope to explained the problem sufficiently with my poor english ...
i need to know if it is a possible way to do.

thanks
F.

Michael Bayer

unread,
Nov 9, 2009, 7:55:22 PM11/9/09
to sqlal...@googlegroups.com

if I understand correctly aren't you looking to pass over just the
components of the User as a string, and have the exec do a "User
(*args)" on the server side ? That would be consistent with your
approach of strings sent from the client being interpreted as model/
ORM code on the server.


Francesco Meloni

unread,
Nov 9, 2009, 8:42:18 PM11/9/09
to sqlal...@googlegroups.com


2009/11/10 Michael Bayer <mik...@zzzcomputing.com>

My problem is client side ATM because i receive an obj from the server not just a dict or string, this obj is made with a dump server side
and a load client side. 
Load need a session and a metadata to work but client side i dont have a db so no meta and no session and not mapper. I am starting to understand
that client side i can't manage "complete"   ORM Object but just a converted dict of that. It is correct?

Thanks
F.

Michael Bayer

unread,
Nov 10, 2009, 8:39:33 PM11/10/09
to sqlal...@googlegroups.com
you're basically building marshalling.  you can use ORM objects on the client side but they wouldn't be associated with any Session - all the data has to come from your server via loads().

Reply all
Reply to author
Forward
0 new messages