Browse Source

fix create game game exists coding error, fix timepicker default value

testing
Burathar 4 years ago
parent
commit
733c80e371
  1. 8
      app/main/routes.py
  2. 4
      app/templates/create_game.html

8
app/main/routes.py

@ -39,11 +39,13 @@ def create_game():
form.state.choices = [(state.value, state.name) for state in GameState] form.state.choices = [(state.value, state.name) for state in GameState]
if form.validate_on_submit(): if form.validate_on_submit():
if Game.query.filter_by(name=form.game_name.data): if Game.query.filter_by(name=form.game_name.data).first():
flash('Please choose a different game name') flash('Please choose a different game name')
return render_template('create_game.html', title='Create Game', form=form) return render_template('create_game.html', title='Create Game', form=form)
game = Game(name=form.game_name.data, start_time=form.start_time.data, game = Game(name=form.game_name.data,
end_time=form.end_time.data, state=GameState(form.state.data)) start_time=form.start_time.data,
end_time=form.end_time.data,
state=GameState(form.state.data))
game.players.append(GamePlayer(user=current_user, role=Role['owner'])) game.players.append(GamePlayer(user=current_user, role=Role['owner']))
db.session.add(game) db.session.add(game)
db.session.commit() db.session.commit()

4
app/templates/create_game.html

@ -55,13 +55,13 @@
<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" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.47/js/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript"> <script type="text/javascript">
$(function () { $(function () {
'{% if form.start_time_enabled %}' '{% if not form.start_time_disabled.data %}'
var startDate = new Date() var startDate = new Date()
'{% else %}' '{% else %}'
var startDate = null var startDate = null
'{% endif %}' '{% endif %}'
'{% if form.end_time_enabled %}' '{% if not form.end_time_disabled.data %}'
var endDate = new Date() var endDate = new Date()
'{% else %}' '{% else %}'
var endDate = null var endDate = null

Loading…
Cancel
Save