def create_view(): app, admin = setup() path = op.join(op.dirname(__file__), 'files') view = fileadmin.FileAdmin(path, '/files/', name='Files') admin.add_view(view) return app, admin, view
def configure_admin(app, admin): ADMIN = app.config.get('ADMIN', {'name': 'Quokka Admin', 'url': '/admin'}) for k, v in list(ADMIN.items()): setattr(admin, k, v) babel = app.extensions.get('babel') if babel: try: @babel.localeselector def get_locale(): override = request.args.get('lang') if override: session['lang'] = override return session.get('lang', 'en') admin.locale_selector(get_locale) except: pass # Exception: Can not add locale_selector second time. for entry in app.config.get('FILE_ADMIN', []): try: admin.add_view( fileadmin.FileAdmin(entry['path'], entry['url'], name=entry['name'], category=entry['category'], endpoint=entry['endpoint'])) except: pass # TODO: check blueprint endpoisnt colision if admin.app is None: admin.init_app(app) return admin
# 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()
db.session.delete(donor) db.session.commit() return json.dumps({'status': 'success'}) except Exception, e: logging.error(e) db.session.rollback() admin = Admin(app) admin.add_view(ModelView(Donor, db.session)) admin.add_view(ModelView(Trxns, db.session)) admin.add_view(ModelView(Surgery, db.session)) admin.add_view(fileadmin.FileAdmin(base_path + "/images", name="images")) class UserView(ModelView): def _list_thumbnail(view, context, model, name): if not model.pic_paths: return '' return Markup('<img src="%s">' % url_for( 'static', filename="images/" + form.thumbgen_filename(model.pic_paths))) column_formatters = {'pic_paths': _list_thumbnail} # Alternative way to contribute field is to override it completely. # In this case, Flask-Admin won't attempt to merge various parameters for the field.
return dict(general_meta_d=general_meta_d, general_meta_k=general_meta_k, menu=menu) admin.add_view(My_ModelView(Article, name=u"Сторінки")) admin.add_view(My_ModelView(Category, name=u"Розділи", endpoint='category_mgm')) admin.add_view(UsersView(User, name=u"Користувачі")) admin.add_view(SettingsView(name=u"Налаштування")) admin.add_view(GalleryView(name=u'Галерея')) admin.add_view( fileadmin.FileAdmin(UPLOAD_FOLDER, '/uploads/', name='File Manager')) app.debug = True SECRET_KEY = 'misha1987' # Flask Assets assets = Environment(app) js = Bundle('js/jquery-1.8.1.min.js', 'js/jquery.form.js', 'js/jquery.lightbox-0.5.min.js', 'js/admin/jquery.cookie.js', 'js/admin/tmpl.min.js', 'js/admin/load-image.min.js', 'js/admin/bootstrap.min.js', 'js/admin/bootstrap-image-gallery.min.js', 'js/admin/jquery-ui.custom.min.js',
app.config.from_object('config') db = SQLAlchemy(app) api = restful.Api(app) # flask-bcrypt flask_bcrypt = Bcrypt(app) # flask-httpauth auth = HTTPBasicAuth() @app.after_request def after_request(response): response.headers.add('Access-Control-Allow-Origin', '*') response.headers.add('Access-Control-Allow-Headers', 'Content-Type,Authorization') response.headers.add('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE') return response from app import views from app.models import User, Post admin = Admin(app) admin.add_view(ModelView(User, db.session)) admin.add_view(ModelView(Post, db.session)) admin.add_view( fileadmin.FileAdmin(app.config['FILE_PATH'], '/files/', name='Files'))