Added svg graphviz rendering

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

19
api.py
View file

@ -2,6 +2,8 @@ from app import app, db
from models import User, Achievement
import json
from graphviz import Digraph
from flask import escape
@app.route("/api")
@app.route("/api/all")
@ -15,3 +17,20 @@ 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 api_svg():
return dot_graph("svg")
@app.route("/api/dot")
def api_dot():
return dot_graph("dot")
def dot_graph(format):
dot = Digraph(format=format)
for user in User.query.all():
dot.node(escape(user.id), escape(user.id))
for achievement in Achievement.query.all():
for endorser in achievement.endorsed_by:
dot.edge(escape(endorser.id), escape(achievement.achieved_by), label=escape(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