Add admin dashboard skeleton

This commit is contained in:
Tim Van Baak 2020-01-15 17:15:51 -08:00
parent c305212130
commit 634c00ae53
4 changed files with 49 additions and 0 deletions

View File

@ -1,9 +1,15 @@
from flask import Blueprint, render_template, url_for from flask import Blueprint, render_template, url_for
from flask_login import login_required, current_user from flask_login import login_required, current_user
from flask_wtf import FlaskForm
from wtforms import TextAreaField, SubmitField
import config import config
import user import user
class DashboardForm(FlaskForm):
submit = SubmitField("Submit")
text = TextAreaField()
def get_bp(): def get_bp():
"""Create a blueprint for pages outside of a specific lexicon""" """Create a blueprint for pages outside of a specific lexicon"""
bp = Blueprint('home', __name__, url_prefix='/home') bp = Blueprint('home', __name__, url_prefix='/home')
@ -13,4 +19,22 @@ def get_bp():
def home(): def home():
return render_template('home/home.html') return render_template('home/home.html')
@bp.route('/admin/', methods=['GET'])
@login_required
def admin():
if not current_user.get('admin'):
return redirect(url_for('home.home'))
with config.json_ro('config.json') as j:
global_config = j
import json
text = json.dumps(j, indent=2, allow_nan=False)
form = DashboardForm()
if form.is_submitted():
return "k"
else:
form.text.data = text
return render_template('home/admin.html', form=form)
return bp return bp

View File

@ -0,0 +1,17 @@
{% extends "page_2col.html" %}
{% block title %}Admin | Amanuensis{% endblock %}
{% block header %}<h2>Amanuensis - Admin Dashboard</h2>{% endblock %}
{% block sb_topline %}<b>{{ current_user.get('displayname') }}</b>{% endblock %}
{% block sb_logout %}<a href="{{ url_for('auth.logout') }}">Log out</a>{% endblock %}
{% block sb_home %}<a href="{{ url_for('home.home') }}">Home</a>{% endblock %}
{% set template_sidebar_rows = [self.sb_topline(), self.sb_logout(), self.sb_home()] %}
{% block main %}
<form action="" method="post" novalidate>
{{ form.hidden_tag() }}
<p>{{ form.text() }}</p>
<p>{{ form.submit() }}</p>
</form>
{% endblock %}
{% set template_content_blocks = [self.main()] %}

View File

@ -1,9 +1,16 @@
{% extends "page_2col.html" %} {% extends "page_2col.html" %}
{% block title %}Home | Amanuensis{% endblock %} {% block title %}Home | Amanuensis{% endblock %}
{% block header %}<h2>Amanuensis - Dashboard</h2>{% endblock %} {% block header %}<h2>Amanuensis - Dashboard</h2>{% endblock %}
{% block sb_topline %}<b>{{ current_user.get('displayname') }}</b>{% endblock %} {% block sb_topline %}<b>{{ current_user.get('displayname') }}</b>{% endblock %}
{% block sb_logout %}<a href="{{ url_for('auth.logout') }}">Log out</a>{% endblock %} {% block sb_logout %}<a href="{{ url_for('auth.logout') }}">Log out</a>{% endblock %}
{% set template_sidebar_rows = [self.sb_topline(), self.sb_logout()] %} {% set template_sidebar_rows = [self.sb_topline(), self.sb_logout()] %}
{% if current_user.get('admin') %}
{% block sb_admin %}<a href="{{ url_for('home.admin') }}">Admin</a>{% endblock %}
{% set template_sidebar_rows = template_sidebar_rows + [self.sb_admin()] %}
{% endif %}
{% block main %} {% block main %}
<h1>Home Page</h1> <h1>Home Page</h1>
{% endblock %} {% endblock %}

View File

@ -58,6 +58,7 @@ def create_user(username, displayname, email):
'password': None, 'password': None,
'created': now, 'created': now,
'newPasswordRequired': True, 'newPasswordRequired': True,
'admin': False,
} }
config.new_user(user_json) config.new_user(user_json)
u = User(uid) u = User(uid)