def init_admin(app): app.config['SECRET_KEY'] = '$\xa1<\xadB\xabNg\xa3q\x13\xf5\xfc+W' app.config['MONGODB_SETTINGS'] = {'DB': 'testdb'} from flask.ext import admin admin = admin.Admin(app, '后台管理') admin.add_view(Login(name="登录")) admin.add_view(RoleView(Role))
def make_app(): # Setup flask and settings app = flask.Flask(__name__) app.secret_key = 'taskpy123' app.config['TASKPY_BASE'] = os.path.expanduser(os.path.join('~', '.taskpy')) app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///%s' % os.path.join(app.config['TASKPY_BASE'], 'main.db') print "Base directory: %s" % app.config['TASKPY_BASE'] print "Database: %s" % app.config['SQLALCHEMY_DATABASE_URI'] # Make sure TASKPY_BASE exists if not os.path.exists(app.config['TASKPY_BASE']): os.mkdir(app.config['TASKPY_BASE']) # Init database db.init_app(app) db.app = app db.create_all() # Add views index_view = taskpy.views.JobsView(name="Jobs", endpoint="jobs", url='/') admin_app = admin.Admin(app, name='Taskpy', index_view=index_view, base_template='admin_base.html') admin_app.add_view(taskpy.views.TasksView(name="Tasks", endpoint="tasks")) # Static bootstrap files (required by flask-admin) admin_app.add_view(taskpy.views.AdminStatic(url='/_')) return app
def admin_init(app): from flask.ext import admin admin = admin.Admin(app, 'Unshred', index_view=BaseAdminIndexView()) admin.add_view(UserView(User)) admin.add_view(TagsView(Tags)) admin.add_view(ShredsView(Shreds)) admin.add_view(CustomShredsView(name='Custom Shreds')) admin.add_view(UsersView(name='Custom Users'))
def setup(): init_login() adm = admin.Admin(app, settings.SITE_TITLE + ' Admin', index_view=AdminIndexView()) adm.add_view(UserAdmin(User)) pass
def setup(): init_login() adm = admin.Admin(app, settings.SITE_TITLE + ' Admin', index_view=AdminIndexView()) adm.add_view(UserAdmin(User)) adm.add_view(PersonAdmin(Person)) adm.add_view(AdminModelView(InventoryGroup)) adm.add_view(InventoryItemAdmin(InventoryItem)) adm.add_view(InventoryLogAdmin(InventoryLog))
edit_template = 'edit.html' class UserAdmin(CustomView): column_searchable_list = ('name', ) column_filters = ('name', 'email') # Flask views @app.route('/') def index(): return '<a href="/admin/">Click me to get to Admin!</a>' # Create admin with custom base template admin = admin.Admin(app, 'Example: Layout', base_template='layout.html') # Add views admin.add_view(UserAdmin(User, db.session)) admin.add_view(CustomView(Page, db.session)) def build_sample_db(): """ Populate a small db with some example entries. """ db.drop_all() db.create_all() first_names = [
class MyAdminIndexView(admin.AdminIndexView): @expose('/') def index(self): if not login.current_user.is_authenticated(): return redirect(url_for('.login_view')) return super(MyAdminIndexView, self).index() @expose('/login/', methods=('GET', 'POST')) def login_view(self): form = LoginForm() if form.validate_on_submit(): login.login_user(DumbUser(1)) flash("Logged in successfully.", "success") return redirect(request.args.get("next") or url_for(".index")) return render_template("login.html", form=form) @expose('/logout/') def logout_view(self): login.logout_user() flash("Logged out successfully", "success") return redirect(url_for('index')) class MyModelView(sqla.ModelView): page_size = 500 def is_accessible(self): return not login.current_user.is_anonymous() admin = admin.Admin(app, index_view=MyAdminIndexView()) #admin.add_view(MyModelView(Registration, db.session)) admin.add_view(MyModelView(User, db.session))
rollback_versions.append((count, version[0])) form.version.choices = rollback_versions if form.validate_on_submit() and form.rollback.data: version = rollback_versions[form.version.data - 1][1] cdb.rollback_using_import_policy(version) flash('Rollback successfully processed', 'success') return redirect(url_for('rollbackview.index')) return self.render('rollback.html', form=form, versions=[]) # Create admin with custom base template homepage_view = AdminIndexView(name='Home', template='admin/index.html', url='/') admin = admin.Admin(app, name='Snapback', index_view=homepage_view, base_template='layout.html') # Add views admin.add_view(CredentialsView(name='Credentials')) admin.add_view( ScheduleSnapshot(name='Schedule Snapshot', endpoint='schedulesnapshot')) admin.add_view(SnapshotsAdmin(Snapshots, db.session, endpoint="snapshotsadmin")) admin.add_view(RollbackView(name='Version Rollback')) admin.add_view(StackedDiffs(name='Version Diffs')) admin.add_view(About(name='About')) admin.add_view(FileView(name='View')) admin.add_view(DiffView(name='View Diffs')) admin.add_view(Feedback(name='Feedback'))
"%Y_%m_%d_%H_%M") + ".csv" return send_file(buffer, attachment_filename=filename, as_attachment=True, mimetype='text/csv') # def is_accessible(self): # if login.current_user.is_authenticated(): # if login.current_user.is_activated: # return True # return False # Create admin admin = admin.Admin(app, 'ActivityInfo Reports', index_view=MyAdminIndexView(), base_template='my_master.html') # Add views admin.add_view(ReportView(Report)) admin.add_view(AdminView(User)) admin.add_view(CartoDBTableView(CartoDbTable)) # Add API api = MongoRest(app) class AttributeResource(Resource): document = Attribute
column_searchable_list = ("primary_term", ) column_filters = ('primary_term', ) def __init__(self, session, **kwargs): # You can pass name and other parameters if you want to super(SkillView, self).__init__(SkillPair, session, **kwargs) # Flask views @app.route('/') def index(): return '<a href="/admin/">Click me to get to Admin!</a>' # Create admin admin = admin.Admin(app, 'SkillCluster') # Add views admin.add_view(SkillView(db.session)) #admin.add_view(PercentagesView(db.session)) def build_db(): db.drop_all() db.create_all() skillKeywords = [ "AJAX", "AMQP", "Android", "Angular", "Ant", "ApacheMQ", "Artifactory", "ASP.NET", "Backbone", "Bootstrap", "C++", "C#", "Cassandra", "Chef", "CSS", "Crystal Reports", "Delphi", "DevOps", "Django", "Eclipse",
from flask import Flask from redis import Redis from flask.ext import admin from flask.ext.admin.contrib import rediscli # Create flask app app = Flask(__name__) # Flask views @app.route('/') def index(): return '<a href="/admin/">Click me to get to Admin!</a>' if __name__ == '__main__': # Create admin interface admin = admin.Admin(app, name="Example: Redis") admin.add_view(rediscli.RedisCli(Redis())) # Start app app.run(debug=True)
@admin.expose('/') def index(self): return self.render('anotheradmin.html') @admin.expose('/test/') def test(self): return self.render('test.html') # Create flask app app = Flask(__name__, template_folder='templates') app.debug = True # Flask views @app.route('/') def index(): return '<a href="/admin/">Click me to get to Admin!</a>' # Create admin interface admin = admin.Admin(name="Example: Simple Views") admin.add_view(MyAdminView(name="view1", category='Test')) admin.add_view(AnotherAdminView(name="view2", category='Test')) admin.init_app(app) if __name__ == '__main__': # Start app app.run()
class RebillView(ModelView): column_list = ('customer', 'pid', 'date', 'batched', 'affid', 'retrynum') column_filters = ['pid', 'batched', 'affid', 'retrynum', 'nmi_id'] column_searchable_list = ('pid', 'card', 'customer') #class AffiliateView(ModelView): # column_searchable_list = ('username', 'affid', 'displayname') #class SmtpserverView(ModelView): # column_filters = ['storeid', 'host', 'port', 'username', 'password', 'theme'] @app.route('/refund/') def refund(): return '<html><body><form method="POST" action="/do_refund/">Order<input type="text"' @app.route('/') def index(): return '<html><body>lol <a href="/admin/">h4x</a></body></html>' if __name__=='__main__': admin= admin.Admin(app, 'datDash') admin.add_view(OrderView(models.Order)) admin.add_view(CustomerView(models.Customer)) # admin.add_view(NMIAccountView(models.NMIAccount)) admin.add_view(RebillView(models.Rebill)) # admin.add_view(AffiliateView(models.Affiliate)) # admin.add_view(SmtpserverView(models.Smtpserver)) app.run(debug=True, port=4200, host='0.0.0.0')
class UserAdmin(CustomView): column_searchable_list = ('name', ) column_filters = ('name', 'email') # Flask views @app.route('/') def index(): return '<a href="/admin/">Click me to get to Admin!</a>' # Create admin with custom base template admin = admin.Admin(app, 'Example: Layout-BS3', base_template='layout.html', template_mode='bootstrap3') # Add views admin.add_view(UserAdmin(User, db.session)) admin.add_view(CustomView(Page, db.session)) def build_sample_db(): """ Populate a small db with some example entries. """ db.drop_all() db.create_all()
list_template = 'list.html' create_template = 'create.html' edit_template = 'edit.html' class UserAdmin(CustomView): column_searchable_list = ('name', ) column_filters = ('name', 'email') # Flask views @app.route('/') def index(): return '<a href="/admin/">Click me to get to Admin!</a>' if __name__ == '__main__': # Create admin with custom base template admin = admin.Admin(app, base_template='layout.html') # Add views admin.add_view(UserAdmin(User, db.session)) admin.add_view(CustomView(Page, db.session)) # Create DB db.create_all() # Start app app.debug = True app.run('0.0.0.0', 8000)
return redirect(url_for('.index')) def create_data(): """ A helper function to create our tables.""" db.create_all() admin_user = User(os.environ['EGM_USER'], os.environ['EGM_PASS']) db.session.add(admin_user) db.session.commit() # Initialize flask-login init_login() # Create admin interface admin = admin.Admin(name="Create or edit content:", index_view=MyAdminIndexView(), base_template='admin_master.html') admin.add_view(BlogAdmin(Blog, db.session)) admin.add_view(BiographyAdmin(Biography, db.session)) admin.add_view(EventAdmin(Event, db.session)) admin.add_view(WorkAdmin(Work, db.session)) admin.add_view(UserAdmin(User, db.session)) admin.init_app(app) if __name__ == '__main__': if '-c' in sys.argv: create_data() else: # Start app app.run()
#if helpers.validate_form_on_submit(form): if request.method == 'POST' and form.validate(): user = form.get_user() login.login_user(user) return redirect(url_for('index')) return render_template('form.html', form=form) @app.route('/logout/') def logout_view(): login.logout_user() return redirect(url_for('index')) if __name__ == '__main__': read_env() allowed = User(os.environ['USERNAME'], os.environ['PASSWORD'], 1 ) init_login() # Create admin admin = admin.Admin(app, 'Kon*Fab Admin') # Add views admin.add_view(MediaView(db.media, 'Media Outlets', endpoint='media')) admin.add_view(CitiesView(db.cities, 'Cities', endpoint='cities')) # Start app app.run(host='0.0.0.0', port=8888, debug=True)
def __unicode__(self): return self.name def __name__(self): return u'角色管理' class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) email = db.Column(db.String(255), unique=True) password = db.Column(db.String(255)) active = db.Column(db.Boolean()) #confirmed_at = db.Column(db.DateTime()) roles = db.relationship('Role', secondary=roles_users, backref=db.backref('users', lazy='dynamic')) # Required for administrative interface. For python 3 please use __str__ instead. def __unicode__(self): return self.email def __name__(self): return u'用户管理' user_datastore = SQLAlchemyUserDatastore(db, User, Role) security = Security() # Create admin admin = admin.Admin(name=u'权限管理', template_mode='bootstrap3')
return self._feed_user_choices(form) def edit_form(self, obj): form = super(TweetView, self).edit_form(obj) return self._feed_user_choices(form) # Correct user_id reference before saving def on_model_change(self, form, model): user_id = model.get('user_id') model['user_id'] = ObjectId(user_id) return model # Flask views @app.route('/') def index(): return '<a href="/admin/">Click me to get to Admin!</a>' if __name__ == '__main__': # Create admin admin = admin.Admin(app, name='Example: PyMongo') # Add views admin.add_view(UserView(db.user, 'User')) admin.add_view(TweetView(db.tweet, 'Tweets')) # Start app app.run(debug=True)
return redirect(url_for('index')) @app.route('/posts/') def posts_view(): posts = Post.query.all() return render_template('posts.html', posts=posts, user=login.current_user) if __name__ == '__main__': # Initialize flask-login init_login() # Create admin admin = admin.Admin(app, 'Secret keeper admin panel', index_view=KeeperAdminIndexView()) admin.add_view(PostModelView(Post, db.session, url='posts')) admin.add_view(ModelView(Tag, db.session, url='tags')) admin.add_view(UserModelView(User, db.session, url='users')) # Create DB db.create_all() manager = APIManager(app, flask_sqlalchemy_db=db) manager.create_api(User, methods=['GET', 'POST', 'DELETE']) manager.create_api(Post, methods=['GET', 'POST', 'DELETE']) manager.create_api(Tag, methods=['GET', 'POST', 'DELETE']) # Start app app.debug = True port = int(os.environ.get('PORT', 5000))
id = db.Column(db.Integer, primary_key=True, autoincrement=True) class CarAdmin(sqla.ModelView): column_display_pk = True form_columns = ['id', 'title', 'E_mail', 'Name', 'Surname', 'block'] column_searchable_list = ('title', ) class CarAdmin1(sqla.ModelView): @expose('/') def index(self): return self.render('ggga.html') admin = admin.Admin(app, name='Admin') admin.add_view(CarAdmin(Users, db.session)) admin.add_view(CarAdmin1(GoHome, db.session)) @app.route('/ShowRes_pass') def ShowRes_pass(): return render_template('ggg1.html') @app.route('/Res_pass', methods=['POST', 'GET']) def Res_pass(): try: global log log = request.values['projectFilepath9']
@admin.expose('/') def index(self): return self.render('anotheradmin.html') @admin.expose('/test/') def test(self): return self.render('test.html') # Create flask app app = Flask(__name__, template_folder='templates') app.debug = True # Flask views @app.route('/') def index(): return '<a href="/admin/">Click me to get to Admin!</a>' # Create admin interface admin = admin.Admin() admin.add_view(MyAdminView(category='Test')) admin.add_view(AnotherAdminView(category='Test')) admin.init_app(app) if __name__ == '__main__': # Start app app.run()
sdb.initialized = False return redirect(url_for('credentialsview.index')) return self.render('credentials.html', form=form, reset_form=reset_form, ipaddr=session.get('ipaddr'), username=session.get('username'), security=session.get('secure', 'False')) # Create admin with custom base template homepage_view = AdminIndexView(name='Home', template='admin/index.html', url='/') admin = admin.Admin(app, name='Search Tom View', index_view=homepage_view, base_template='layout.html') # Add views admin.add_view(CredentialsView(name='Credentials')) admin.add_view(About(name='About', endpoint='about')) admin.add_view(Feedback(name='Feedback')) admin.add_view(AciConnSearchView(name='Search')) # admin.add_view(ShowObjectView(name='Object View', endpoint='atk_object')) def build_flow_spec(terms): flow_spec = FlowSpec() protocol_filter = ProtocolFilter() flow_spec.protocol_filter = [protocol_filter]
tmp = u""" <p><a href="/admin/?lang=en">Click me to get to Admin! (English)</a></p> <p><a href="/admin/?lang=cs">Click me to get to Admin! (Czech)</a></p> <p><a href="/admin/?lang=de">Click me to get to Admin! (German)</a></p> <p><a href="/admin/?lang=es">Click me to get to Admin! (Spanish)</a></p> <p><a href="/admin/?lang=fa">Click me to get to Admin! (Farsi)</a></p> <p><a href="/admin/?lang=fr">Click me to get to Admin! (French)</a></p> <p><a href="/admin/?lang=pt">Click me to get to Admin! (Portuguese)</a></p> <p><a href="/admin/?lang=ru">Click me to get to Admin! (Russian)</a></p> <p><a href="/admin/?lang=zh_CN">Click me to get to Admin! (Chinese - Simplified)</a></p> <p><a href="/admin/?lang=zh_TW">Click me to get to Admin! (Chinese - Traditional)</a></p> """ return tmp if __name__ == '__main__': # Create admin admin = admin.Admin(app, 'Example: Babel') #admin.locale_selector(get_locale) # Add views admin.add_view(sqla.ModelView(User, db.session)) admin.add_view(sqla.ModelView(Post, db.session)) # Create DB db.create_all() # Start app app.run(debug=True)
def add_cosmos_admin(flask_app, session): adm = admin.Admin(flask_app, 'Flask Admin', base_template="admin_layout.html") for m in [Execution, Stage, Task, TaskFile]: adm.add_view(sqla.ModelView(m, session))
from blueprints.wiki.views import wiki from blueprints.projects.views import projects from blueprints.downloads.views import downloads from blueprints.downloads.models import Download neobug.register_blueprint(wiki, url_prefix='/wiki') neobug.register_blueprint(projects, url_prefix='/projects') neobug.register_blueprint(downloads, url_prefix='/downloads') def init_login(): login_manager = login.LoginManager() login_manager.init_app(neobug) @login_manager.user_loader def load_user(user_id): return User.objects.where("this.username=='" + user_id + "'")[0] init_login() admin = admin.Admin(neobug, 'neobug', index_view=MyAdminIndexView()) admin.add_view(UserView(User)) admin.add_view(ProjectView(Project)) admin.add_view(IssueView(Issue)) admin.add_view(OverviewView(Overview)) admin.add_view(DownloadView(Download)) if __name__ == "__main__": neobug.run()
login.logout_user() return redirect(url_for('.index')) # Flask views @app.route('/') def index(): return render_template('index.html') # Initialize flask-login init_login() # Create admin admin = admin.Admin(app, 'Example: Auth', index_view=MyAdminIndexView(), base_template='my_master.html') # Add view admin.add_view(MyModelView(User, db.session)) def build_sample_db(): """ Populate a small db with some example entries. """ import string import random db.drop_all()
# Create flask app app = Flask(__name__, template_folder='templates', static_folder='files') # Create dummy secrey key so we can use flash app.config['SECRET_KEY'] = '123456790' # Flask views @app.route('/') def index(): return '<a href="/admin/">Click me to get to Admin!</a>' if __name__ == '__main__': # Create directory path = op.join(op.dirname(__file__), 'files') try: os.mkdir(path) except OSError: pass # Create admin interface admin = admin.Admin(app) admin.add_view(fileadmin.FileAdmin(path, '/files/', name='Files')) # Start app app.debug = True app.run()
form_ajax_refs = { 'user': (User.username, User.email), 'tags': (Tag.name, ) } def __init__(self, session): # Just call parent class with predefined model. super(PostAdmin, self).__init__(Post, session) class TreeView(sqla.ModelView): inline_models = (Tree, ) if __name__ == '__main__': # Create admin admin = admin.Admin(app, 'Simple Models') # Add views admin.add_view(UserAdmin(User, db.session)) admin.add_view(sqla.ModelView(Tag, db.session)) admin.add_view(PostAdmin(db.session)) admin.add_view(TreeView(Tree, db.session)) # Create DB db.create_all() # Start app app.run(debug=True)
filters.FilterLike(UserDetail.website, 'Fixed Title', options=(('test1', 'Test 1'), ('test2', 'Test 2')))) form_args = dict(text=dict(label='Big Text', validators=[])) def __init__(self, session): super(UserDetailAdmin, self).__init__(UserDetail, session) def is_accessible(self): if current_user.get_role() == '0': return current_user.is_authenticated() # Create admin admin = admin.Admin(app, 'FlaskCamel Admin') # Add views to admin admin.add_view(UsersAdmin(db.session)) admin.add_view(UserDetailAdmin(db.session)) ########NEW FILE######## __FILENAME__ = views from datetime import datetime, date from itsdangerous import URLSafeSerializer from flask import render_template, url_for, redirect, flash, request, session from flask.ext.login import (LoginManager, current_user, login_required, login_user, logout_user, AnonymousUser) from flask.ext.mail import Mail, Message