Get home screen working

This commit is contained in:
Tim Van Baak 2021-06-16 20:15:30 -07:00
parent 562d7d8a4b
commit 3cfc01a9c8
6 changed files with 49 additions and 53 deletions

View File

@ -4,6 +4,8 @@ import os
from flask import Flask, g from flask import Flask, g
import amanuensis.backend.lexicon
import amanuensis.backend.user
from amanuensis.config import AmanuensisConfig, CommandLineConfig from amanuensis.config import AmanuensisConfig, CommandLineConfig
from amanuensis.db import DbContext from amanuensis.db import DbContext
import amanuensis.server.auth as auth import amanuensis.server.auth as auth
@ -58,6 +60,11 @@ def get_app(
app.template_filter("date")(date_format) app.template_filter("date")(date_format)
def include_backend():
return {"db": db, "lexiq": amanuensis.backend.lexicon, "userq": amanuensis.backend.user}
app.context_processor(include_backend)
# Set up Flask-Login # Set up Flask-Login
auth.get_login_manager().init_app(app) auth.get_login_manager().init_app(app)

View File

@ -69,11 +69,11 @@ def login():
login_user(user, remember=remember_me) login_user(user, remember=remember_me)
userq.update_logged_in(g.db, username) userq.update_logged_in(g.db, username)
LOG.info("Logged in user {0.username} ({0.id})".format(user)) LOG.info("Logged in user {0.username} ({0.id})".format(user))
return redirect(url_for("home.admin")) return redirect(url_for("home.home"))
@bp.get("/logout/") @bp.get("/logout/")
@login_required @login_required
def logout(): def logout():
logout_user() logout_user()
return redirect(url_for("home.admin")) return redirect(url_for("home.home"))

View File

@ -1,43 +1,23 @@
from flask import Blueprint, render_template, g from flask import Blueprint, render_template, g
# from flask import Blueprint, render_template, redirect, url_for, current_app
# from flask_login import login_required, current_user
import amanuensis.backend.user as userq import amanuensis.backend.user as userq
import amanuensis.backend.lexicon as lexiq import amanuensis.backend.lexicon as lexiq
# from amanuensis.config import RootConfigDirectoryContext
# from amanuensis.lexicon import create_lexicon, load_all_lexicons
# from amanuensis.models import UserModel, ModelFactory
# from amanuensis.server.helpers import admin_required
# from .forms import LexiconCreateForm # from .forms import LexiconCreateForm
bp = Blueprint("home", __name__, url_prefix="/home", template_folder=".") bp = Blueprint("home", __name__, url_prefix="/home", template_folder=".")
# @bp.get("/") @bp.get("/")
# def home(): def home():
# Show lexicons that are visible to the current user return render_template('home.root.jinja')
# return "TODO"
# user_lexicons = []
# public_lexicons = []
# for lexicon in load_all_lexicons(root):
# if user.uid in lexicon.cfg.join.joined:
# user_lexicons.append(lexicon)
# elif lexicon.cfg.join.public:
# public_lexicons.append(lexicon)
# return render_template(
# 'home.root.jinja',
# user_lexicons=user_lexicons,
# public_lexicons=public_lexicons)
@bp.get("/admin/") @bp.get("/admin/")
# @login_required # @login_required
# @admin_required # @admin_required
def admin(): def admin():
return render_template("home.admin.jinja", db=g.db, userq=userq, lexiq=lexiq) return render_template("home.admin.jinja", userq=userq, lexiq=lexiq)
# @bp_home.route("/admin/create/", methods=['GET', 'POST']) # @bp_home.route("/admin/create/", methods=['GET', 'POST'])

View File

@ -4,7 +4,7 @@
{% block header %}<h2>Amanuensis - Admin Dashboard</h2>{% endblock %} {% block header %}<h2>Amanuensis - Admin Dashboard</h2>{% endblock %}
{# TODO #} {# TODO #}
{% block sb_home %}<a href="#{#{ url_for('home.home') }#}">Home</a>{% endblock %} {% block sb_home %}<a href="{{ url_for('home.home') }}">Home</a>{% endblock %}
{% block sb_create %}<a href="#{#{ url_for('home.admin_create') }#}">Create a lexicon</a>{% endblock %} {% block sb_create %}<a href="#{#{ url_for('home.admin_create') }#}">Create a lexicon</a>{% endblock %}
{% set template_sidebar_rows = [self.sb_home(), self.sb_create()] %} {% set template_sidebar_rows = [self.sb_home(), self.sb_create()] %}

View File

@ -11,10 +11,16 @@
<span style="color:#ff0000">{{ message }}</span><br> <span style="color:#ff0000">{{ message }}</span><br>
{% endfor %} {% endfor %}
{% if current_user.is_authenticated %}
{% set joined = lexiq.get_joined(db, current_user.id)|list %}
{% else %}
{% set joined = [] %}
{% endif %}
{% if current_user.is_authenticated %} {% if current_user.is_authenticated %}
<h2>Your games</h2> <h2>Your games</h2>
{% if user_lexicons %} {% if joined %}
{% for lexicon in user_lexicons %} {% for lexicon in joined %}
{{ macros.dashboard_lexicon_item(lexicon) }} {{ macros.dashboard_lexicon_item(lexicon) }}
{% endfor %} {% endfor %}
{% else %} {% else %}
@ -22,9 +28,10 @@
{% endif %} {% endif %}
{% endif %} {% endif %}
{% set public = lexiq.get_public(db)|reject("in", joined)|list %}
<h2>Public games</h2> <h2>Public games</h2>
{% if public_lexicons %} {% if public %}
{% for lexicon in public_lexicons %} {% for lexicon in public %}
{{ macros.dashboard_lexicon_item(lexicon) }} {{ macros.dashboard_lexicon_item(lexicon) }}
{% endfor %} {% endfor %}
{% else %} {% else %}
@ -34,7 +41,7 @@
{% endblock %} {% endblock %}
{% set template_content_blocks = [self.main()] %} {% set template_content_blocks = [self.main()] %}
{% if current_user.cfg.is_admin %} {% if current_user.is_site_admin %}
{% block admin_dash %} {% block admin_dash %}
<a href="{{ url_for('home.admin') }}" style="display:block; text-align:center;">Admin dashboard</a> <a href="{{ url_for('home.admin') }}" style="display:block; text-align:center;">Admin dashboard</a>
{% endblock %} {% endblock %}

View File

@ -3,33 +3,35 @@
<div class="dashboard-lexicon-item dashboard-lexicon-{{ status }}"> <div class="dashboard-lexicon-item dashboard-lexicon-{{ status }}">
<p> <p>
<span class="dashboard-lexicon-item-title"> <span class="dashboard-lexicon-item-title">
<a href="#{#{ url_for('lexicon.contents', name=lexicon.cfg.name) }#}"> <a href="#{#{ url_for('lexicon.contents', name=lexicon.cfg.name) }#}">{{ lexicon.full_title }}</a>
{{ lexicon.full_title }}</a>
</span> </span>
[{{ lexicon.status.capitalize() }}] [{{ status.capitalize() }}]
</p> </p>
<p><i>{{ lexicon.prompt }}</i></p> <p><i>{{ lexicon.prompt }}</i></p>
{% if current_user.is_authenticated %} {% if current_user.is_authenticated %}
<p> <p>
{# TODO #} {#-
{# {% Show detailed player information if the current user is a member of the lexicon or if the current user is a site admin. The filter sequence must be converted to a list because it returns a generator, which is truthy.
if current_user.uid in lexicon.cfg.join.joined -#}
{%-
if lexicon.memberships|map(attribute="user_id")|select("equalto", current_user.id)|list
or current_user.is_site_admin or current_user.is_site_admin
%} #} -%}
Editor: {#{ lexicon.cfg.editor|user_attr('username') }#} / Editor: {{
Players: lexicon.memberships|selectattr("is_editor")|map(attribute="user")|map(attribute="username")|join(", ")
{# {% for uid in lexicon.cfg.join.joined %} #} }} / Players: {{
{# {{ uid|user_attr('username') }}{% if not loop.last %}, {% endif %} #} lexicon.memberships|map(attribute="user")|map(attribute="username")|join(", ")
{# {% endfor %} #} }} ({{ lexicon.memberships|count }}
{# ({{ lexicon.cfg.join.joined|count }}/{{ lexicon.cfg.join.max_players }}) #} {%- if lexicon.player_limit is not none -%}
{# {% else %} #} /{{ lexicon.player_limit }}
{# Players: {{ lexicon.cfg.join.joined|count }}/{{ lexicon.cfg.join.max_players }} #} {%- endif -%})
{# {% if lexicon.cfg.join.public and lexicon.cfg.join.open %} #} {%- else -%}
{# / <a href="{{ url_for('lexicon.join', name=lexicon.cfg.name) }}"> #} Players: {{ lexicon.memberships|count }}{% if lexicon.player_limit is not none %} / {{ lexicon.player_limit }}{% endif -%}
{# Join game #} {%-
{# </a> #} if lexicon.public and lexicon.joinable
{# {% endif %} #} %} / <a href="#{#{ url_for('lexicon.join', name=lexicon.cfg.name) }#}">Join game</a>
{# {% endif %} #} {%- endif -%}
{%- endif -%}
</p> </p>
{% endif %} {% endif %}
</div> </div>