def category_detail_json(cid): cat = CategoryService().find_by_id(cid, True) if not cat: return jsonify({}), 404 return jsonify(cat.to_json())
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")
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')
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())
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)
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."
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)
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')
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')
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']
def category_json(): return jsonify([c.to_short_json() for c in CategoryService().all()])
def category(): categories = CategoryService().all() return render_template("category_index.html", categories=categories)