diff --git a/fishbowl/app.py b/fishbowl/app.py index d7ec7fe..0e2be74 100644 --- a/fishbowl/app.py +++ b/fishbowl/app.py @@ -13,7 +13,7 @@ from flask_bootstrap import Bootstrap from flask_sqlalchemy import SQLAlchemy from flask_wtf import FlaskForm from wtforms import StringField, SubmitField, BooleanField, PasswordField -from wtforms.validators import DataRequired, Length, Optional +from wtforms.validators import DataRequired, Length, Optional, ValidationError import flask_sqlalchemy @@ -98,8 +98,14 @@ class AddWordForm(FlaskForm): class PlayGameForm(FlaskForm): draw_word = SubmitField(label='Draw word') + + +class ResetGameForm(FlaskForm): reset_game = SubmitField(label='Reset game') - reset_confirm = BooleanField(label='Confirm reset') + reset_confirm = BooleanField( + label='Confirm reset', + validators=[DataRequired()], + ) @app.route('/', methods=['GET', 'POST']) @@ -126,6 +132,7 @@ def game(game_uuid): game_login = GameLoginForm() word_form = AddWordForm() play_form = PlayGameForm() + reset_form = ResetGameForm() try: game = Game.by_uuid(game_uuid) except flask_sqlalchemy.orm.exc.NoResultFound: @@ -145,16 +152,18 @@ def game(game_uuid): # We just drew a new word! if play_form.draw_word.data: words = game.get_remaining_words() - if words: + if words and len(words) > 0: word = choice(words) word.is_picked = True else: - word = "There are no words. Add some and try again!" + word = None # Reset the game - if play_form.reset_game.data and play_form.reset_confirm.data: + if reset_form.reset_game.data and reset_form.validate(): for unpick_word in game.words: unpick_word.is_picked = False + reset_form.reset_confirm.data = False + db.session.add(game) db.session.commit() @@ -165,6 +174,7 @@ def game(game_uuid): game_login=game_login, word_form=word_form, play_form=play_form, + reset_form=reset_form, game=game, word=word, words=words, diff --git a/fishbowl/fishbowl.db b/fishbowl/fishbowl.db deleted file mode 100644 index 7f34389..0000000 Binary files a/fishbowl/fishbowl.db and /dev/null differ diff --git a/fishbowl/templates/game.html b/fishbowl/templates/game.html index c916244..6f14694 100644 --- a/fishbowl/templates/game.html +++ b/fishbowl/templates/game.html @@ -6,12 +6,16 @@ {% if game.password is not none and not session['logged_in'][game.uuid] %} {{ render_form(game_login) }} {% else %} -

To share this game, just share the url to this page

+

To share this game, just share the url to this page

{% if word is not none %} -
Your word is: {{ word.text }}
+

Your word is: {{ word.text }}

{% endif %} -
Words remaining: {{ words|length }}
+

Words remaining: {{ words|length }}

{{ render_form(play_form) }} +

+

Put words back

+

Make all drawn words pickable again

+ {{ render_form(reset_form) }}

Add new word

{{ render_form(word_form) }} {% endif %}