Added svg graphviz rendering
This commit is contained in:
parent
bafda3862d
commit
4ad2b75835
2 changed files with 13 additions and 3 deletions
12
api.py
12
api.py
|
@ -2,6 +2,7 @@ from app import app, db
|
||||||
from models import User, Achievement
|
from models import User, Achievement
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
from graphviz import Digraph
|
||||||
|
|
||||||
@app.route("/api")
|
@app.route("/api")
|
||||||
@app.route("/api/all")
|
@app.route("/api/all")
|
||||||
|
@ -15,3 +16,14 @@ def api_all_users():
|
||||||
@app.route("/api/achievements")
|
@app.route("/api/achievements")
|
||||||
def api_all_achievements():
|
def api_all_achievements():
|
||||||
return json.dumps([achievement.to_obj() for achievement in Achievement.query.all()])
|
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")
|
||||||
|
|
||||||
|
|
|
@ -5,14 +5,12 @@ Flask==1.0.2
|
||||||
Flask-Login==0.4.1
|
Flask-Login==0.4.1
|
||||||
Flask-OAuthlib==0.9.5
|
Flask-OAuthlib==0.9.5
|
||||||
Flask-SQLAlchemy==2.3.2
|
Flask-SQLAlchemy==2.3.2
|
||||||
|
graphviz==0.10.1
|
||||||
idna==2.7
|
idna==2.7
|
||||||
itsdangerous==0.24
|
itsdangerous==0.24
|
||||||
Jinja2==2.10
|
Jinja2==2.10
|
||||||
MarkupSafe==1.0
|
MarkupSafe==1.0
|
||||||
mysql==0.0.2
|
|
||||||
mysqlclient==1.3.13
|
|
||||||
oauthlib==2.1.0
|
oauthlib==2.1.0
|
||||||
pkg-resources==0.0.0
|
|
||||||
pytz==2018.5
|
pytz==2018.5
|
||||||
requests==2.19.1
|
requests==2.19.1
|
||||||
requests-oauthlib==1.0.0
|
requests-oauthlib==1.0.0
|
||||||
|
|
Loading…
Reference in a new issue