La version 5 de Planète Casio. Regroupe le forum, les programmes, les tutoriel, les sprites et tous les autres outils développés par nos soins.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

decorators.py 454B

1234567891011121314151617
  1. from flask import redirect, url_for, flash
  2. from flask import current_user
  3. import functools
  4. # Use only with @login_required.
  5. def privilege_required(priv):
  6. def privilege_decorator(f):
  7. @functools.wraps(f)
  8. def wrapper():
  9. if not current_user.priv(priv):
  10. flash(f'Cette page est protégée par le privilège <code>{priv}'+
  11. '</code>', 'error')
  12. return redirect(url_for('index'))
  13. else:
  14. f()
  15. return wrapper
  16. return privilege_decorator