I note you changed this a little, my question: if field has no label
defined? this field.label will be filled up with fieldname?
<yourcode>
headers = {}
for c in columns:
(t,f) = c.split('.')
field = sqlrows.db[t][f]
headers[c] = field.label
</yourcode>
<mycode>
headers = {}
for c in columns:
(t,f) = c.split('.')
field = sqlrows.db[t][f]
# IF FIELD HAS A LABEL
if hasattr(field,'label'):
headers[c] = field.label
# IF FIELD HAS NO LABEL
else:
lbl = c.split('.')[1].replace("_", " ").capitalize()
headers[c] = lbl
</mycode>
I am thinking about the case of Joins,
can detect a Join with:
<code>
sqlrows_tables = set(map(lambda c: c.split('.')[0], sqlrows.colnames))
is_joined = len(sqlrows_tables) > 1
</code>
So no problem when having a join because:
for c in columns: (t,f) = c.split('.') # this will fetch tablename and
fieldname
and this:
field = sqlrows.db[t][f] # will take the correct label from db
Right?
2010/12/9 mdipierro <[email protected]>
> This is now partially in trunk but default has not changed. What if
> you are printing the result of a join?
>
> On Dec 8, 7:40 pm, Bruno Rocha <[email protected]> wrote:
> > Now this is better and I can make a patch,
> >
> > Do you think SQLTABLE should use the defined field labels by default if
> > headers param is empty?
> >
> > <code>
> > if not columns:
> > columns = sqlrows.colnames
> >
> > if headers=='fieldname:capitalize':
> > headers = {}
> > for c in columns:
> > headers[c] = ' '.join([w.capitalize() for w in
> > c.split('.')[-1].split('_')])
> >
> > if not headers or headers=='labels':
> > headers = {}
> > for c in columns:
> > (t,f) = c.split('.')
> > field = sqlrows.db[t][f]
> > if hasattr(field,'label'):
> > headers[c] = field.label
> > else:
> > lbl = c.split('.')[1].replace("_", " ").capitalize()
> > headers[c] = lbl
> >
> > </code>
> > --
> >
> > Bruno Rochahttp://about.me/rochacbruno/bio
>
--
Bruno Rocha
http://about.me/rochacbruno/bio