예제 #1
0
파일: core.py 프로젝트: fucc1/FPA_Core
def create_web_app(**config):
    app = create_app(**config)

    app.jinja_env.add_extension('pyjade.ext.jinja.PyJadeExtension')

    with app.app_context():

        from openspending.views import register_views
        register_views(app)

        from openspending.admin.routes import register_admin
        flaskadmin = admin.Admin(app, name='FIND Admin')
        #flaskadmin = Admin(app, url='/admin', name='admin2')
        register_admin(flaskadmin, db)

        from openspending.model import Dataset
        from openspending.model.country import Country
        whoosearch.whoosh_index(app, Dataset)
        whoosearch.whoosh_index(app, Country)

        from openspending.views.context import generate_csrf_token
        app.jinja_env.globals['csrf_token'] = generate_csrf_token

        from openspending.assets.assets import register_assets
        register_assets(assets)

    return app
예제 #2
0
def create_app():
    """
    Do initialization
    """

    hostname = utils.get_host_name()
    admin = flask_admin.Admin(app,
                              'Admin',
                              base_template='layout.html',
                              template_mode='bootstrap3')

    admin.add_view(AdminCustomView(settings.Settings))
    logging.info("Starting Shamash on %s", hostname)
    clusters = settings.get_all_clusters_settings()
    for cluster in clusters.iter():
        met = metrics.Metrics(cluster.Cluster)
        met.init_metrics()

    client = pubsub.get_pubsub_client()
    pubsub.create_topic(client, 'shamash-monitoring')
    pubsub.create_topic(client, 'shamash-scaling')
    pubsub.create_subscriptions(client, 'monitoring', 'shamash-monitoring')
    pubsub.create_subscriptions(client, 'scaling', 'shamash-scaling')
    pubsub.pull(client, 'monitoring',
                'https://shamash-dot-{}/get_monitoring_data'.format(hostname))
    pubsub.pull(client, 'scaling',
                "https://shamash-dot-{}/scale".format(hostname))
예제 #3
0
def create_application(run_mode=os.getenv('FLASK_ENV', 'production')):
    # Create application
    application = flask.Flask(__name__)
    application.config.from_object(config.CONFIGURATION[run_mode])

    # Do the call that sets up OIDC for the application.
    keycloak.Keycloak(application)

    # Create the connection to the database.
    models.db = flask_sqlalchemy.SQLAlchemy(application)

    # The root page - point the users to the admin interface.
    @application.route('/')
    def index():
        return '<a href="/admin/synonym/"/>Click me to get to Synonyms!</a>'

    admin = flask_admin.Admin(application,
                              name='Solr Configuration',
                              template_mode='bootstrap3')
    admin.add_view(synonym_view.SynonymView(synonym.Synonym,
                                            models.db.session))
    admin.add_view(
        synonym_audit_view.SynonymAuditView(synonym_audit.SynonymAudit,
                                            models.db.session))

    return application
예제 #4
0
def create_app(config_name):
    app = Flask(__name__)
    admin = flask_admin.Admin(
        app,
        'My Dashboard',
        base_template='my_master.html',
        template_mode='bootstrap3',
    )
    app.config.from_object(config_options[config_name])

    #initalize flask extensions
    bootstrap.init_app(app)
    db.init_app(app)
    login_manager.init_app(app)
    mail.init_app(app)

    
    # #config uploadset
    # configure_uploads(app, photos)

    #Registering bluprints
    from .main import main as main_blueprint
    app.register_blueprint(main_blueprint)
    from .auth import auth as auth_blueprint
    app.register_blueprint(auth_blueprint,url_prefix = '/authenticate')

    return app
예제 #5
0
파일: app.py 프로젝트: foosa/CovidOnCamp.us
def create_app(config_object="sarscov2_gatech_community_survey.settings"):
    """Create application factory, as explained here: http://flask.pocoo.org/docs/patterns/appfactories/.

    :param config_object: The configuration object to use.
    """
    app = Flask(__name__.split(".")[0])
    app.config.from_object(config_object)
    admin_app = admin.Admin(app,
                            index_view=MyAdminIndexView(),
                            template_mode='bootstrap3',
                            base_template='admin/index.html')
    admin_app.add_view(MyModelView(user.models.User, db.session))
    admin_app.add_view(MyModelView(user.models.Results, db.session))
    admin_app.add_view(MyModelView(user.models.Consent, db.session))
    admin_app.add_view(MyModelView(user.models.Role, db.session))
    admin_app.add_view(MyModelView(user.models.AuditLog, db.session))
    admin_app.add_view(MyModelView(user.models.UserInfo, db.session))
    admin_app.add_view(
        fileadmin.FileAdmin(app.config['UPLOAD_FOLDER'], name='Files'))
    register_extensions(app)
    register_blueprints(app)
    register_errorhandlers(app)
    register_shellcontext(app)
    register_commands(app)
    configure_logger(app)
    # bootstrap = Bootstrap(app)
    return app
예제 #6
0
def create_application(run_mode=os.getenv('FLASK_ENV', 'production')):
    # Create application
    application = flask.Flask(__name__)
    application.config.from_object(config.CONFIGURATION[run_mode])

    # Do the call that sets up OIDC for the application.
    keycloak.Keycloak(application)

    # Create the connection to the database.
    models.db = flask_sqlalchemy.SQLAlchemy(application)

    # The root page - point the users to the admin interface.
    @application.route('/')
    def index():
        return '<a href="/admin/synonym/"/>Login to administration.</a>'

    admin = flask_admin.Admin(application, name='Namex Administration', template_mode='bootstrap3')

    admin.add_view(synonym_view.SynonymView(synonym.Synonym, models.db.session))
    admin.add_view(virtual_word_condition_view.VirtualWordConditionView(virtual_word_condition.VirtualWordCondition, models.db.session, name='Restricted Word Condition'))
    admin.add_view(decision_reason_view.DecisionReasonView(decision_reason.DecisionReason, models.db.session))
    admin.add_view(word_classification_view.WordClassificationView(word_classification.WordClassification, models.db.session))

    admin.add_view(synonym_audit_view.SynonymAuditView(synonym_audit.SynonymAudit, models.db.session))
    admin.add_view(restricted_word_condition_audit_view.RestrictedConditionAuditView(restricted_condition_audit.RestrictedConditionAudit, models.db.session))
    admin.add_view(decision_reason_audit_view.DecisionReasonAuditView(decision_reason_audit.DecisionReasonAudit, models.db.session))

    return application, admin
예제 #7
0
def init_admin(app):
    flask_admin = admin.Admin(app, name=current_app.config['SITE_NAME'], url="/admin")
    flask_admin.add_view(StatementView(HostingStatement, db.session))
    flask_admin.add_view(StatementView(ApplicationTypeStatement, db.session))
    flask_admin.add_view(StatementView(VisibilityStatement, db.session))
    flask_admin.add_view(StatementView(AuthenticationStatement, db.session))
    flask_admin.add_view(ApplicationView(Application, db.session))
예제 #8
0
def init():
    """Create the administration system."""
    # Initialize flask-login
    init_login()

    # Create admin
    admin = flask_admin.Admin(app,
                              template_mode='bootstrap3'
                              '',
                              index_view=MyAdminIndexView(name='Accueil'),
                              base_template='admin/master.html')

    # Add view

    # Do we want the admin to editate this ?

    #admin.add_view(MyModelView(TrombiAdmin, db.session))
    admin.add_view(PersonView(Person, db.session, u'Ajout'))
    admin.add_view(MyModelView(Team, db.session, u'Services'))
    #admin.add_view(MyModelView(Infos, db.session, u'Informations'))
    #admin.add_view(MyModelView(Link, db.session, u'Actualités'))
    admin.add_view(AnalyticsView(name='Analytics', endpoint='analytics'))
    admin.add_view(WelcomeView(name='Welcome', endpoint='accueil'))
    admin.add_view(
        DatabaseSaveView(name='Base de données', endpoint='database'))
    admin.add_view(ChartsView(name='Organigramme', endpoint='charts'))
    admin.add_view(CommentsView(name='Messages', endpoint='comments'))

    # We create the database backup directory if it doesn't exists
    if (not isdir(config.DATABASE_SAVES_DIRECTORY)):
        mkdir(config.DATABASE_SAVES_DIRECTORY)
        print('Backup directory created at ' + config.DATABASE_SAVES_DIRECTORY)
예제 #9
0
def create_app(config_name):
    from .market import market as market_blueprint
    from .admin import admin_panel as admin_blueprint
    import flask_admin as admin

    app = Flask(__name__)
    app.config.from_object(config[config_name])
    app.register_blueprint(market_blueprint)
    app.register_blueprint(admin_blueprint)
    bootstrap.init_app(app)
    db.init_app(app)
    migrate.init_app(app, db)

    admin = admin.Admin(app, name='Example: Market', template_mode='bootstrap3')
    admin.add_view(UserAdmin(User, db.session))
    admin.add_view(CategoryAdmin(Category, db.session))
    admin.add_view(ColorsAdmin(Colors, db.session))
    admin.add_view(ObjectAdmin(Object, db.session))
    admin.add_view(ImageView(Image, db.session))
    admin.add_view(ParamAdmin(Param, db.session))
    admin.add_view(ObjectParamAdmin(ObjectParam, db.session))

    # admin = Admin(app, name='microblog', template_mode='bootstrap3')
    # admin.add_view(ModelView(User, models.session))
    return app
예제 #10
0
def setup_admin(app):
    adm = admin.Admin(app, name='Elogy')
    adm.add_view(LogbookAdmin(Logbook))
    adm.add_view(LogbookChangeAdmin(LogbookChange))
    adm.add_view(EntryAdmin(Entry))
    adm.add_view(EntryChangeAdmin(EntryChange))
    adm.add_view(EntryLockAdmin(EntryLock))
    adm.add_view(AttachmentAdmin(Attachment))
예제 #11
0
def register_extensions(app):
    """Register extensions with config vars defined."""
    AEAirtable.init_app(app)

    # Admin
    AEAdmin = flask_admin.Admin(app, 'AE Admin')
    AEAdmin.add_view(UserView(User))
    AEAdmin.add_view(LeadView(Lead))
예제 #12
0
def init_admin(app, db):
    admin = flask_admin.Admin(app, name='birthday')

    admin.add_view(UserAdmin(User, db.session))
    admin.add_view(AdminModelView(Role, db.session))
    admin.add_view(AdminModelView(Birthday, db.session))
    admin.add_view(AdminModelView(Payment, db.session))
    admin.add_view(AdminModelView(Deposit, db.session))
예제 #13
0
def create_app(config_name):
    app = Flask(__name__,
                template_folder='users/templates',
                static_folder='upload_files')
    app.config.from_object(config[config_name])
    config[config_name].init_app(app)

    bootstrap.init_app(app)
    mail.init_app(app)
    moment.init_app(app)
    db.init_app(app)
    login_manager.init_app(app)
    pagedown.init_app(app)

    # Setup Flask-Security
    user_datastore = SQLAlchemyUserDatastore(db, User, Role)
    security = Security(app, user_datastore)

    # from .app import app as main_blueprint
    # from .auth import auth as auth_blueprint
    # from .user import user as user_blueprint
    #
    # app.register_blueprint(main_blueprint)
    # app.register_blueprint(auth_blueprint, url_prefix='/auth')
    # app.register_blueprint(user_blueprint, url_prefix='/user')

    # Create admin
    admin = flask_admin.Admin(
        app,
        'Example: 黎光',
        base_template='my_master.html',
        template_mode='bootstrap3',
    )

    # Add model views
    admin.add_view(MyModelView(Role, db.session))
    admin.add_view(MyModelView(User, db.session))

    if not os.path.exists(path):
        try:
            os.mkdir(path)
        except OSError:
            pass

    admin.add_view(fileadmin.FileAdmin(path, '/upload_files/', name='Files'))

    # define a context processor for merging flask-admin's template context into the
    # flask-security views.
    @security.context_processor
    def security_context_processor():
        return dict(admin_base_template=admin.base_template,
                    admin_view=admin.index_view,
                    h=admin_helpers,
                    get_url=url_for)

    return app
예제 #14
0
def create_app(test_config=None):
    # create and configure the app
    app = Flask(__name__, instance_relative_config=True)

    if test_config is None:
        # load the instance config, if it exists, when not testing
        app.config.from_envvar('SETTINGS_PATH')
    else:
        # load the test config if passed in
        app.config.from_mapping(test_config)

    CORS(app, origins=["https://hugocohen.com", "http://localhost:8080"])
    configure_uploads(app, (images))
    patch_request_class(app)
    # initialize the database
    db.init_app(app)
    migrate.init_app(app, db)
    from .api.sync import bp as sync
    from .api.video import videoapi
    from .api.album import albumapi

    from .models.Admin import Administrator
    from .views.AdminView import AdminView
    from .models.Video import Video
    from .views.VideoView import VideoView
    from .models.Photos import Photo
    from .views.PhotoView import PhotoView
    from .models.Albums import Album
    from .views.AlbumView import AlbumView
    from .api.admin import MyAdminIndexView, aboutapi

    init_login(app)
    app.register_blueprint(sync)
    app.register_blueprint(videoapi)
    app.register_blueprint(albumapi)
    app.register_blueprint(aboutapi)
    a = admin.Admin(app,
                    name="hugoweb",
                    index_view=MyAdminIndexView(),
                    base_template='admin/my_master.html',
                    template_mode="bootstrap3")
    a.add_view(VideoView(Video, db.session))
    a.add_view(AdminView(Administrator, db.session))
    a.add_view(AlbumView(Album, db.session))
    a.add_view(PhotoView(Photo, db.session))

    # ensure the instance folder exists
    try:
        os.makedirs(app.instance_path)
    except OSError:
        pass

    # Init administrator if not present
    with app.app_context():
        #Administrator.init()
        return app
예제 #15
0
def run_admin():
    admin_panel = admin.Admin(name="Gene Calc - Admin Panel",
                              index_view=MyAdminIndexView(),
                              base_template='admin_overwrite/layout.html',
                              template_mode='bootstrap4')

    admin_panel.add_view(MyModelView(User, db.session))
    admin_panel.add_view(PageAdmin(Page, db.session))

    return admin_panel
예제 #16
0
def init(app):
    # Create admin
    admin = flask_admin.Admin(app,
                              'C4E-Portfolio',
                              index_view=AdminIndexView())

    # Add views
    admin.add_view(ModelView(Project))
    admin.add_view(UserView(User))
    admin.add_view(ModelView(Tag))
예제 #17
0
def register(app, db):
    # create admin
    admin_view = admin.Admin(app, name='eKonek', template_mode='bootstrap3')

    # add views
    admin_view.add_view(UserView(User, db.session))
    admin_view.add_view(BookingView(Booking, db.session))
    admin_view.add_view(BookingRequestView(BookingRequest, db.session))
    admin_view.add_view(FeedbackView(Feedback, db.session))
    admin_view.add_view(ServiceView(Service, db.session))
    admin_view.add_view(sqla.ModelView(ResetPassword, db.session))
예제 #18
0
def _intitialize_flask_admin(app, db):
    if not IS_PRODUCTION:
        admin = flask_admin.Admin(
            app,
            name=app.zen_config.general.DEPLOYMENT_FULL_NAME,
            template_mode='bootstrap3',
            url='/flask-admin',
        )
        # Add views
        admin.add_view(ZenysisModelView(IndicatorGroups, db.session))
        admin.add_view(ZenysisModelView(Indicators, db.session))
예제 #19
0
def create_app(object_name):
    """
    An flask application factory, as explained here:
    http://flask.pocoo.org/docs/patterns/appfactories/

    Arguments:
        object_name: the python path of the config object,
                     e.g. project.config.ProdConfig

    """
    from webapp1.models import db
    app = Flask(__name__)
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    app.config.from_object('webapp1.config.ProdConfig')
    #app.config.from_object('webapp.config.DevConfig')
    db.init_app(app)
    try:
        db.create_all()
    except Exception as e:
        print(e)
    bcrypt.init_app(app)
    oid.init_app(app)
    login_manager.init_app(app)
    principals.init_app(app)

    # db.create_all()
    rest_api.add_resource(ELDAPI, '/api/eld')
    rest_api.add_resource(AuthApi, '/api/auth')
    rest_api.add_resource(PostAPI, '/api/post')
    rest_api.init_app(app)

    #app.register_blueprint(account_blueprint)
    app.register_blueprint(drivers_blueprint)
    app.register_blueprint(dvir_blueprint)
    app.register_blueprint(logs_blueprint)
    app.register_blueprint(trucks_blueprint)
    app.register_blueprint(elogstation_blueprint)
    app.register_blueprint(webservices_blueprint)
    # Create admin
    import flask_admin as admin1

    admin = admin1.Admin(app,
                         'Example: Auth',
                         index_view=MyAdminIndexView(),
                         base_template='layout.html')
    # Add view
    admin.add_view(MyModelView(User, db.session))
    admin.add_view(MyModelView(Role, db.session))
    admin.add_view(MyModelView(Person, db.session))
    admin.add_view(MyModelView(companyuser, db.session))
    admin.add_view(MyModelView(company1, db.session))
    admin.add_view(MyModelView(RPM, db.session))

    return app
예제 #20
0
파일: admin.py 프로젝트: laranea/Ignite
    def init_app(self, app):
        self.dashboard = admin.Admin(
            name='appname',
            template_mode='bootstrap3',
            index_view=AdminHomeView(template='admin/index.html'))

        self.dashboard.add_view(UserView(User, db.session))
        # self.dashboard.add_view(TeamView(ModelProxy.teams.Team, db.session))
        # self.dashboard.add_view(TeamMemberView(ModelProxy.teams.TeamMember, db.session))

        self.dashboard.init_app(app)
        return self.dashboard
예제 #21
0
def setup_flask_admin(app, db):
    import flask_admin
    from flask_admin import AdminIndexView
    from flask_admin.contrib.sqla import ModelView
    from flask_login import current_user
    from flasquelistan import models
    from flasquelistan.views import auth

    class AdminLoginMixin:
        def is_accessible(self):
            if current_user.is_authenticated:
                return current_user.is_admin
            return False

        def inaccessible_callback(self, name, **kwargs):
            if current_user.is_authenticated:
                flask.flash("Du måste vara admin för att komma åt den sidan.",
                            'error')
                return flask.redirect(flask.url_for('strequelistan.index'))
            else:
                return auth.login_manager.unauthorized()

    class LoginIndexView(AdminLoginMixin, AdminIndexView):
        pass

    class LoginModelView(AdminLoginMixin, ModelView):
        pass

    admin = flask_admin.Admin(app,
                              name='Flasquelistan',
                              index_view=LoginIndexView(url='/flask-admin'))
    admin.add_view(LoginModelView(models.User, db.session, name='User'))
    admin.add_view(LoginModelView(models.Group, db.session, name='Group'))
    admin.add_view(LoginModelView(models.Quote, db.session, name='Quote'))
    admin.add_view(LoginModelView(models.Article, db.session, name='Article'))
    admin.add_view(
        LoginModelView(models.Transaction, db.session, name='Transaction'))
    admin.add_view(LoginModelView(models.Streque, db.session, name='Streque'))
    admin.add_view(
        LoginModelView(models.AdminTransaction,
                       db.session,
                       name='AdminTransaction'))
    admin.add_view(
        LoginModelView(models.ProfilePicture,
                       db.session,
                       name='ProfilePicture'))
    admin.add_view(
        LoginModelView(models.RegistrationRequest,
                       db.session,
                       name='RegistrationRequest'))

    return admin
예제 #22
0
def register_debug_extensions(app):
  from flask_debugtoolbar import DebugToolbarExtension
  toolbar = DebugToolbarExtension()
  toolbar.init_app(app)

  from flask_admin.contrib.mongoengine import ModelView
  import flask_admin as admin
  admin = admin.Admin(app, 'TimeTracker:Admin')

  # Add views
  from models import User, Role
  admin.add_view(ModelView(User))
  admin.add_view(ModelView(Role))
예제 #23
0
파일: server.py 프로젝트: xspurs/flaskblog
def create_flask_admin():
    import flask_admin

    admin_instance = flask_admin.Admin(app,
                                       name='博客管理后台',
                                       template_mode='bootstrap3',
                                       index_view=CustomizedAdminIndexView(),
                                       base_template='customized_master.html')
    admin_instance.add_view(UserView(User, name="用户管理"))
    admin_instance.add_view(ClassificationView(Classification, name="分类管理"))
    admin_instance.add_view(ArticleView(Article, name="文章管理"))
    admin_instance.add_view(CommentView(Comment, name="评论管理"))
    return admin_instance
예제 #24
0
def create_interface(app, security):
    user = flask_admin.Admin(app,
                             'Talky',
                             base_template='base_template.html',
                             template_mode='bootstrap3',
                             url='/secure/user',
                             endpoint='user',
                             index_view=UserHomeView(name='Talks',
                                                     url='/secure/user',
                                                     endpoint='home'))

    user.add_view(make_view(UserView, view=DBCategoryView))
    user.add_view(make_view(UserView, view=DBContactView))
    user.add_view(make_view(UserView, view=DBConferenceView))

    admin = flask_admin.Admin(app,
                              'Talky - Admin',
                              base_template='base_template.html',
                              template_mode='bootstrap3',
                              url='/secure/admin',
                              endpoint='admin')

    admin.add_view(make_view(AdminView, db=schema.Role))
    admin.add_view(make_view(AdminView, db=schema.Experiment))
    admin.add_view(make_view(AdminView, db=schema.User))
    admin.add_view(make_view(AdminView, view=DBContactView))
    admin.add_view(make_view(AdminView, view=DBCategoryView))
    admin.add_view(make_view(AdminView, view=DBConferenceView))
    admin.add_view(make_view(AdminView, view=DBTalkView))
    admin.add_view(make_view(AdminView, db=schema.Submission))
    admin.add_view(make_view(AdminView, db=schema.Comment))

    @security.context_processor
    def security_context_processor_user():
        return dict(admin_base_template=user.base_template,
                    admin_view=user.index_view,
                    h=admin_helpers,
                    get_url=url_for)
예제 #25
0
def create_app(test_config=None):
    """Create and configure an instance of the Flask application."""
    app = Flask(__name__)

    db_path = os.path.join(app.instance_path, 'example.sqlite')

    # which including build database obj
    database = SqliteDatabase(db_path)
    DATABASE_PROXY.initialize(database)
    false_alter_feedback_handler = FalseAlertPeeweeDbWriter(database)

    # actually we needn't set the db obj here, since we initialize proxy above
    app.config.from_mapping(
        DATABASE=database,
        FALSE_ALTER_FEEDBACK_HANDLER=false_alter_feedback_handler
    )

    # ensure the instance folder exists
    try:
        os.makedirs(app.instance_path)
    except OSError:
        pass

    # apply the blueprints to the app
    from monitor_reporter import album, bar_chart, line_feedback
    app.register_blueprint(album.bp)
    app.register_blueprint(bar_chart.bp)
    app.register_blueprint(line_feedback.bp)

    # register flask-admin for ImageInfo, BboxDetectionResult,
    # RegisteredAudience, FalseAlertFeedback
    # create table if not exist
    detection_models.ImageInfo.create_table()
    detection_models.BboxDetectionResult.create_table()
    feedback_models.RegisteredAudience.create_table()
    feedback_models.FalseAlertFeedback.create_table()

    # register admin
    admin = flask_admin.Admin(app, name='Example: Peewee')
    admin.add_view(ModelView(detection_models.ImageInfo))
    admin.add_view(ModelView(detection_models.BboxDetectionResult))
    admin.add_view(ModelView(feedback_models.RegisteredAudience))
    admin.add_view(ModelView(feedback_models.FalseAlertFeedback))

    return app
예제 #26
0
def init_app(app):
    admin = flask_admin.Admin(app=app,
                              name='ProxyPool Admin',
                              base_template="admin/master_base.html",
                              index_view=ProxyPoolAdminIndexView(),
                              template_mode='bootstrap3')
    admin.add_view(ProxyView(ProxyModel))
    admin.add_view(SettingView(SettingModel))
    # admin.add_view(ProxyPoolView(ProxyPoolModel))
    admin.add_view(FetcherView(FetcherModel))

    db = MongoEngine()
    db.init_app(app)

    user_datastore = MongoEngineUserDatastore(db, User, Role)
    init_security(user_datastore, app, admin)

    init_base_data(user_datastore, app)
예제 #27
0
def create_app(config={}):
    app = Flask(__name__)
    # Config.
    app.config.from_object('cheese.settings')
    app.config.update(config)
    CSRFProtect(app)
    if app.config['DEBUG']:
        app.testing = True  # For Flask-WTF
    # Blueprints.
    from cheese.views import bp as cheese_bp
    from cheese.filters import bp as filters_bp
    from cheese.functions import bp as functions_bp
    app.register_blueprint(cheese_bp)
    app.register_blueprint(filters_bp)
    app.register_blueprint(functions_bp)
    # Models.
    from cheese.models import db, migrate, user_manager, db_adapter
    db.init_app(app)
    migrate.init_app(app, db)
    user_manager.init_app(app, db_adapter)
    # Admin.
    from cheese.views import init_admin, CheeseAdminIndexView
    admin = flask_admin.Admin(app,
                              name='CHEESE database',
                              index_view=CheeseAdminIndexView(name='Summary'),
                              base_template='admin_master.html',
                              template_mode='bootstrap3')
    init_admin(admin)
    # Flask extensions.
    from cheese.views import mail, pages, s3
    mail.init_app(app)
    pages.init_app(app)
    mixer.init_app(app)
    s3.init_app(app)
    # Register signals.
    init_signals(app)
    # Add logging handlers.
    init_file_logging(app)
    init_mail_logging(app)
    app.logger.setLevel(logging.INFO)
    # Additional CLI commands.
    from cheese.commands import resetdb
    resetdb = app.cli.command('resetdb')(resetdb)
    return app
예제 #28
0
def create_app(object_name):
    """
    An flask application factory, as explained here:
    http://flask.pocoo.org/docs/patterns/appfactories/

    Arguments:
        object_name: the python path of the config object,
                     e.g. project.config.ProdConfig

    """
    from webapp.models import db
    app = Flask(__name__)
    app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://*****:*****@localhost:5432/test5'
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    app.config.from_object('webapp.config.ProdConfig')
    #app.config.from_object('webapp.config.DevConfig')
    db.init_app(app)
    try:
        db.create_all()
    except Exception as e:
        print(e)
    bcrypt.init_app(app)
    oid.init_app(app)
    login_manager.init_app(app)
    principals.init_app(app)
    # db.create_all()

    app.register_blueprint(account_blueprint)
    app.register_blueprint(drivers_blueprint)
    app.register_blueprint(dvir_blueprint)
    app.register_blueprint(logs_blueprint)
    app.register_blueprint(trucks_blueprint)
    app.register_blueprint(elogstation_blueprint)
    # Create admin
    import flask_admin as admin1

    admin = admin1.Admin(app, 'Example: Auth', index_view=MyAdminIndexView(), base_template='my_master.html')
    # Add view
    admin.add_view(MyModelView(User, db.session))
    admin.add_view(MyModelView(Person, db.session))
    admin.add_view(MyModelView(companyuser, db.session))
    admin.add_view(MyModelView(company1, db.session))
    admin.add_view(MyModelView(ELD, db.session))
    return app
예제 #29
0
    def _add_admin(self, app, **kwargs):
        """Add a Flask Admin interface to an application.

        :param flask.Flask app:
        :param session:
        :param kwargs:
        :rtype: flask_admin.Admin
        """
        import flask_admin
        from flask_admin.contrib.sqla import ModelView

        admin = flask_admin.Admin(app, **kwargs)

        class EnzymeView(ModelView):
            column_hide_backrefs = False
            column_list = ('expasy_id', 'description', 'parents')

        admin.add_view(EnzymeView(Enzyme, self.session))
        admin.add_view(ModelView(Prosite, self.session))
        admin.add_view(ModelView(Protein, self.session))

        return admin
예제 #30
0
def create_admin_console(app):
    # Admin Panel

    user_datastore = MongoEngineUserDatastore(db, models.User, models.Role)
    security = Security(app, user_datastore)

    admin_console = flask_admin.Admin(
        app,
        'Jumiabot System Dashboard',
        base_template='my_master.html',
        template_mode='bootstrap3',
    )

    admin_console.add_view(views.RolesView(models.Role))
    admin_console.add_view(views.UsersView(models.User))

    @security.context_processor
    def security_context_processor():
        return dict(admin_base_template=admin_console.base_template,
                    admin_view=admin_console.index_view,
                    h=admin_helpers,
                    get_url=url_for)