Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/kageurufu/flask-sandbox

A Flask plugin to restrict blueprints to specific users
https://github.com/kageurufu/flask-sandbox

Last synced: 11 days ago
JSON representation

A Flask plugin to restrict blueprints to specific users

Awesome Lists containing this project

README

        

flask-sandbox
=============

[![Build Status](https://travis-ci.org/kageurufu/flask-sandbox.png?branch=master)](https://travis-ci.org/kageurufu/flask-sandbox)

A Flask plugin to restrict blueprints to specific users, this depends on flask-login's current_user, so that is required

Goals of this extension are simple code, extendable code, and readability. So far, its only 31 lines of code

Usage
=====

from flask import Flask, Blueprint, redirect
from flask.ext.login import LoginManager
from flask.ext.sandbox import Sandbox

app = Flask(__name__)
login_manager = LoginManager(app)
sandbox = Sandbox(app)

@app.route("/protected/admin/page")
@sandbox(lambda user: user.admin)
def protected_admin_page():
return render_template("admin.jinja")

blueprint = Blueprint("admin", __name__)

@blueprint.route("/admin")
def admin():
return render_template("admin.jinja")

sandbox.register_blueprint(blueprint, lambda user: user.admin == True, redirect("/"))