currently when having
{{=records}}
in your view, it prints out a table with the records, the table
headers being the 'ugly' field names (prefixed with the table).

The following patch will make use of the labels supplied on the
db.define(...)

I've not yet tested this for GAE.

=== modified file 'web2py/gluon/sql.py'
--- web2py/gluon/sql.py 2009-05-29 15:28:54 +0000
+++ web2py/gluon/sql.py 2009-05-31 07:31:05 +0000
@@ -1036,6 +1036,11 @@
              self.table.fields]
         return ', '.join(s)

+    def labels(self):
+        l = {}
+        for field in self.table.fields:
+            l.update({'%s.%s' % (self.table._tablename, field):
self.table[field].label})
+        return l

 class SQLJoin(object):

@@ -1191,7 +1196,8 @@
                 ftype = field.type.native or field.type.type
             elif not field.type in self._db._translator:
                 raise SyntaxError, \
-                    'SQLField: unkown field type: %s' % field.type
+                    "SQLField: unkown field type: '%s' for '%s'" \
+                    % (field.type, field)
             else:
                 ftype = self._db._translator[field.type]\
                      % dict(length=field.length)
@@ -1921,6 +1927,13 @@
         if len(tablenames) < 1:
             raise SyntaxError, 'SQLSet: no tables selected'
         self.colnames = [c.strip() for c in sql_f.split(', ')]
+
+        if len(tablenames) > 1:
+            self.labels = \
+                ['%s [%s]' % (self._db[table].ALL.labels(), table)
for table in tablenames]
+        else:
+            self.labels = [self._db[table].ALL.labels() for table in
tablenames]
+
         if self.sql_w:
             sql_w = ' WHERE ' + self.sql_w
         else:
@@ -2015,7 +2028,10 @@
             r = cache_model(key, lambda : response(query),
time_expire)
         if self._db._dbname in ['mssql', 'mssql2', 'db2']:
             r = r[(attributes.get('limitby', None) or (0,))[0]:]
-        return SQLRows(self._db, r, *self.colnames)
+
+        labels = {'labels': self.labels}
+
+        return SQLRows(self._db, r, *self.colnames, **labels )

     def _count(self):
         return self._select('count(*)')
@@ -2120,13 +2136,21 @@
         self,
         db,
         response,
-        *colnames
+        *colnames,
+        **args
         ):
         self._db = db
         self.colnames = colnames
         self.response = response
         self.hooks = True
         self.compact = True
+
+        if 'labels' in args.keys():
+            self.labels = args['labels'][0]
+        else:
+            self.labels = {}
+            for col in colnames:
+                self.labels.append({col: col})

     def __nonzero__(self):
         if len(self.response):

=== modified file 'web2py/gluon/sqlhtml.py'
--- web2py/gluon/sqlhtml.py     2009-05-23 13:22:56 +0000
+++ web2py/gluon/sqlhtml.py     2009-05-31 07:36:56 +0000
@@ -611,12 +611,13 @@
         self.attributes = attributes
         self.sqlrows = sqlrows
         (components, row) = (self.components, [])
+
         if not orderby:
             for c in sqlrows.colnames:
-                row.append(TH(headers.get(c, c)))
+                row.append(TH(headers.get(c, sqlrows.labels[c])))
         else:
             for c in sqlrows.colnames:
-                row.append(TH(A(headers.get(c, c), _href='?orderby='
+                row.append(TH(A(headers.get(c, sqlrows.labels[c]),
_href='?orderby='
                             + c)))
         components.append(THEAD(TR(*row)))
         tbody = []


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to