Skip to content

Instantly share code, notes, and snippets.

@zindel
Last active May 30, 2016 14:04
Show Gist options
  • Save zindel/75475cc1beeca40c7fa851a7565366f1 to your computer and use it in GitHub Desktop.
Save zindel/75475cc1beeca40c7fa851a7565366f1 to your computer and use it in GitHub Desktop.
def fields(table_name, prefix, skip=[]):
skip_dict = dict([(f.label, True) for f in skip])
table = model().table(table_name)
ret = []
print table
print table.schema
for f in table.fields():
if f.label in skip_dict:
continue
ret.append(f.label)
return ret
def facets(table_name, skip_links_to=[]):
schema = model()
tables = []
for table in schema.tables():
identity = table.identity().fields
if len(identity) == 1 \
and identity[0].is_link \
and identity[0].target_table.label == table_name:
tables.append((table, identity[0]))
view_facet = lambda table, skip: action(table_name,
title='View %s' % table.title,
fields=fields(table_name, prefix=table_name, skip=[skip])
)
return [view_facet(t, s)
for t, s in sorted(tables, key=lambda x: x[0].title)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment