diff --git a/app/main/forms.py b/app/main/forms.py index cfb1e27..88b091d 100644 --- a/app/main/forms.py +++ b/app/main/forms.py @@ -22,6 +22,9 @@ class CreateGameForm(FlaskForm): def validate_end_time(self, end_time): self.date_time_validator(self.end_time_disabled, end_time) + if self.start_time.data and end_time.data: + if self.start_time.data > end_time.data: + raise ValidationError('Start Time must be before End Time.') def date_time_validator(self, disabled, date_time): print(1) diff --git a/app/main/routes.py b/app/main/routes.py index 9b746f7..bed26ce 100644 --- a/app/main/routes.py +++ b/app/main/routes.py @@ -12,7 +12,7 @@ from sqlalchemy import and_ from app import db from app.main import bp -from app.utils import generate_qr_code, serve_pil_image +from app.utils import generate_qr_code, serve_pil_image, flash_errors from app.models import User, Game, Role, GamePlayer, GameState, Objective, ObjectiveMinimalEncoder,\ LocationEncoder, PlayerCaughtPlayer, Review, Location from app.main.forms import CreateGameForm, ObjectiveForm, PlayerAddForm, UserCreateForm, \ @@ -48,6 +48,8 @@ def create_game(): db.session.commit() flash(f"'{game.name}' had been created!") return redirect(url_for('main.game_dashboard', game_name=game.name)) + else: + flash_errors(form) return render_template('create_game.html', title='Create Game', form=form) @bp.route('/game//change_settings', methods=['GET', 'POST']) @@ -85,6 +87,8 @@ def change_game_settings(game_name): db.session.commit() flash(f"'{game.name}' had been updated!") return redirect(url_for('main.game_dashboard', game_name=game.name)) + else: + flash_errors(form) return render_template('create_game.html', title='Chage Game Settings', form=form) @bp.route('/game//delete') diff --git a/app/templates/create_game.html b/app/templates/create_game.html index 65a2ab3..247c931 100644 --- a/app/templates/create_game.html +++ b/app/templates/create_game.html @@ -55,9 +55,7 @@ {% endblock %} diff --git a/app/utils.py b/app/utils.py index 3be0b79..5ca1dd7 100644 --- a/app/utils.py +++ b/app/utils.py @@ -1,6 +1,6 @@ from io import BytesIO import qrcode -from flask import send_file +from flask import send_file, flash def generate_qr_code(url): qr = qrcode.QRCode( @@ -19,3 +19,13 @@ def serve_pil_image(pil_img): pil_img.save(img_io, 'PNG', quality=70) img_io.seek(0) return send_file(img_io, mimetype='image/png') + +def flash_errors(form): + """Flashes form errors""" + print('a') + for field, errors in form.errors.items(): + for error in errors: + flash(u"Error in the %s field - %s" % ( + getattr(form, field).label.text, + error + ), 'error')