Added svg graphviz rendering

This commit is contained in:
Robbe Van Herck 2018-11-28 15:34:45 +01:00
parent bafda3862d
commit 4ad2b75835
No known key found for this signature in database
GPG key ID: 4D1C8E8FBD1C7188
2 changed files with 13 additions and 3 deletions

12
api.py
View file

@ -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")

View file

@ -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