Issue 1423:smartgrid multiple links to related table - how to suppress all but one, thanks cjkske
This commit is contained in:
@@ -1 +1 @@
|
|||||||
Version 2.4.5-stable+timestamp.2013.04.01.12.44.20
|
Version 2.4.5-stable+timestamp.2013.04.01.14.13.58
|
||||||
|
|||||||
+38
-12
@@ -2524,8 +2524,9 @@ class SQLFORM(FORM):
|
|||||||
break
|
break
|
||||||
if nargs > len(args) + 1:
|
if nargs > len(args) + 1:
|
||||||
query = (field == id)
|
query = (field == id)
|
||||||
if isinstance(linked_tables, dict):
|
# cjk
|
||||||
linked_tables = linked_tables.get(table._tablename, [])
|
# if isinstance(linked_tables, dict):
|
||||||
|
# linked_tables = linked_tables.get(table._tablename, [])
|
||||||
if linked_tables is None or referee in linked_tables:
|
if linked_tables is None or referee in linked_tables:
|
||||||
field.represent = lambda id, r=None, referee=referee, rep=field.represent: A(callable(rep) and rep(id) or id, _class=trap_class(), _href=url(args=['view', referee, id]))
|
field.represent = lambda id, r=None, referee=referee, rep=field.represent: A(callable(rep) and rep(id) or id, _class=trap_class(), _href=url(args=['view', referee, id]))
|
||||||
except (KeyError, ValueError, TypeError):
|
except (KeyError, ValueError, TypeError):
|
||||||
@@ -2550,20 +2551,45 @@ class SQLFORM(FORM):
|
|||||||
check[rfield.tablename] = \
|
check[rfield.tablename] = \
|
||||||
check.get(rfield.tablename, []) + [rfield.name]
|
check.get(rfield.tablename, []) + [rfield.name]
|
||||||
if isinstance(linked_tables, dict):
|
if isinstance(linked_tables, dict):
|
||||||
linked_tables = linked_tables.get(table._tablename, [])
|
for tbl in linked_tables.keys():
|
||||||
for tablename in sorted(check):
|
tb = db[tbl]
|
||||||
linked_fieldnames = check[tablename]
|
if isinstance(linked_tables[tbl], list):
|
||||||
tb = db[tablename]
|
if len(linked_tables[tbl]) > 1:
|
||||||
multiple_links = len(linked_fieldnames) > 1
|
t = T('%s(%s)' %(tbl, fld))
|
||||||
for fieldname in linked_fieldnames:
|
else:
|
||||||
if linked_tables is None or tablename in linked_tables:
|
t = T(tb._plural)
|
||||||
t = T(tb._plural) if not multiple_links else \
|
for fld in linked_tables[tbl]:
|
||||||
T(tb._plural + '(' + fieldname + ')')
|
if fld not in db[tbl].fields:
|
||||||
args0 = tablename + '.' + fieldname
|
raise ValueError('Field %s not in table' %fld)
|
||||||
|
args0 = tbl + '.' + fld
|
||||||
|
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:
|
||||||
|
t = T(tb._plural)
|
||||||
|
fld = linked_tables[tbl]
|
||||||
|
if fld not in db[tbl].fields:
|
||||||
|
raise ValueError('Field %s not in table' %fld)
|
||||||
|
args0 = tbl + '.' + fld
|
||||||
links.append(
|
links.append(
|
||||||
lambda row, t=t, nargs=nargs, args0=args0:
|
lambda row, t=t, nargs=nargs, args0=args0:
|
||||||
A(SPAN(t), _class=trap_class(), _href=url(
|
A(SPAN(t), _class=trap_class(), _href=url(
|
||||||
args=[args0, row[id_field_name]])))
|
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(tb._plural + '(' + fieldname + ')')
|
||||||
|
args0 = tablename + '.' + fieldname
|
||||||
|
links.append(
|
||||||
|
lambda row, t=t, nargs=nargs, args0=args0:
|
||||||
|
A(SPAN(t), _class=trap_class(), _href=url(
|
||||||
|
args=[args0, row[id_field_name]])))
|
||||||
|
|
||||||
grid = SQLFORM.grid(query, args=request.args[:nargs], links=links,
|
grid = SQLFORM.grid(query, args=request.args[:nargs], links=links,
|
||||||
links_in_grid=links_in_grid,
|
links_in_grid=links_in_grid,
|
||||||
|
|||||||
Reference in New Issue
Block a user