Skip to content

Commit

Permalink
Merge pull request #69 from nsidc/create_user_list_view
Browse files Browse the repository at this point in the history
Create user list view
  • Loading branch information
rmarow authored Jul 31, 2023
2 parents b76ae62 + 1752c1f commit 576cf02
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 11 deletions.
2 changes: 1 addition & 1 deletion usaon_vta_survey/constants/roles.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ROLES = [
'admin',
# 'respondent',
'respondent',
# 'analyst',
]
1 change: 1 addition & 0 deletions usaon_vta_survey/routes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
import usaon_vta_survey.routes.profile
import usaon_vta_survey.routes.survey
import usaon_vta_survey.routes.surveys
import usaon_vta_survey.routes.users
13 changes: 13 additions & 0 deletions usaon_vta_survey/routes/users.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from flask import render_template

from usaon_vta_survey import app
from usaon_vta_survey.models.tables import User


@app.route('/users')
def view_users():
users = User.query.order_by(User.name).all()
return render_template(
'users.html',
users=users,
)
2 changes: 1 addition & 1 deletion usaon_vta_survey/templates/base.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% from 'macros/user_login_management_buttons.j2' import user_login_buttons %}
{% from 'macros/login_button_or_private_nav_buttons.j2' import user_login_buttons %}

<!doctype html>
<head>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% macro user_login_buttons(current_user) -%}
{% if current_user.is_authenticated %}
{% if current_user.role=='admin' %}
<a href="{{url_for('profile', user_id=current_user.id)}}">Profile</a>
<a href="{{url_for('view_users')}}">Users</a>
<a href="{{url_for('logout')}}">Logout</a>
{% else %}
<a href="{{url_for('profile', user_id=current_user.id)}}">Profile</a>
<a href="{{url_for('logout')}}">Logout</a>
{% endif %}
{% else %}
<a href="{{url_for('login')}}">Login</a>
{% endif %}

{%- endmacro -%}

This file was deleted.

35 changes: 35 additions & 0 deletions usaon_vta_survey/templates/users.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{% extends 'base.html' %}


{% block content %}
<h2>{% block title %}Users{% endblock %}</h1>

{% if not current_user.is_authenticated %}
<h3>Please login to view this page.</h3>
{% else %}
{% if not current_user.role=='admin' %}
<h3>You don't belong here! This page is for admins only.</h3>
{% else %}
<table>

<tr>
<th>id</th>
<th>Name</th>
<th>Role</th>
<th>Affiliation</th>
<th>Bio</th>

{% for user in users %}
<tr>
<td>{{user.id}} </td>
<td>{{user.name}}</td>
<td>{{user.role}}</td>
<td>{{user.affiliation}}</td>
<td>{{user.biography}}</td>
</tr>
{% endfor %}

</table>
{% endif %}
{% endif %}
{% endblock %}

0 comments on commit 576cf02

Please sign in to comment.