from app import app, db from models import User, Achievement from flask import request, render_template from flask_login import current_user, login_required import json @app.route("/users//addachievement") @login_required def add_achievement(id): name = request.args.get("name") if not name: return "No name supplied" achievement = Achievement(name=name, achieved_by=id) achievement.endorsed_by.append(current_user) db.session.add(achievement) db.session.commit() return "OK" @app.route("/users/") def get_user(id): user = User.query.filter_by(id=id).first() if not user: return "Unknown user" return render_template("user.html", data=user.to_obj()) @app.route("/users/") def all_users(): return json.dumps([user.to_obj() for user in User.query.all()])