From 4ad2b75835745d3a91007abab4741f5956ba9cbd Mon Sep 17 00:00:00 2001 From: Robbe Van Herck Date: Wed, 28 Nov 2018 15:34:45 +0100 Subject: [PATCH] Added svg graphviz rendering --- api.py | 12 ++++++++++++ requirements.txt | 4 +--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/api.py b/api.py index 05119cf..119717f 100644 --- a/api.py +++ b/api.py @@ -2,6 +2,7 @@ from app import app, db from models import User, Achievement import json +from graphviz import Digraph @app.route("/api") @app.route("/api/all") @@ -15,3 +16,14 @@ def api_all_users(): @app.route("/api/achievements") def api_all_achievements(): return json.dumps([achievement.to_obj() for achievement in Achievement.query.all()]) + +@app.route("/api/svg") +def dot_graph(): + dot = Digraph(format="svg") + for user in User.query.all(): + dot.node(user.id, user.id) + for achievement in Achievement.query.all(): + for endorser in achievement.endorsed_by: + dot.edge(endorser.id, achievement.achieved_by, label=achievement.name) + return dot.pipe().decode("utf-8") + diff --git a/requirements.txt b/requirements.txt index 6d1bef4..fb10acc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,14 +5,12 @@ Flask==1.0.2 Flask-Login==0.4.1 Flask-OAuthlib==0.9.5 Flask-SQLAlchemy==2.3.2 +graphviz==0.10.1 idna==2.7 itsdangerous==0.24 Jinja2==2.10 MarkupSafe==1.0 -mysql==0.0.2 -mysqlclient==1.3.13 oauthlib==2.1.0 -pkg-resources==0.0.0 pytz==2018.5 requests==2.19.1 requests-oauthlib==1.0.0