def get_cluster(cluster_id=None): """Renders a single cluster as json. If the cluster id is not provided, picks a random one. """ batch = request.args.get("batch") if cluster_id is None: cluster = Cluster.get_some(batch=batch) else: cluster = Cluster.objects.get_or_404(pk=cluster_id) return jsonify({ "success": True, "data": { "cluster": json.loads(cluster.to_json()), }, })