Beispiel #1
0
def game_detail_json(gid):
    game_d = GameService().find_by(gid, True)

    if not game_d:
        return jsonify({}), 404

    return jsonify(game_d.to_json())
Beispiel #2
0
def index():
    game_service = GameService()

    latest_games = latest(game_service)
    top10 = game_service.top10()

    return render_template('index.html', latest_games=latest_games,
                           top10=top10)
Beispiel #3
0
def update_game_form(gid):
    game_service = GameService()
    category_service = CategoryService()

    game_update = game_service.find_by(gid)

    if not game_update:
        flash('Game not found', 'warning')
        return redirect('/game')

    return render_template("game_form.html",
                           game=game_update,
                           target_url="/game/%d/update" % game_update.id,
                           categories=category_service.all())
Beispiel #4
0
def delete_game(gid):
    game_service = GameService()

    game_delete = game_service.find_by(gid)

    if not game_delete:
        flash('Game not found', 'warning')

    try:
        game_service.delete(game_delete)
        flash('Game removed', 'info')
    except Exception as exc:
        flash('Error deleting game: %s' % exc.message, 'danger')

    return redirect('/game')
Beispiel #5
0
def game_detail(gid):
    game_d = GameService().find_by(gid)

    if not game_d:
        flash("Game with id %d not found" % gid, "warning")
        return redirect("/game")

    return render_template("game.html", game=game_d)
Beispiel #6
0
    def increment_game_click(*args, **kwargs):
        """ Add 1 to game visualization and proceeds.  """
        try:
            GameService().increment(kwargs['gid'])
        except Exception as exc:
            print "Error counting page views: %s" % exc.message

        return func(*args, **kwargs)
Beispiel #7
0
def category_detail(cid):
    cat = CategoryService().find_by_id(cid)
    if not cat:
        flash('Category not found', 'warning')
        return redirect('/category')

    games = GameService().find_by_category(cat)

    return render_template("category.html", category=cat, games=games)
Beispiel #8
0
def game_new():
    v_game = validate_game()

    if v_game:
        if GameService().new(v_game):
            flash('New game added', 'success')
        else:
            flash('Error adding game', 'danger')

    return redirect('/game/new')
Beispiel #9
0
def platform_games(plat):
    """ Lists games by specified platform. """
    platform_results = GameService().find_by_platform(plat)

    if not platform_results['platform']:
        flash('Invalid platform provided', 'warning')
        return redirect('/game')

    return render_template('game_index.html',
                           games_scope=platform_results['platform'],
                           games=platform_results['games'])
Beispiel #10
0
def update_game(gid):
    updated_game = validate_game()

    if updated_game:
        updated_game.id = gid

        if GameService().new(updated_game):
            flash('Game updated', 'success')
            return redirect("/game/%d" % updated_game.id)
        else:
            flash('Error updating game', 'danger')

    return redirect('/game')
Beispiel #11
0
    def is_owner(model_type, **kwargs):

        if not SecurityService.is_authenticated():
            return False

        model = {}

        if model_type == Game:
            mid = kwargs['gid']
            model = GameService().find_by(mid, False)
        elif model_type == Category:
            mid = kwargs['cid']
            model = CategoryService().find_by_id(mid, False)
        else:
            return False

        return model.user_id == session['user']['id']
Beispiel #12
0
def game_json():
    return jsonify([g.to_short_json() for g in GameService().all()])
Beispiel #13
0
def game():
    return render_template("game_index.html",
                           games_scope="All Games",
                           games=GameService().all())
Beispiel #14
0
def top_json():
    return jsonify([t.to_short_json() for t in GameService().top10()])
Beispiel #15
0
def latest_json():
    return jsonify([l.to_short_json() for l in latest(GameService())])