Coverage for modules/box__default/appadmin/admin.py: 70%

# Coverage for modules/box__default/appadmin/admin.py : 70%

## 21 statements

Hot-keys on this page

r m x p toggle line displays

j k next/prev highlighted chunk

0 (zero) top of page

1 (one) first highlighted chunk

1 from functools import wraps

2

3 from flask import flash

4 from flask import redirect

5 from flask import url_for

6 from flask_login import current_user

7 from init import login_manager

8 from modules.box__default.auth.models import User

9

10 from shopyo.api.html import notify_warning

11

12 login_manager.login_view = "auth.login"

13 login_manager.login_message = notify_warning("Please login for access")

14

15

16@login_manager.user_loader

17 def load_user(id):

18 return User.query.get(id)

19

20

21 def admin_required(f):

22 @wraps(f)

23 def wrap(*args, **kwargs):

24 if current_user.is_admin:

25 return f(*args, **kwargs)

26 else:

27 flash(notify_warning("You need to be an admin to view this page."))

28 return redirect(url_for("dashboard.index"))

29

30 return wrap