fixed linked tables again

This commit is contained in:
mdipierro
2013-07-27 06:47:25 -05:00
parent 6faacfbf36
commit 30a570538b
2 changed files with 23 additions and 31 deletions
+1 -1
View File
@@ -1 +1 @@
Version 2.6.0-development+timestamp.2013.07.26.15.55.14 Version 2.6.0-development+timestamp.2013.07.27.06.46.34
+22 -30
View File
@@ -2618,38 +2618,30 @@ class SQLFORM(FORM):
for rfield in table._referenced_by: for rfield in table._referenced_by:
check[rfield.tablename] = \ check[rfield.tablename] = \
check.get(rfield.tablename, []) + [rfield.name] check.get(rfield.tablename, []) + [rfield.name]
if linked_tables is None:
linked_tables = db.tables()
if isinstance(linked_tables, dict): if isinstance(linked_tables, dict):
for tbl in linked_tables.keys(): linked_tables = linked_tables.get(table._tablename,[])
tb = db[tbl] if linked_tables:
if isinstance(linked_tables[tbl], list) and len(linked_tables[tbl])==1: for item in linked_tables:
linked_tables[tbl] = linked_tables[tbl][0] tb = None
if isinstance(linked_tables[tbl], list): if isinstance(item,Table) and item._tablename in check:
for fld in linked_tables[tbl]: tablename = item._tablename
if fld not in db[tbl].fields: linked_fieldnames = check[tablename]
raise ValueError('Field %s not in table' %fld) td = item
args0 = tbl + '.' + fld elif isinstance(item,str) and item in check:
t = T('%s(%s)' %(tbl, fld)) tablename = item
links.append( linked_fieldnames = check[item]
lambda row, t=t, nargs=nargs, args0=args0: tb = db[item]
A(SPAN(t), _class=trap_class(), _href=url( elif isinstance(item,Field) and item.name in check.get(item._tablename,[]):
args=[args0, row[id_field_name]]))) tablename = item._tablename
linked_fieldnames = [item.name]
tb = item.table
else: else:
fld = linked_tables[tbl] linked_fieldnames = []
if fld not in db[tbl].fields: if tb:
raise ValueError('Field %s not in table' %fld) multiple_links = len(linked_fieldnames) > 1
args0 = tbl + '.' + fld for fieldname in linked_fieldnames:
t = T(tb._plural)
links.append(
lambda row, t=t, nargs=nargs, args0=args0:
A(SPAN(t), _class=trap_class(), _href=url(
args=[args0, row[id_field_name]])))
else:
for tablename in sorted(check):
linked_fieldnames = check[tablename]
tb = db[tablename]
multiple_links = len(linked_fieldnames) > 1
for fieldname in linked_fieldnames:
if linked_tables is None or tablename in linked_tables:
t = T(tb._plural) if not multiple_links else \ t = T(tb._plural) if not multiple_links else \
T(tb._plural + '(' + fieldname + ')') T(tb._plural + '(' + fieldname + ')')
args0 = tablename + '.' + fieldname args0 = tablename + '.' + fieldname