Display public games on /home/

This commit is contained in:
Tim Van Baak 2020-01-31 13:59:14 -08:00
parent 81c18b5c7c
commit 6c244b084c
2 changed files with 24 additions and 7 deletions

View File

@ -3,7 +3,7 @@ from flask_login import login_required, current_user
from amanuensis.config import json_ro, json_rw from amanuensis.config import json_ro, json_rw
from amanuensis.lexicon import LexiconModel 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.forms import LexiconCreateForm
from amanuensis.server.helpers import admin_required from amanuensis.server.helpers import admin_required
from amanuensis.user import UserModel from amanuensis.user import UserModel
@ -15,10 +15,17 @@ def get_bp():
@bp.route('/', methods=['GET']) @bp.route('/', methods=['GET'])
def home(): def home():
lexicons = [] user_lexicons = []
if current_user.is_authenticated: public_lexicons = []
lexicons = get_user_lexicons(current_user) for lexicon in get_all_lexicons():
return render_template('home/home.html', lexicons=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']) @bp.route('/admin/', methods=['GET'])
@login_required @login_required

View File

@ -13,14 +13,24 @@
{% if current_user.is_authenticated %} {% if current_user.is_authenticated %}
<h2>Your games</h2> <h2>Your games</h2>
{% if lexicons %} {% if user_lexicons %}
{% for lexicon in lexicons %} {% for lexicon in user_lexicons %}
{{ macros.dashboard_lexicon_item(lexicon) }} {{ macros.dashboard_lexicon_item(lexicon) }}
{% endfor %} {% endfor %}
{% else %} {% else %}
<p>You haven't joined a game yet.</p> <p>You haven't joined a game yet.</p>
{% endif %} {% endif %}
{% endif %} {% endif %}
<h2>Public games</h2>
{% if public_lexicons %}
{% for lexicon in public_lexicons %}
{{ macros.dashboard_lexicon_item(lexicon) }}
{% endfor %}
{% else %}
<p>No public games available.</p>
{% endif %}
{% endblock %} {% endblock %}
{% set template_content_blocks = [self.main()] %} {% set template_content_blocks = [self.main()] %}