def edit(id): """ Adds a new game to the database. """ game = controller.game(id) # Initialize with current data, if any form = EditGameForm(name=game.name, image_url=game.image_url, description=game.description, released=game.released, platforms=[p.id for p in game.platforms]) if request.method == 'POST' and form.validate_on_submit(): controller.edit_game(game=game, name=form.name.data, released=form.released.data, image_url=form.image_url.data, description=form.description.data, platforms=controller.map_platforms( form.platforms.data)) return redirect(url_for('details', id=id)) elif form.errors: flash_errors(form) return render_template('edit.html', user=current_user, title='Edit Game | Goodplays', game=game, form=form)
def delete(id): """ Deletes a game """ game = controller.game(id) controller.delete_game(game) return redirect(url_for('games'))
def update(id): """ Updates a game with data from Giant Bomb """ game = controller.game(id) controller.update_game(game) if not game: flash(f'Unable to update game with ID {id}.') return redirect(url_for('games')) return redirect(url_for('details', id=game.id))
def import_image(id): """ Import's a game's hotlinked cover image """ game = controller.game(id) if not game: flash(f'Unable to import image for game with ID {id}.') return redirect(url_for('games')) controller.import_image(game) return redirect(url_for('details', id=game.id))
def details(id): """ Displays a game's details page """ game = controller.game(id) if not game: flash(f"Unable to find game with ID {id}.") return redirect(url_for('index')) return render_template( 'details.html', title=f'{game.name} | Goodplays', user=current_user, game=game, add_form=AddPlayForm(), edit_form=EditPlayForm(), plays=controller.game_plays(current_user, game.id), can_edit=current_user.is_authenticated, can_delete=current_user.is_authenticated and not game.plays.count(), )