from flask import redirect, url_for, send_file
from werkzeug.utils import secure_filename
import os.path
from app import app
from app.models.user import Member
from app.models.trophy import Trophy
from app.utils import unicode_names
from app.utils.render import render
from config import V5Config


@app.route('/membre/<username>')
def user(username):
    norm = unicode_names.normalize(username)
    member = Member.query.filter_by(norm=norm).first_or_404()
    trophies = Trophy.query.all()
    return render('account/user.html', member=member, trophies=trophies)


@app.route('/membre/id/<int:user_id>')
def user_by_id(user_id):
    member = Member.query.filter_by(id=user_id).first_or_404()
    return redirect(url_for('user', username=member.name))
