Exemple #1
0
    def init_app(self, app):
        """
            Register the Jinja extension, load edits from 
            app.config['EDITS_PATH'] and register blueprints.

            :param app:
                Flask application instance
        """
        app.config.setdefault('EDITS_URL', '/edits')
        app.config.setdefault('EDITS_PREVIEW', True)
        app.config.setdefault('EDITS_SUMMERNOTE', False)

        if 'EDITS_PATH' not in app.config:
            raise Exception('EDITS_PATH not set in app configuration.')

        if os.path.isfile(app.config['EDITS_PATH']):
            with open(app.config['EDITS_PATH']) as f:
                _db = json.loads(f.read(), object_pairs_hook=OrderedDict)
        else:
            _db = OrderedDict()

        app.jinja_env.add_extension('flask.ext.edits.EditableExtension')
        app.jinja_env.edits = _db
        app.jinja_env.edits_preview = app.config['EDITS_PREVIEW']
        app.jinja_env.edits_cache = copy_cache(app.jinja_env.cache)

        if app.config['EDITS_PREVIEW']:
            app.jinja_env.cache = None

        app.register_blueprint(edits, url_prefix=app.config['EDITS_URL'])
Exemple #2
0
def preview():
    if request.form.get('state') == 'true':
        preview = True
        cache = None
    else:
        preview = False
        cache = copy_cache(current_app.jinja_env.edits_cache)

    current_app.jinja_env.edits_preview = preview
    current_app.jinja_env.cache = cache

    if current_app.jinja_env.cache:
        current_app.jinja_env.cache.clear()

    return ''
Exemple #3
0
def preview():
    if request.form.get('state') == 'true':
        preview = True
        cache = None
    else:
        preview = False
        cache = copy_cache(current_app.jinja_env.edits_cache)

    current_app.jinja_env.edits_preview = preview
    current_app.jinja_env.cache = cache

    if current_app.jinja_env.cache:
        current_app.jinja_env.cache.clear()

    return ''