diff --git a/app/auth/models.py b/app/auth/models.py index e276fd9..c5beeb9 100644 --- a/app/auth/models.py +++ b/app/auth/models.py @@ -30,7 +30,7 @@ _nameToRole = { } -def _checkRole(role): +def _check_role(role): if isinstance(role, int): rv = role elif str(role) == role: @@ -65,14 +65,14 @@ class User(UserMixin, db.Model): self.password = None def set_role(self, role): - self.role = _checkRole(role) + self.role = _check_role(role) def has_role(self, role): - role = _checkRole(role) + role = _check_role(role) return self.role == role def has_role_or_higher(self, role): - role = _checkRole(role) + role = _check_role(role) return self.role and (self.role >= role) def set_password(self, password): diff --git a/app/auth/routes.py b/app/auth/routes.py index 71f4e6f..8ea1276 100644 --- a/app/auth/routes.py +++ b/app/auth/routes.py @@ -7,6 +7,8 @@ from flask_login import login_user, logout_user from app.auth.models import User from app.auth import bp +main_index = 'main.index' + # # Decorator used to protect routes by role @@ -30,10 +32,10 @@ def role_required(role): try: is_authorised = current_user.has_role_or_higher(role) except ValueError: - raise Exception("Unknowk role provided %s" % role) + raise ValueError("Unknown role provided %s" % role) if not is_authorised: flash("Vous n'avez pas les autorisations pour accéder à cette page", 'dark') - return redirect(url_for('main.index')) + return redirect(url_for(main_index)) return f(*args, **kwargs) return decorated_function @@ -50,12 +52,11 @@ def login(): def login_post(): user_login = request.form.get('login') user_password = request.form.get('password') - # user_remember = request.form.get('remember') user = User.query.filter_by(login=user_login).one_or_none() if user and user.check_password(user_password): login_user(user) flash("Connection Réussie !", 'success') - return redirect(url_for('main.index')) + return redirect(url_for(main_index)) else: flash("Mauvais login ou mot de passe.", 'warning') return redirect(url_for('auth.login')) @@ -65,4 +66,4 @@ def login_post(): def logout(): logout_user() flash("Vous êtes maintenant déconnecté", 'info') - return redirect(url_for('main.index')) + return redirect(url_for(main_index)) diff --git a/app/commands/commands.py b/app/commands/commands.py index 86bf26e..2e5e1ce 100644 --- a/app/commands/commands.py +++ b/app/commands/commands.py @@ -433,7 +433,7 @@ def feed_periods(begin_year, end_year): @click.option('--agent', '-a', 'agent', default=None, help="the agent id you want to charge") def feed_random_charges(agent): """ Randomly fill in the agents charges. """ - for i in range(0, 100): + for _ in range(0, 100): if agent is None: agent_id = random.choice([i for (i,) in db.session.query(Agent.id).all()]) else: diff --git a/app/errors/handlers.py b/app/errors/handlers.py index 420cc81..78b34c5 100644 --- a/app/errors/handlers.py +++ b/app/errors/handlers.py @@ -2,30 +2,32 @@ from flask import render_template from app import db from . import bp - # Inspired by: # https://flask.palletsprojects.com/en/master/patterns/errorpages/ +error_page = 'error.html' + + @bp.app_errorhandler(403) def forbidden_error(error): error_title = "Page Interdite" - return render_template('error.html', error_title=error_title, error_msg=error), 403 + return render_template(error_page, error_title=error_title, error_msg=error), 403 @bp.app_errorhandler(404) def not_found_error(error): error_title = "Page Introuvable." - return render_template('error.html', error_title=error_title, error_msg=error), 404 + return render_template(error_page, error_title=error_title, error_msg=error), 404 @bp.app_errorhandler(405) def method_error(error): error_title = "Erreur de Méthode." - return render_template('error.html', error_title=error_title, error_msg=error), 405 + return render_template(error_page, error_title=error_title, error_msg=error), 405 @bp.app_errorhandler(500) def internal_error(error): db.session.rollback() error_title = "Erreur Interne. Administrateur Prévenu." - return render_template('error.html', error_title=error_title, error_msg=error), 500 + return render_template(error_page, error_title=error_title, error_msg=error), 500 -- libgit2 0.21.2