예제 #1
0
파일: base.py 프로젝트: lukas-lansky/sagenb
def create_app(path_to_notebook, *args, **kwds):
    """
    This is the main method to create a running notebook. This is
    called from the process spawned in run_notebook.py
    """
    global notebook
    startup_token = kwds.pop('startup_token', None)

    #############
    # OLD STUFF #
    #############
    import sagenb.notebook.notebook as notebook
    notebook.MATHJAX = True
    notebook = notebook.load_notebook(path_to_notebook, *args, **kwds)
    init_updates()

    ##############
    # Create app #
    ##############
    app = SageNBFlask('flask_server', startup_token=startup_token)
    app.secret_key = os.urandom(24)
    oid.init_app(app)
    app.debug = True

    @app.before_request
    def set_notebook_object():
        g.notebook = notebook

    ####################################
    # create Babel translation manager #
    ####################################
    babel = Babel(app, default_locale=notebook.conf()['default_language'],
                  default_timezone='UTC',
                  date_formats=None, configure_jinja=True)

    ########################
    # Register the modules #
    ########################
    app.register_blueprint(base)

    from worksheet_listing import worksheet_listing
    app.register_blueprint(worksheet_listing)

    from admin import admin
    app.register_blueprint(admin)

    from authentication import authentication
    app.register_blueprint(authentication)

    from doc import doc
    app.register_blueprint(doc)

    from worksheet import ws as worksheet
    app.register_blueprint(worksheet)

    from settings import settings
    app.register_blueprint(settings)

    #autoindex v0.3 doesnt seem to work with modules
    #routing with app directly does the trick
    #TODO: Check to see if autoindex 0.4 works with modules
    idx = AutoIndex(app, browse_root=SRC, add_url_rules=False)
    @app.route('/src/')
    @app.route('/src/<path:path>')
    @guest_or_login_required
    def autoindex(path='.'):
        filename = os.path.join(SRC, path)
        if os.path.isfile(filename):
            from cgi import escape
            src = escape(open(filename).read().decode('utf-8','ignore'))
            if (os.path.splitext(filename)[1] in
                ['.py','.c','.cc','.h','.hh','.pyx','.pxd']):
                return render_template(os.path.join('html', 'source_code.html'),
                                       src_filename=path,
                                       src=src, username = g.username)
            return src
        return idx.render_autoindex(path)

    return app
예제 #2
0
파일: base.py 프로젝트: sangkyunyoon/sagenb
 def check_default_lang():
     def_lang = notebook.conf()['default_language']
     trans_ids = [str(trans) for trans in babel.list_translations()]
     if def_lang not in trans_ids:
         notebook.conf()['default_language'] = None
예제 #3
0
def create_app(path_to_notebook, *args, **kwds):
    """
    This is the main method to create a running notebook. This is
    called from the process spawned in run_notebook.py
    """
    global notebook
    startup_token = kwds.pop('startup_token', None)

    #############
    # OLD STUFF #
    #############
    import sagenb.notebook.notebook as notebook
    notebook.MATHJAX = True
    notebook = notebook.load_notebook(path_to_notebook, *args, **kwds)
    init_updates()

    ##############
    # Create app #
    ##############
    app = SageNBFlask('flask_version', startup_token=startup_token)
    app.secret_key = os.urandom(24)
    oid.init_app(app)
    app.debug = True

    @app.before_request
    def set_notebook_object():
        g.notebook = notebook

    ####################################
    # create Babel translation manager #
    ####################################
    babel = Babel(app, default_locale=notebook.conf()['default_language'],
                  default_timezone='UTC',
                  date_formats=None, configure_jinja=True)

    ########################
    # Register the modules #
    ########################
    app.register_blueprint(base)

    from worksheet_listing import worksheet_listing
    app.register_blueprint(worksheet_listing)

    from admin import admin
    app.register_blueprint(admin)

    from authentication import authentication
    app.register_blueprint(authentication)

    from doc import doc
    app.register_blueprint(doc)

    from worksheet import ws as worksheet
    app.register_blueprint(worksheet)

    from settings import settings
    app.register_blueprint(settings)

    #autoindex v0.3 doesnt seem to work with modules
    #routing with app directly does the trick
    #TODO: Check to see if autoindex 0.4 works with modules
    idx = AutoIndex(app, browse_root=SRC, add_url_rules=False)
    @app.route('/src/')
    @app.route('/src/<path:path>')
    @guest_or_login_required
    def autoindex(path='.'):
        filename = os.path.join(SRC, path)
        if os.path.isfile(filename):
            from cgi import escape
            src = escape(open(filename).read().decode('utf-8','ignore'))
            if (os.path.splitext(filename)[1] in
                ['.py','.c','.cc','.h','.hh','.pyx','.pxd']):
                return render_template(os.path.join('html', 'source_code.html'),
                                       src_filename=path,
                                       src=src, username = g.username)
            return src
        return idx.render_autoindex(path)

    return app
예제 #4
0
파일: base.py 프로젝트: yanghaa/sagenb
 def check_default_lang():
     def_lang = notebook.conf()['default_language']
     trans_ids = [str(trans) for trans in babel.list_translations()]
     if def_lang not in trans_ids:
         notebook.conf()['default_language'] = None
예제 #5
0
파일: base.py 프로젝트: sagemath/sagenb
 def get_locale():
     return notebook.conf()['default_language']
예제 #6
0
def create_app(path_to_notebook, *args, **kwds):
    """
    This is the main method to create a running notebook. This is
    called from the process spawned in run_notebook.py
    """
    global notebook
    startup_token = kwds.pop('startup_token', None)

    #############
    # OLD STUFF #
    #############
    import sagenb.notebook.notebook as notebook
    notebook.MATHJAX = True
    notebook = notebook.load_notebook(path_to_notebook, *args, **kwds)
    init_updates()

    ##############
    # Create app #
    ##############
    app = SageNBFlask('flask_version', startup_token=startup_token)
    app.secret_key = os.urandom(24)
    oid.init_app(app)
    app.debug = True

    # connect to database
    database_path = os.path.join(path_to_notebook, 'chat_history.db')
    from sqlalchemy import create_engine
    from sqlalchemy.orm import sessionmaker
    engine = create_engine('sqlite:///'+database_path, convert_unicode=True)
    Session = sessionmaker(bind=engine)
    sess = Session()

    # initialize database if necessary
    from sqlalchemy.engine.reflection import Inspector
    inspector = Inspector.from_engine(engine)
    if "chatlog" not in inspector.get_table_names():
        import models
        models.init_db(engine)

    @app.before_request
    def set_notebook_object():
        g.notebook = notebook
        g.db = sess
        # ist leider nicht aussagekraeftig (immer True):
        g.pokal_debug_mode = current_app.debug

    ####################################
    # create Babel translation manager #
    ####################################
    babel = Babel(app, default_locale=notebook.conf()['default_language'],
                  default_timezone='UTC',
                  date_formats=None, configure_jinja=True)

    ########################
    # Register the modules #
    ########################
    app.register_blueprint(base)

    from worksheet_listing import worksheet_listing
    app.register_blueprint(worksheet_listing)

    from admin import admin
    app.register_blueprint(admin)

    from authentication import authentication
    app.register_blueprint(authentication)

    from doc import doc
    app.register_blueprint(doc)

    from worksheet import ws as worksheet
    app.register_blueprint(worksheet)

    from settings import settings
    app.register_blueprint(settings)

    #autoindex v0.3 doesnt seem to work with modules
    #routing with app directly does the trick
    #TODO: Check to see if autoindex 0.4 works with modules
    idx = AutoIndex(app, browse_root=SRC, add_url_rules=False)
    @app.route('/src/')
    @app.route('/src/<path:path>')
    @guest_or_login_required
    def autoindex(path='.'):
        filename = os.path.join(SRC, path)
        if os.path.isfile(filename):
            from cgi import escape
            src = escape(open(filename).read().decode('utf-8','ignore'))
            if (os.path.splitext(filename)[1] in
                ['.py','.c','.cc','.h','.hh','.pyx','.pxd']):
                return render_template(os.path.join('html', 'source_code.html'),
                                       src_filename=path,
                                       src=src, username = g.username)
            return src
        return idx.render_autoindex(path)

    return app
예제 #7
0
파일: base.py 프로젝트: timokau/sagenb
 def get_locale():
     return notebook.conf()['default_language']