diff --git a/app/forms.py b/app/forms.py index c3b3d0d..b0d4c1b 100644 --- a/app/forms.py +++ b/app/forms.py @@ -1,5 +1,5 @@ from flask_wtf import FlaskForm -from wtforms import StringField, PasswordField, BooleanField, SubmitField, TextAreaField +from wtforms import StringField, PasswordField, BooleanField, SubmitField, TextAreaField, DateTimeField from wtforms.validators import DataRequired, EqualTo, ValidationError, Length from app.models import Player @@ -19,4 +19,9 @@ class RegistrationForm(FlaskForm): def validate_username(self, username): player = Player.query.filter_by(name=username.data).first() if player is not None: - raise ValidationError('Please use a different username.') \ No newline at end of file + raise ValidationError('Please use a different username.') + +class CreateGameForm(FlaskForm): + game_name = StringField('Game Name', validators=[DataRequired(), Length(min=0, max=64)]) + start_time = DateTimeField(id='datepick') + submit = SubmitField('Register') \ No newline at end of file diff --git a/app/routes.py b/app/routes.py index d0f0d9c..7ce20ec 100644 --- a/app/routes.py +++ b/app/routes.py @@ -2,7 +2,7 @@ from flask import render_template, flash, redirect, url_for, request from flask_login import login_user, logout_user, current_user, login_required from app import app, db from app.models import Player, Game -from app.forms import LoginForm, RegistrationForm +from app.forms import LoginForm, RegistrationForm, CreateGameForm @app.route('/', methods=['GET']) @app.route('/index', methods=['GET']) @@ -41,4 +41,13 @@ def register(): db.session.commit() flash('Congratulations, you are now a registered user!') return redirect(url_for('login')) - return render_template('register.html', title='Register', form=form) \ No newline at end of file + return render_template('register.html', title='Register', form=form) + +@login_required +@app.route('/create_game', methods=['GET', 'POST']) +def create_game(): + form = CreateGameForm() + if form.validate_on_submit(): + game = Game(name=form.game_name.data) + return render_template('create_game.html', title='Create Game!', form=form) + return render_template('create_game.html', title='Create Game', form=form) \ No newline at end of file diff --git a/app/templates/base.html b/app/templates/base.html index 828c8f6..fa7f1a2 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -19,6 +19,7 @@