def test_table_data(self, a, db_session): from dallinger.experiment_server.experiment_server import Experiment from dallinger.models import Network exp = Experiment(db_session) network = Network.query.all()[0] table = exp.table_data(model_type=["Network"]) assert len(table["data"]) == 1 assert table["data"][0]["id"] == network.id assert table["data"][0]["role"] == network.role assert len(table["columns"]) > 2 for col in table["columns"]: if col["data"] == "role": assert col == {"data": "role", "name": "role"} break else: raise KeyError("'role' not in Network columns") source = a.source(network=network) table = exp.table_data(model_type="Node") assert len(table["data"]) == 1 assert table["data"][0]["id"] == source.id assert table["data"][0]["type"] == source.type assert len(table["columns"]) > 2 for col in table["columns"]: if col["data"] == "id": assert col == {"data": "id", "name": "id"} break else: raise KeyError("'id' not in Node columns")
def database(): from dallinger.experiment_server.experiment_server import Experiment, session title = "Database View" exp = Experiment(session) model_type = request.args.get("model_type") if model_type: title = "Database View: {}s".format(model_type) datatables_options = prep_datatables_options( exp.table_data(**request.args.to_dict(flat=False))) columns = [ c.get("name") or c["data"] for c in datatables_options.get("columns", []) if c.get("data") ] # Extend with custom actions actions = { "extend": "collection", "text": "Actions", "buttons": [], } buttons = actions["buttons"] exp_actions = exp.dashboard_database_actions() for action in exp_actions: buttons.append({ "extend": "route_action", "text": action["title"], "route_name": action["name"], }) is_sandbox = getattr(recruiters.from_config(get_config()), "is_sandbox", None) if is_sandbox is True or is_sandbox is False: buttons.append("compensate") else: is_sandbox = None if len(buttons): datatables_options["buttons"].append(actions) return render_template( "dashboard_database.html", title=title, columns=columns, is_sandbox=is_sandbox, datatables_options=json.dumps(datatables_options, default=date_handler, indent=True), )
def database(): from dallinger.experiment_server.experiment_server import Experiment, session title = "Database View" exp = Experiment(session) model_type = request.args.get("model_type") if model_type: title = "Database View: {}s".format(model_type) datatables_options = prep_datatables_options( exp.table_data(**request.args.to_dict(flat=False))) columns = [ c.get("name") or c["data"] for c in datatables_options.get("columns", []) if c.get("data") ] return render_template( "dashboard_database.html", title=title, columns=columns, datatables_options=json.dumps(datatables_options, default=date_handler, indent=True), )