Add warning messages and button colors

This commit is contained in:
IamTheFij 2020-04-06 16:49:27 -07:00
parent 9049e457a4
commit a40a6a37f5
3 changed files with 14 additions and 3 deletions

View File

@ -9,6 +9,7 @@ from flask import render_template
from flask import request
from flask import session
from flask import url_for
from flask import flash
from flask_bootstrap import Bootstrap
from flask_sqlalchemy import SQLAlchemy
from flask_wtf import FlaskForm
@ -97,7 +98,9 @@ class AddWordForm(FlaskForm):
class PlayGameForm(FlaskForm):
draw_word = SubmitField(label='Draw word')
draw_word = SubmitField(
label='Draw word',
)
class ResetGameForm(FlaskForm):
@ -149,6 +152,8 @@ def game(game_uuid):
if word_form.submit_new_word.data and word_form.validate():
word = Word(text=word_form.new_word.data)
game.words.append(word)
flash(f"Word added: {word.text}")
word = None
# We just drew a new word!
if play_form.draw_word.data:
words = game.get_remaining_words()
@ -156,6 +161,10 @@ def game(game_uuid):
word = choice(words)
word.is_picked = True
else:
flash(
"No words left to draw. Either add more or reset.",
"warning",
)
word = None
# Reset the game
if reset_form.reset_game.data and reset_form.validate():

View File

@ -1,4 +1,5 @@
{% from 'bootstrap/nav.html' import render_nav_item %}
{% from 'bootstrap/utils.html' import render_messages %}
<!DOCTYPE html>
<html lang="en">
@ -23,6 +24,7 @@
</nav>
<main class="container">
{{ render_messages(container=False, dismissible=True) }}
{% block content %}{% endblock %}
</main>

View File

@ -11,11 +11,11 @@
<p>Your word is: {{ word.text }}</p>
{% endif %}
<p>Words remaining: {{ words|length }}</p>
{{ render_form(play_form) }}
{{ render_form(play_form, button_map={"draw_word": "primary"}) }}
<p></p>
<h4>Put words back</h4>
<p>Make all drawn words pickable again</p>
{{ render_form(reset_form) }}
{{ render_form(reset_form, button_map={"reset_game": "danger"}) }}
<h1>Add new word</h1>
{{ render_form(word_form) }}
{% endif %}