Maybe I should ask instead, can anyone please point me in the right
direction, to find out a proper way to export the xml file when
joining 2 tables, and want only several fields in the xml file?

Thanks.


On Mar 15, 10:25 pm, "Adnan S." <adnan.smajlo...@gmail.com> wrote:
> I used the code that Massimo posted for returning the xml, which works
> perfectly fine when exporting from a single table, but when selecting
> fields from two tables it gets stuck, due to table names propagated in
> the resultset. Being a newbie w web2py and python I'm not finding an
> elegant solution around it, but I know it must be there.
>
> Here is a code snippet:
>
> def export_orders_xml():
> ...
> orders = db(db.order_items.item_id==int(request.args(0)))\
>            (db.order_items.order_id==db.order1.id)\
>            .select(
>                    db.order_items.order_id, \
>                    db.order1.first_name, \
>                    db.order1.last_name, \
>                    )
>
> return xml_list(orders)
>
> #xml tags
> def export_xml(rows, fields):
>     users=[]
>     for row in rows: users.append(TAG.user(*[TAG[f](row[f]) for f in
> fields]))
>     return TAG.users(*users).xml()
>
> #xml view
> def xml_list(rows):
>     response.headers['Content-Type']='application/xml'
>     return export_xml(rows,['order_items','order1'])
>     # would prefer to use it this way: return export_xml(rows,
> ['first_name','last_name'])
>
> I think TAG should go around something like this:
> row['table_name'].field, but not sure how to get to it :)
>
> Rendered output:
> - <users>
>   - <user>
>          <order_items><Row {'order_id': 123}></order_items>
>         - <order1>
>         <Row {'first_name': 'John', 'order_items': <gluon.dal.Set object at
> 0x1176689d0>, 'last_name': 'Test', 'update_record': <function <lambda>
> at 0x117644050>, 'delete_record': <function <lambda> at 0x117644a28>}>
>       </order1>
>     </user>

Reply via email to