From ede475f91020234f83ca1f5ecae761af03afb1c2 Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Tue, 14 Jan 2020 16:37:51 -0800 Subject: [PATCH] Add real page templates and home and logout pages --- amanuensis/resources/default_config.json | 1 + amanuensis/resources/page.css | 119 +++++++++++++++++++++++ amanuensis/server/__init__.py | 14 ++- amanuensis/server/auth.py | 14 ++- amanuensis/server/home.py | 18 ++++ amanuensis/templates/auth/login.html | 13 ++- amanuensis/templates/home/home.html | 7 ++ amanuensis/templates/page.html | 22 +++++ amanuensis/templates/page_1col.html | 3 + amanuensis/templates/page_2col.html | 8 ++ 10 files changed, 207 insertions(+), 12 deletions(-) create mode 100644 amanuensis/resources/page.css create mode 100644 amanuensis/server/home.py create mode 100644 amanuensis/templates/home/home.html create mode 100644 amanuensis/templates/page.html create mode 100644 amanuensis/templates/page_1col.html create mode 100644 amanuensis/templates/page_2col.html diff --git a/amanuensis/resources/default_config.json b/amanuensis/resources/default_config.json index 60bc497..7478c74 100644 --- a/amanuensis/resources/default_config.json +++ b/amanuensis/resources/default_config.json @@ -3,6 +3,7 @@ "address": "127.0.0.1", "port": "5000", "lexicon_data": "./lexicon", + "static_root": "./static", "logging": { "version": 1, "formatters": { diff --git a/amanuensis/resources/page.css b/amanuensis/resources/page.css new file mode 100644 index 0000000..3d0bc89 --- /dev/null +++ b/amanuensis/resources/page.css @@ -0,0 +1,119 @@ +body { + background-color: #eeeeee; + line-height: 1.4; + font-size: 16px; +} +div#wrapper { + max-width: 800px; + position: absolute; + left: 0; + right: 0; + margin: 0 auto; +} +div#header { + padding: 5px; + margin: 5px; + background-color: #ffffff; + box-shadow: 2px 2px 10px #888888; + border-radius: 5px; +} +div#header p, div#header h2 { + margin: 5px; +} +div#sidebar { + width: 200px; + float:left; + margin:5px; + padding: 8px; + text-align: center; + background-color: #ffffff; + box-shadow: 2px 2px 10px #888888; + border-radius: 5px; +} +img#logo { + max-width: 200px; +} +table { + table-layout: fixed; + width: 100%; +} +div#sidebar table { + border-collapse: collapse; +} +div.citeblock table td:first-child + td a { + justify-content: flex-end; +} +div.misclinks table td a { + justify-content: center; +} +table a { + display: flex; + padding: 3px; + background-color: #dddddd; + border-radius: 5px; + text-decoration: none; +} +div#sidebar table a { + justify-content: center; +} +table a:hover { + background-color: #cccccc; +} +div#sidebar table td { + padding: 0px; margin: 3px 0; + border-bottom: 8px solid transparent; +} +div#content { + margin: 5px; +} +div.content-2col { + position: absolute; + right: 0px; + left: 226px; + max-width: 564px; +} +div.contentblock { + background-color: #ffffff; + box-shadow: 2px 2px 10px #888888; + margin-bottom: 5px; + padding: 10px; + width: auto; + border-radius: 5px; +} +div.contentblock h3 { + margin: 0.3em 0; +} +a.phantom { + color: #cc2200; +} +div.citeblock a.phantom { + font-style: italic; +} +span.signature { + text-align: right; +} +@media only screen and (max-width: 816px) { + div#wrapper { + padding: 5px; + } + div#header { + max-width: 554; + margin: 0 auto; + } + div#sidebar { + max-width: 548; + width: inherit; + float: inherit; + margin: 5px auto; + } + div#content { + max-width: 564px; + position: static; + right: inherit; + margin: 5px auto; + } + img#logo { + max-width: inherit; + width: 100%; + } +} \ No newline at end of file diff --git a/amanuensis/server/__init__.py b/amanuensis/server/__init__.py index 54f8ee2..026cd47 100644 --- a/amanuensis/server/__init__.py +++ b/amanuensis/server/__init__.py @@ -1,12 +1,24 @@ +import os + from flask import Flask, render_template from flask_login import LoginManager import config from server.auth import get_bp as get_auth_bp +from server.home import get_bp as get_home_bp -app = Flask(__name__, template_folder="../templates") +# Flask app init +static_root = os.path.abspath(config.get("static_root")) +app = Flask(__name__, template_folder="../templates", static_folder=static_root) app.secret_key = bytes.fromhex(config.get('secret_key')) + +# Flask-Login init login = LoginManager(app) +login.login_view = 'auth.login' + +# Blueprint inits auth_bp = get_auth_bp(login) app.register_blueprint(auth_bp) +home_bp = get_home_bp() +app.register_blueprint(home_bp) diff --git a/amanuensis/server/auth.py b/amanuensis/server/auth.py index da3e414..4950e64 100644 --- a/amanuensis/server/auth.py +++ b/amanuensis/server/auth.py @@ -1,8 +1,8 @@ -import flask +from flask import Blueprint, render_template, redirect, url_for from flask_wtf import FlaskForm from wtforms import StringField, PasswordField, BooleanField, SubmitField from wtforms.validators import DataRequired -from flask_login import current_user, login_user +from flask_login import current_user, login_user, logout_user, login_required import config import user @@ -15,7 +15,7 @@ class LoginForm(FlaskForm): def get_bp(login_manager): """Create a blueprint for the auth functions""" - bp = flask.Blueprint('auth', __name__, url_prefix='/auth') + bp = Blueprint('auth', __name__, url_prefix='/auth') @login_manager.user_loader def load_user(uid): @@ -35,6 +35,12 @@ def get_bp(login_manager): name = u.get('username') else: name = "guest" - return flask.render_template('auth/login.html', form=form, username=name) + return render_template('auth/login.html', form=form, username=name) + + @bp.route("/logout/", methods=['GET']) + @login_required + def logout(): + logout_user() + return redirect(url_for('auth.login')) return bp diff --git a/amanuensis/server/home.py b/amanuensis/server/home.py new file mode 100644 index 0000000..1f31f60 --- /dev/null +++ b/amanuensis/server/home.py @@ -0,0 +1,18 @@ +from flask import Blueprint, render_template, url_for +from flask_login import login_required, current_user + +import config +import user + +def get_bp(): + """Create a blueprint for pages outside of a specific lexicon""" + bp = Blueprint('home', __name__, url_prefix='/home') + + @bp.route('/', methods=['GET']) + @login_required + def home(): + return render_template( + 'home/home.html', + sidebar_rows=[current_user.get('username'), current_user.get('displayname'), current_user.uid]) + + return bp diff --git a/amanuensis/templates/auth/login.html b/amanuensis/templates/auth/login.html index 30bc909..8c40578 100644 --- a/amanuensis/templates/auth/login.html +++ b/amanuensis/templates/auth/login.html @@ -1,12 +1,11 @@ - - - -

Hello, {{username}}

-{% if current_user.is_authenticated %}{{ current_user.get('displayname') }}{% endif %} +{% extends "page_1col.html" %} +{% block title %}Login | Amanuensis{% endblock %} +{% block header %}

Login

{% endblock %} +{% block primary_content %} +

Log in

{{ form.hidden_tag() }}

{{ form.username.label }}
{{ form.username(size=32) }}

{{ form.submit() }}

- - +{% endblock %} \ No newline at end of file diff --git a/amanuensis/templates/home/home.html b/amanuensis/templates/home/home.html new file mode 100644 index 0000000..6afe982 --- /dev/null +++ b/amanuensis/templates/home/home.html @@ -0,0 +1,7 @@ +{% extends "page_2col.html" %} +{% block title %}Home | Amanuensis{% endblock %} +{% block header %}

Amanuensis

{% endblock %} +{% block primary_content %} +

Home

+

Logout

+{% endblock %} \ No newline at end of file diff --git a/amanuensis/templates/page.html b/amanuensis/templates/page.html new file mode 100644 index 0000000..f84657d --- /dev/null +++ b/amanuensis/templates/page.html @@ -0,0 +1,22 @@ + + + + + + {% block title %}{% endblock %} + + + +
+ + {% block sidebar %}{% endblock %} +
+
+ {% block primary_content %}{% endblock %}
{% for content_block in additional_content %} +
+ {{ content_block|safe }}
+ {% endfor %} +
+
+ + diff --git a/amanuensis/templates/page_1col.html b/amanuensis/templates/page_1col.html new file mode 100644 index 0000000..0878463 --- /dev/null +++ b/amanuensis/templates/page_1col.html @@ -0,0 +1,3 @@ +{% extends "page.html" %} +{% block sidebar %}{% endblock %} +{% block content_class %}content-1col{% endblock %} \ No newline at end of file diff --git a/amanuensis/templates/page_2col.html b/amanuensis/templates/page_2col.html new file mode 100644 index 0000000..93c668f --- /dev/null +++ b/amanuensis/templates/page_2col.html @@ -0,0 +1,8 @@ +{% extends "page.html" %} +{% block sidebar %} +{% endblock %} +{% block content_class %}content-2col{% endblock %} \ No newline at end of file