from flask import ( abort, redirect, render_template, send_from_directory, url_for ) from flask_breadcrumbs import register_breadcrumb from flask_login import current_user, login_required import os from app.models import Corpus, User from . import bp from .utils import user_dynamic_list_constructor as user_dlc @bp.route('') @register_breadcrumb(bp, '.', 'groupUsers') @login_required def users(): return redirect(url_for('main.social_area', _anchor='users')) @bp.route('/') @register_breadcrumb(bp, '.entity', '', dynamic_list_constructor=user_dlc) @login_required def user(user_id): user = User.query.get_or_404(user_id) if not (user.is_public or user == current_user or current_user.is_administrator()): abort(403) return render_template( 'users/user.html.j2', title=user.username, user=user ) @bp.route('//avatar') @login_required def user_avatar(user_id): user = User.query.get_or_404(user_id) if not (user.is_public or user == current_user or current_user.is_administrator()): abort(403) if user.avatar is None: return redirect(url_for('static', filename='images/user_avatar.png')) 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 )