Added Achievement display

This commit is contained in:
Robbe Van Herck 2018-07-17 09:44:20 +02:00
parent d0fa5d0375
commit a65e2c48cb
No known key found for this signature in database
GPG key ID: 4D1C8E8FBD1C7188
3 changed files with 15 additions and 3 deletions

View file

@ -1,6 +1,7 @@
from app import app, db from app import app, db
from models import Achievement from models import Achievement
from flask import render_template
from flask_login import current_user, login_required from flask_login import current_user, login_required
import json import json
@ -9,8 +10,8 @@ import json
def get_achievement(id): def get_achievement(id):
achievement = Achievement.query.filter_by(id=id).first() achievement = Achievement.query.filter_by(id=id).first()
if not achievement: if not achievement:
return "{}" return "Unknown achievement"
return json.dumps(achievement.to_obj()) return render_template("achievement.html", data=achievement)
@app.route("/achievement/<id>/endorse") @app.route("/achievement/<id>/endorse")
@login_required @login_required

View file

@ -0,0 +1,11 @@
<html>
<body>
<h2>{{data.name}}</h2>
<ul>
{% for endorser in data.endorsed_by -%}
<li> <a href="{{url_for('get_user', id=endorser.id)}}">{{ endorser.id }} </a></li>
{% endfor -%}
<li> <a href="{{url_for('endorse_achievement', id=data.id)}}">Endorse</a></li>
</ul>
</body>
</html>

View file

@ -3,7 +3,7 @@
<h2>{{data.id}}</h2> <h2>{{data.id}}</h2>
<ul> <ul>
{% for achievement in data.achievements -%} {% for achievement in data.achievements -%}
<li> {{ achievement.name }}: {{ achievement.endorsed_by|length }} endorsement{{ "s" if (achievement.endorsed_by|length != 1) else "" }}</li> <li> <a href="{{url_for('get_achievement', id=achievement.id)}}">{{ achievement.name }}</a>: {{ achievement.endorsed_by|length }} endorsement{{ "s" if (achievement.endorsed_by|length != 1) else "" }}</li>
{% endfor -%} {% endfor -%}
<li> <a href="{{url_for('add_achievement', id=data.id)}}">Add achievement</a></li> <li> <a href="{{url_for('add_achievement', id=data.id)}}">Add achievement</a></li>
</ul> </ul>