From 6c244b084cf1aa3307e56a9d91f1101bca203ba7 Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Fri, 31 Jan 2020 13:59:14 -0800 Subject: [PATCH] Display public games on /home/ --- amanuensis/server/home.py | 17 ++++++++++++----- amanuensis/templates/home/home.html | 14 ++++++++++++-- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/amanuensis/server/home.py b/amanuensis/server/home.py index 728f6cf..b519681 100644 --- a/amanuensis/server/home.py +++ b/amanuensis/server/home.py @@ -3,7 +3,7 @@ from flask_login import login_required, current_user from amanuensis.config import json_ro, json_rw from amanuensis.lexicon import LexiconModel -from amanuensis.lexicon.manage import create_lexicon, get_user_lexicons +from amanuensis.lexicon.manage import create_lexicon, get_all_lexicons from amanuensis.server.forms import LexiconCreateForm from amanuensis.server.helpers import admin_required from amanuensis.user import UserModel @@ -15,10 +15,17 @@ def get_bp(): @bp.route('/', methods=['GET']) def home(): - lexicons = [] - if current_user.is_authenticated: - lexicons = get_user_lexicons(current_user) - return render_template('home/home.html', lexicons=lexicons) + user_lexicons = [] + public_lexicons = [] + for lexicon in get_all_lexicons(): + if current_user.in_lexicon(lexicon): + user_lexicons.append(lexicon) + elif lexicon.join.public: + public_lexicons.append(lexicon) + return render_template( + 'home/home.html', + user_lexicons=user_lexicons, + public_lexicons=public_lexicons) @bp.route('/admin/', methods=['GET']) @login_required diff --git a/amanuensis/templates/home/home.html b/amanuensis/templates/home/home.html index 5a58857..555b0fb 100644 --- a/amanuensis/templates/home/home.html +++ b/amanuensis/templates/home/home.html @@ -13,14 +13,24 @@ {% if current_user.is_authenticated %}

Your games

-{% if lexicons %} -{% for lexicon in lexicons %} +{% if user_lexicons %} +{% for lexicon in user_lexicons %} {{ macros.dashboard_lexicon_item(lexicon) }} {% endfor %} {% else %}

You haven't joined a game yet.

{% endif %} {% endif %} + +

Public games

+{% if public_lexicons %} +{% for lexicon in public_lexicons %} +{{ macros.dashboard_lexicon_item(lexicon) }} +{% endfor %} +{% else %} +

No public games available.

+{% endif %} + {% endblock %} {% set template_content_blocks = [self.main()] %}