<div dir="ltr"><div><div><div><div>Hi Vadim!<br><br></div>Thanks for the suggestion!<br><br></div>Unfortunately I don't think that the `to_dict` and `to_json` methods of the `pony.orm.serialization` module could be extended to allow specifying tuples and other structures besides full ORM objects. The format of the result of these methods just doesn't have place to store such a data. I'd say that these module with its functions was just an initial experiment of bringing Pony ORM data to the frontend side.<br><br></div>But now we have something better! We're almost finished development of new serialization module which allows using not just JSON data, but full-blown ORM objects on the frontend side!<br><br></div>With this new library you can do the following:<br>1) Construct arbitrary JSON-like data on the backend side, including not just primitive JSON data types, but also full-blown ORM objects with fields and relations.<br><div><div>2) Serialize this data to normal JSON format and pass it to the frontend<br></div><div>3) Get the same structures and ORM objects on the JavaScript side (with related ORM objects if necessary)<br></div><div>4) Perform two-way binding of ORM objects with the HTML UI interface, so you can change object attribute and have corresponding HTML element changed automatically.<br></div><div>5) Modify any object attributes or create new ORM objects on the JavaScript side locally. The only restriction is that you cannot make direct queries to the database (which is obvious, because this is frontend, not backend).<br></div><div>6) Load additional objects if necessary by performing additional AJAX calls to the backend.<br></div><div>7) Automatically construct a JSON data packet with all modifications and send it back to the server.<br></div><div>8) Apply changes on the server side and complete transaction.<br></div><div><br></div><div>I think that this new library is much more usable then the previous pony.orm.serialization module. This library will be part of the next Pony ORM release. Currently we can show you a preview with some demo example which demonstrated all the steps I just described above.<br><br></div><div>I think that these library can be a very useful in your case. Currently it doesn't allow sending of partial objects from the server, but I think that we can add this feature relatively easily. Please see the demo which we a going to send in the following message.<br></div><div><br></div><div>I need to warn that this is an early preview and not all may works as expected. The main functionality that is omitted is access right control, so this is not safe to use this library at the public frontend site. But it is already very useful for the internnal admin interfaces. We plan to add access right control in the nearest time so this library can be used at the public frontend as well.<br><br></div><div>I'm very interested to see your comments.<br><br></div><div>Regards,<br></div><div>Alexander Kozlovsky<br></div><div><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jan 5, 2015 at 6:23 PM, Вадим Бажов <span dir="ltr"><<a href="mailto:vadim@ideco.ru" target="_blank">vadim@ideco.ru</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I've got a clue, I suppose.<br>
<br>
When we select or get a whole entity(ies), pony outputs a collection or structure, or something similar (arrays ?) representing the entity(ies) in DB. It holds the structure of entities and is easily convertable to json. So to_json converts this to json string.<br>
<br>
When we make a partial selection of fields - tuple is being returned, but to_json is waiting for a db model representation. It's easy to convert to json too, but that's another story )).<br>
<br>
So, this thread is kinda a feature request: please make to_json and to_dict are able to work with tuples for partial selections too.<br>
Built-in json answers from DB backend is very useful feature to let Pony talk directly in RESTfull API with web-frontend.<div class="HOEnZb"><div class="h5"><br>
<br>
On 02.01.2015 14:51, Вадим Бажов wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Suppose we have a table of Codes and Customers. Each code can belong to exactly one customer.<br>
For example, this works fine, giving me a json representation of a whole object with all relation onjects if any:<br>
<br>
    rcodeid = '3'<br>
<br>
    rcode = to_json(select(r for r in Rcodes if <a href="http://r.id" target="_blank">r.id</a> == rcodeid))<br>
<br>
<br>
But if i try to select particular fields from table, like this:<br>
<br>
    rcode = to_json(select((<a href="http://r.id" target="_blank">r.id</a>,r.code) for r in Rcodes if <a href="http://r.id" target="_blank">r.id</a> == rcodeid))<br>
<br>
<br>
i get an exception:<br>
<br>
(<type 'exceptions.TypeError'>, TypeError('not all arguments converted during string formatting',), <traceback object at 0x8ff648c>)<br>
<br>
The situation with to_dict is exactly the same. Works fine with full entities, throws an exception with partial selections.<br>
<br>
Didn't find any notice in docs and blog that to_dict and to_json works only with complete entities. So enlighten me please if it's me doing something wrong or Pony ))<br>
<br>
<br>
<br>
Thank you for the to_json method - it's very usefull.<br>
</blockquote>
<br>
______________________________<u></u>_________________<br>
ponyorm-list mailing list<br>
<a href="mailto:ponyorm-list@ponyorm.org" target="_blank">ponyorm-list@ponyorm.org</a><br>
<a href="/ponyorm-list" target="_blank">https://mailman-mail5.<u></u>webfaction.com/listinfo/<u></u>ponyorm-list</a><br>
</div></div></blockquote></div><br></div>