Added svg graphviz rendering
This commit is contained in:
parent
bafda3862d
commit
148f811d94
2 changed files with 20 additions and 3 deletions
19
api.py
19
api.py
|
@ -2,6 +2,8 @@ from app import app, db
|
||||||
from models import User, Achievement
|
from models import User, Achievement
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
from graphviz import Digraph
|
||||||
|
from flask import escape
|
||||||
|
|
||||||
@app.route("/api")
|
@app.route("/api")
|
||||||
@app.route("/api/all")
|
@app.route("/api/all")
|
||||||
|
@ -15,3 +17,20 @@ 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 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")
|
||||||
|
|
|
@ -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