separating users and admins on admin dashboard #35
2 changed files with 20 additions and 5 deletions
|
@ -9,9 +9,9 @@ bp = Blueprint("admin", __name__, url_prefix="/admin")
|
||||||
from goathacks import db, mail as app_mail
|
from goathacks import db, mail as app_mail
|
||||||
from goathacks.admin import events
|
from goathacks.admin import events
|
||||||
|
|
||||||
@bp.route("/")
|
# Helper function for admin.home and admin.admin_list to render list of users.
|
||||||
@login_required
|
# This function was abstracted to promote code reuse.
|
||||||
def home():
|
def render_user_list(admin_list):
|
||||||
if not current_user.is_admin:
|
if not current_user.is_admin:
|
||||||
return redirect(url_for("dashboard.home"))
|
return redirect(url_for("dashboard.home"))
|
||||||
male_count = 0
|
male_count = 0
|
||||||
|
@ -21,7 +21,10 @@ def home():
|
||||||
waitlist_count = 0
|
waitlist_count = 0
|
||||||
total_count = 0
|
total_count = 0
|
||||||
shirt_count = {'XS': 0, 'S': 0, 'M': 0, 'L': 0, 'XL': 0}
|
shirt_count = {'XS': 0, 'S': 0, 'M': 0, 'L': 0, 'XL': 0}
|
||||||
hackers = db.session.execute(db.select(User)).scalars().all()
|
if(admin_list):
|
||||||
|
hackers = db.session.execute(db.select(User).where(User.is_admin)).scalars().all()
|
||||||
|
else:
|
||||||
|
hackers = db.session.execute(db.select(User).where(User.is_admin == False)).scalars().all()
|
||||||
schools = {}
|
schools = {}
|
||||||
|
|
||||||
for h in hackers:
|
for h in hackers:
|
||||||
|
@ -55,6 +58,17 @@ def home():
|
||||||
female_count=female_count, nb_count=nb_count,
|
female_count=female_count, nb_count=nb_count,
|
||||||
check_in_count=check_in_count, schools=schools)
|
check_in_count=check_in_count, schools=schools)
|
||||||
|
|
||||||
|
@bp.route("/")
|
||||||
|
@login_required
|
||||||
|
def home():
|
||||||
|
return render_user_list(False) # list users (not admins)
|
||||||
|
|
||||||
|
@bp.route("/admin_list")
|
||||||
|
@login_required
|
||||||
|
def admin_list():
|
||||||
|
return render_user_list(True) # list users (admins)
|
||||||
|
|
||||||
|
|
||||||
@bp.route("/mail")
|
@bp.route("/mail")
|
||||||
@login_required
|
@login_required
|
||||||
def mail():
|
def mail():
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
||||||
<ul class="nav navbar-nav me-auto mb-2 mb-lg-0">
|
<ul class="nav navbar-nav me-auto mb-2 mb-lg-0">
|
||||||
{{ render_nav_item('admin.home', 'User List')}}
|
{{ render_nav_item('admin.home', 'User List')}}
|
||||||
|
{{ render_nav_item('admin.admin_list', 'Admin List')}}
|
||||||
{{ render_nav_item('admin.list_events', 'Event List')}}
|
{{ render_nav_item('admin.list_events', 'Event List')}}
|
||||||
{{ render_nav_item('admin.mail', 'Bulk Mail Tool')}}
|
{{ render_nav_item('admin.mail', 'Bulk Mail Tool')}}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
Loading…
Add table
Reference in a new issue