示例#1
0
def category_detail_json(cid):
    cat = CategoryService().find_by_id(cid, True)

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

    return jsonify(cat.to_json())
示例#2
0
def game_form():
    categories = CategoryService().all()

    if not categories.count():
        flash('Please, register at least one category.', 'info')
        return redirect("/category/new")

    return render_template("game_form.html",
                           categories=categories,
                           game=Game().reset(),
                           target_url="/game/new")
示例#3
0
def delete_category(cid):
    category_service = CategoryService()
    cat = category_service.find_by_id(cid)

    if not cat:
        flash('Category does not exists', 'warning')

    try:
        category_service.delete(cat)
        flash('Category removed', 'info')
    except Exception as exc:
        flash("Error deleting category: %s" % exc.message, 'danger')

    return redirect('/category')
示例#4
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())
示例#5
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)
示例#6
0
    def create_categories():
        """ Insert template categories when none is found. """

        category_service = CategoryService()
        if not category_service.all().count():
            print "Creating categories..."
            cat_file = open(os.getcwd() + '/catalog/resources/categories.csv',
                            'r')
            for line in cat_file:
                if line.startswith("#"):
                    continue
                category_line = line.split('\t')
                category = Category(name=category_line[0],
                                    description=category_line[1])
                category_service.new(category)
        else:
            print "Category table already populated."

        print "Done."
示例#7
0
def update_category_form(cid):
    cat = CategoryService().find_by_id(cid)

    if not cat:
        flash('Category does not exists')
        return redirect('/category')

    return render_template("category_form.html",
                           category=cat,
                           target_url="/category/%d/update" % cat.id)
示例#8
0
def category_new():
    new_category = validate_category()

    if new_category:
        if CategoryService().new(new_category):
            flash('New category added', 'success')
        else:
            flash('Error adding category', 'danger')

    return redirect('/category')
示例#9
0
def update_category(cid):
    updated_category = validate_category()

    if updated_category:
        updated_category.id = cid

        if CategoryService().new(updated_category):
            flash('Category updated', 'success')
        else:
            flash('Error updating category', 'danger')

    return redirect('/category')
示例#10
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']
示例#11
0
def category_json():
    return jsonify([c.to_short_json() for c in CategoryService().all()])
示例#12
0
def category():
    categories = CategoryService().all()
    return render_template("category_index.html", categories=categories)