Browse Source

add start of create_game

feature_tests
Burathar 4 years ago
parent
commit
276543ab3e
  1. 9
      app/forms.py
  2. 13
      app/routes.py
  3. 1
      app/templates/base.html
  4. 27
      app/templates/create_game.html
  5. 1
      app/templates/login.html

9
app/forms.py

@ -1,5 +1,5 @@
from flask_wtf import FlaskForm 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 wtforms.validators import DataRequired, EqualTo, ValidationError, Length
from app.models import Player from app.models import Player
@ -19,4 +19,9 @@ class RegistrationForm(FlaskForm):
def validate_username(self, username): def validate_username(self, username):
player = Player.query.filter_by(name=username.data).first() player = Player.query.filter_by(name=username.data).first()
if player is not None: if player is not None:
raise ValidationError('Please use a different username.') 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')

13
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 flask_login import login_user, logout_user, current_user, login_required
from app import app, db from app import app, db
from app.models import Player, Game 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('/', methods=['GET'])
@app.route('/index', methods=['GET']) @app.route('/index', methods=['GET'])
@ -41,4 +41,13 @@ def register():
db.session.commit() db.session.commit()
flash('Congratulations, you are now a registered user!') flash('Congratulations, you are now a registered user!')
return redirect(url_for('login')) return redirect(url_for('login'))
return render_template('register.html', title='Register', form=form) 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)

1
app/templates/base.html

@ -19,6 +19,7 @@
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav"> <ul class="nav navbar-nav">
<li><a href="{{ url_for('index') }}">Home</a></li> <li><a href="{{ url_for('index') }}">Home</a></li>
<li><a href="{{ url_for('create_game') }}">Create Game</a></li>
</ul> </ul>
<ul class="nav navbar-nav navbar-right"> <ul class="nav navbar-nav navbar-right">
{% if current_user.is_anonymous %} {% if current_user.is_anonymous %}

27
app/templates/create_game.html

@ -0,0 +1,27 @@
{% extends 'base.html' %}
{% import 'bootstrap/wtf.html' as wtf %}
{% block head %}
{{ super() }}
<link type="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.47/css/bootstrap-datetimepicker.min.css">
{% endblock %}
{% block app_content %}
<h1>Create a new game</h1>
<div class="row">
<div class="col-md-4">
{{ wtf.quick_form(form) }}
</div>
</div>
{% endblock %}
{% block scripts %}
{{ super() }}
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.47/js/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript">
$(function () {
$('#datepick').datetimepicker();
});
</script>
{% endblock %}

1
app/templates/login.html

@ -1,4 +1,3 @@
{% extends 'base.html' %} {% extends 'base.html' %}
{% import 'bootstrap/wtf.html' as wtf %} {% import 'bootstrap/wtf.html' as wtf %}

Loading…
Cancel
Save