from flask import redirect, url_for
from app import app
from app.models.users import Member
from app.utils.render import render


@app.route('/user/<username>')
def user(username):
    member = Member.query.filter_by(name=username).first_or_404()
    return render('user.html', member=member)


@app.route('/user/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))
