from flask import Flask from flask.ext.superadmin import Admin, BaseView, expose class MyView(BaseView): @expose('/') def index(self): return self.render('index.html') app = Flask(__name__) admin = Admin(app) admin.add_view(MyView(name='Hello 1', endpoint='test1', category='Test')) admin.add_view(MyView(name='Hello 2', endpoint='test2', category='Test')) admin.add_view(MyView(name='Hello 3', endpoint='test3', category='Test')) app.run()
def init_app(): init_login() admin = Admin(app) admin.add_view(AdminViews(name='Admin View'))
from database import make_db_utils # Database Connection _, db_session, _ = make_db_utils() # App configuration app = Flask(__name__, static_url_path='', static_folder='../static') app.config["SECRET_KEY"] = urandom(24) app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False app.config["SQLALCHEMY_DATABASE_URI"] = environ["SQLALCHEMY_DATABASE_URI"] app.add_url_rule("/", "root", lambda: app.send_static_file("index.html")) # API configuration api = MultiApi(app) api.add_resource(ReadingResource, "/api/reading/") api.add_resource(DeviceResource, "/api/dev/") # Admin and Security configuration admin = Admin(index_view=HomeView("Helmuth")) admin.register(Device, AuthModelView, session=db_session) admin.register(Reading, AuthModelView, session=db_session) admin.register(User, AuthModelView, session=db_session) admin.add_view(UploadView(name="upload")) admin.init_app(app) db = SQLAlchemy(app) user_datastore = SQLAlchemyUserDatastore(db, User, Role) security = Security(app, user_datastore) if __name__ == "__main__": app.run(host="0.0.0.0", port=8000, debug=True)
from flask import Flask from flask.ext.superadmin import Admin, BaseView, expose class MyView(BaseView): @expose('/') def index(self): return self.render('index.html') app = Flask(__name__) admin = Admin(app) admin.add_view(MyView(name='Hello')) app.run()
# # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. from flask.ext.superadmin import Admin, AdminIndexView from flask.ext.superadmin.model.backends.mongoengine import ModelAdmin from flask.ext.login import current_user from webapp import app from .models import User, DummyContent # Create customized model view class class MyModelView(ModelAdmin): def is_accessible(self): return current_user.is_authenticated() # Create customized index view class class MyAdminIndexView(AdminIndexView): def is_accessible(self): return current_user.is_authenticated() # Create admin admin = Admin(app, 'Backoffice', index_view=MyAdminIndexView()) # Add view admin.add_view(MyModelView(User)) admin.add_view(MyModelView(DummyContent))
@superadmin.expose('/') def index(self): return refresh_users() class UserAdmin(ModelAdmin): list_display = ('username',) search_fields = list_display class TagAdmin(ModelAdmin): list_display = ('name', 'value', ) search_fields = list_display if __name__ == "__main__": app.debug = True app.host = '0.0.0.0' app.secret_key = 'testytesttestxx' admin = Admin(app, 'AWS CC') # Add views admin.register(User, UserAdmin, session=db.session) admin.register(Tag, TagAdmin, session=db.session) admin.add_view(RefreshTags(category='Refresh from AWS')) admin.add_view(RefreshUsers(category='Refresh from AWS')) db.create_all() app.run()
from flask_bootstrap import Bootstrap import logging, sys from flask.ext.superadmin import Admin logging.basicConfig(stream=sys.stderr) tmpl_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'templates') app = Flask(__name__,template_folder=tmpl_dir) Bootstrap(app) from . import views from . import login from . import models from . import tasks from . import auth from . import forms from . import inject_trades from .database import db admin = Admin(app,index_view=models.MyAdminIndexView()) #admin.register(models.User, session=db.session) admin.register(models.Item, session=db.session) admin.register(models.Trade, session=db.session) admin.register(models.Factory, session=db.session) admin.register(models.Distributor, session=db.session) admin.register(models.ManufactureJob, session=db.session) admin.add_view(models.MyModelView(models.User, db.session)) celery = tasks.make_celery(app)
def init_app(app, messageService, locatorService): class BroadcastView(BaseView): @expose('/') def index(self): roles = Role.query.all() return self.render('broadcast.jade', roles=roles) @expose('/send', methods=['POST']) def send(self): role_id = request.form.get('role') message = request.form.get('message') if message is None or len(message) == 0: flash("You need to supply a message!") return redirect(url_for('.index')) if role_id is None: flash("You need to select which group to target!") return redirect(url_for('.index')) if role_id < 0: messageService.sendBroadcast(User.query.all(), message) else: role = Role.query.get(role_id) messageService.sendBroadcast(role.users, message) flash("Successfully sent message") return redirect(url_for('.index')) class LocateView(BaseView): @expose('/') def index(self): users = User.query.all() return self.render('locate.jade', users=users) @expose('/send', methods=['POST']) def send(self): sender = User.query.get(request.form.get('sender', 1)) target = User.query.get(request.form.get('target', 1)) locatorService.startLocating(target, sender) flash('Started locating') return redirect(url_for('.index')) @expose('/cheeseit') def cheeseit(self): testuser = Role.query.get(27) messageService.sendCheesit(testuser.users) flash('Delicious topping activated') return redirect(url_for('.index')) class DataView(BaseView): @expose('/') def index(self): users = User.query.all() return self.render('data.jade', users=users) @expose('/send', methods=['POST']) def send(self): target = User.query.get(request.form.get('sender', 1)) action = request.form.get('action') payload = request.form.get('payload') if action is None or len(action) == 0: flash("You need to supply an action!") return redirect(url_for('.index')) if payload is None or len(payload) == 0: flash("You need to supply a payload!") return redirect(url_for('.index')) messageService.sendData(target, payload, action) flash('Successfully sent data') return redirect(url_for('.index')) class UserView(model.ModelAdmin): session = db.session list_display = ('fullname', 'username', 'is_admin') class BeaconView(model.ModelAdmin): session = db.session list_display = ('location', 'uuid') class HashView(BaseView): @expose('/') def index(self): return self.render('hashview.jade') @expose('/send', methods=['POST']) def send(self): pw = request.form.get('password') hashpw = _hash(pw).hexdigest() flash(hashpw) return redirect(url_for('.index')) class AdminView(AdminIndexView): @expose('/') def index(self): return self.render('admin_index.jade') admin = Admin(name='LoKI', index_view=AdminView()) admin.register(Role, session=db.session) admin.register(User, UserView) admin.register(Device, session=db.session) admin.register(AccessToken, session=db.session) admin.register(LocatingRequest, session=db.session) admin.register(Beacon, BeaconView) admin.add_view(BroadcastView(name='Broadcast', category='Tools')) admin.add_view(LocateView(name='Locate', category='Tools')) admin.add_view(DataView(name='Data', category='Tools')) admin.add_view(HashView(name='Hash', category='Tools')) admin.init_app(app)
# Copyright 2013 Alexandre Bulté <alexandre[at]bulte[dot]net> # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. from flask.ext.superadmin import Admin, AdminIndexView from flask.ext.superadmin.model.backends.mongoengine import ModelAdmin from flask.ext.login import current_user from webapp import app from .models import User, DummyContent # Create customized model view class class MyModelView(ModelAdmin): def is_accessible(self): return current_user.is_authenticated() # Create customized index view class class MyAdminIndexView(AdminIndexView): def is_accessible(self): return current_user.is_authenticated() # Create admin admin = Admin(app, 'Backoffice', index_view=MyAdminIndexView()) # Add view admin.add_view(MyModelView(User)) admin.add_view(MyModelView(DummyContent))