def index(self): if request.args.get('privateOnly', 'false') == 'true': return _get_scenarios_private_only() else: public_scenarios = Scenario.fetchall(is_public=True) private_scenarios = Scenario.fetchall(is_public=False, owner_id=g.user['id']) ret = [] for s in public_scenarios + private_scenarios: r = { 'id': s.id, 'name': s.name, 'description': s.description, 'sgRules': s.sg_rules, 'topo': s.topo.value } ret.append(r) return jsonify(sorted(ret, key=lambda i: i['id'], reverse=True))
def _get_scenarios_private_only(): ret = [] for scenario in Scenario.fetchall(owner_id=g.user['id']): ret.append({ 'id': scenario.id, 'name': scenario.name, 'description': scenario.description, 'sgRules': scenario.sg_rules, 'topo': scenario.topo.value }) return jsonify(sorted(ret, key=lambda i: i['id'], reverse=True))