Thanks Massimo.

This does it, but with another problem.

For some reason some of the fields get truncated with 3 dots at the
end. Like the email, and the datetime field.

Could it be that classes "odd" and "even" are limiting the size of
fields?


Here is the output, and it's the same with, and without the .xml:

<tr class="odd">
  <td>123</td>
  <td>Name 1</td>
  <td>Last Name 1</td>
  <td>email181@ro...</td>
  <td/>
  <td>2010-02-07 17...</td>
  <td>146.4</td>
  <td>9544671</td>
</tr>


On Mar 16, 6:43 pm, Massimo Di Pierro <massimo.dipie...@gmail.com>
wrote:
> if you use trunk and simply return orders and call the action
> with .xml it should do what you asked.
> You do not need a view
>
> On Mar 16, 2:33 pm, "Adnan S." <adnan.smajlo...@gmail.com> wrote:
>
> > 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