2022-12-23 17:08:33 +00:00
|
|
|
from flask import (
|
|
|
|
abort,
|
|
|
|
redirect,
|
|
|
|
render_template,
|
|
|
|
send_from_directory,
|
|
|
|
url_for
|
|
|
|
)
|
2023-03-14 10:44:15 +00:00
|
|
|
from flask_breadcrumbs import register_breadcrumb
|
2022-09-02 11:07:30 +00:00
|
|
|
from flask_login import current_user, login_required
|
2022-12-23 17:08:33 +00:00
|
|
|
import os
|
2023-03-17 14:56:37 +00:00
|
|
|
from app.models import Corpus, User
|
2022-09-02 11:07:30 +00:00
|
|
|
from . import bp
|
2023-03-17 14:56:37 +00:00
|
|
|
from .utils import user_dynamic_list_constructor as user_dlc
|
2023-03-14 10:44:15 +00:00
|
|
|
|
2022-09-02 11:07:30 +00:00
|
|
|
|
2023-03-14 10:44:15 +00:00
|
|
|
@bp.route('')
|
2023-03-16 08:29:57 +00:00
|
|
|
@register_breadcrumb(bp, '.', '<i class="material-icons left">group</i>Users')
|
2022-12-23 17:08:33 +00:00
|
|
|
@login_required
|
2023-03-14 10:44:15 +00:00
|
|
|
def users():
|
|
|
|
return redirect(url_for('main.social_area', _anchor='users'))
|
|
|
|
|
2022-09-02 11:07:30 +00:00
|
|
|
|
|
|
|
@bp.route('/<hashid:user_id>')
|
2023-03-14 10:44:15 +00:00
|
|
|
@register_breadcrumb(bp, '.entity', '', dynamic_list_constructor=user_dlc)
|
2022-09-02 11:07:30 +00:00
|
|
|
@login_required
|
|
|
|
def user(user_id):
|
2022-12-23 17:08:33 +00:00
|
|
|
user = User.query.get_or_404(user_id)
|
2023-03-22 11:06:33 +00:00
|
|
|
if not (user.is_public or user == current_user or current_user.is_administrator()):
|
2022-12-23 17:08:33 +00:00
|
|
|
abort(403)
|
|
|
|
return render_template(
|
2023-03-22 11:06:33 +00:00
|
|
|
'users/user.html.j2',
|
2023-03-28 12:19:37 +00:00
|
|
|
title=user.username,
|
|
|
|
user=user
|
2022-12-23 17:08:33 +00:00
|
|
|
)
|
2022-09-02 11:07:30 +00:00
|
|
|
|
|
|
|
|
2022-12-23 17:08:33 +00:00
|
|
|
@bp.route('/<hashid:user_id>/avatar')
|
2023-03-14 10:44:15 +00:00
|
|
|
@login_required
|
2023-03-22 11:06:33 +00:00
|
|
|
def user_avatar(user_id):
|
2022-12-23 17:08:33 +00:00
|
|
|
user = User.query.get_or_404(user_id)
|
2023-03-16 08:54:48 +00:00
|
|
|
if not (user.is_public or user == current_user or current_user.is_administrator()):
|
|
|
|
abort(403)
|
2022-12-23 17:08:33 +00:00
|
|
|
if user.avatar is None:
|
2023-03-14 13:21:23 +00:00
|
|
|
return redirect(url_for('static', filename='images/user_avatar.png'))
|
2022-12-23 17:08:33 +00:00
|
|
|
return send_from_directory(
|
|
|
|
os.path.dirname(user.avatar.path),
|
|
|
|
os.path.basename(user.avatar.path),
|
|
|
|
as_attachment=True,
|
|
|
|
attachment_filename=user.avatar.filename,
|
|
|
|
mimetype=user.avatar.mimetype
|
|
|
|
)
|