def check_global(): """Allow overriding of the user by making it global. This also checks if the setting is enabled for the app, otherwise it will not allow it. Returns: dict: A dictionary with certain global flags overriden. """ global_enabled = setting('JSONDASH_GLOBALDASH') global_flag = request.form.get('is_global') is not None can_make_global = auth(authtype='edit_global') if all([global_flag, global_enabled, can_make_global]): return dict(created_by=setting('JSONDASH_GLOBAL_USER')) return dict()
def ctx(): """Inject any context needed for this blueprint.""" filter_user = setting('JSONDASH_FILTERUSERS') static = setting('JSONDASH').get('static') # Rewrite the static config paths to be local if the overrides are set. config = (settings.CHARTS_CONFIG if not static else local_static( settings.CHARTS_CONFIG, static)) return dict( static_config=static, charts_config=config, page_title='dashboards', docs_url=('https://github.com/christabor/flask_jsondash/' 'blob/master/docs/'), embeddable=request.args.get('embeddable', False), demo_mode=request.args.get('jsondash_demo_mode', False), global_dashuser=setting('JSONDASH_GLOBAL_USER'), global_dashboards=setting('JSONDASH_GLOBALDASH'), username=metadata(key='username') if filter_user else None, filter_dashboards=filter_user, )
def ctx(): """Inject any context needed for this blueprint.""" filter_user = setting('JSONDASH_FILTERUSERS') static = setting('JSONDASH').get('static') # Rewrite the static config paths to be local if the overrides are set. config = (settings.CHARTS_CONFIG if not static else local_static(settings.CHARTS_CONFIG, static)) return dict( static_config=static, charts_config=config, page_title='dashboards', docs_url=('https://github.com/christabor/flask_jsondash/' 'blob/master/docs/'), embeddable=request.args.get('embeddable', False), demo_mode=request.args.get('jsondash_demo_mode', False), global_dashuser=setting('JSONDASH_GLOBAL_USER'), global_dashboards=setting('JSONDASH_GLOBALDASH'), username=metadata(key='username') if filter_user else None, filter_dashboards=filter_user, )
def dashboard(): """Load all views.""" opts = dict() views = [] # Allow query parameter overrides. page = int(request.args.get('page', 0)) per_page = int(request.args.get('per_page', setting('JSONDASH_PERPAGE'))) if setting('JSONDASH_FILTERUSERS'): opts.update(filter=dict(created_by=metadata(key='username'))) views = list(adapter.read(**opts)) if setting('JSONDASH_GLOBALDASH'): opts.update(filter=dict( created_by=setting('JSONDASH_GLOBAL_USER'))) views += list(adapter.read(**opts)) else: views = list(adapter.read(**opts)) if views: pagination = utils.paginator(count=len(views), page=page, per_page=per_page) opts.update(limit=pagination.limit, skip=pagination.skip) views = views[pagination.skip:pagination.next] else: pagination = None categorized = utils.categorize_views(views) kwargs = dict( total=len(views), views=categorized, view=None, paginator=pagination, creating=True, can_edit_global=auth(authtype='edit_global'), total_modules=sum([ len(view.get('modules', [])) for view in views if isinstance(view, dict) ]), ) return render_template('pages/charts_index.html', **kwargs)
def dashboard(): """Load all views.""" opts = dict() views = [] # Allow query parameter overrides. page = int(request.args.get('page', 0)) per_page = int(request.args.get( 'per_page', setting('JSONDASH_PERPAGE'))) if setting('JSONDASH_FILTERUSERS'): opts.update(filter=dict(created_by=metadata(key='username'))) views = list(adapter.read(**opts)) if setting('JSONDASH_GLOBALDASH'): opts.update( filter=dict(created_by=setting('JSONDASH_GLOBAL_USER'))) views += list(adapter.read(**opts)) else: views = list(adapter.read(**opts)) if views: pagination = utils.paginator(count=len(views), page=page, per_page=per_page) opts.update(limit=pagination.limit, skip=pagination.skip) views = views[pagination.skip:pagination.next] else: pagination = None categorized = utils.categorize_views(views) kwargs = dict( total=len(views), views=categorized, view=None, paginator=pagination, creating=True, can_edit_global=auth(authtype='edit_global'), total_modules=sum([ len(view.get('modules', [])) for view in views if isinstance(view, dict) ]), ) return render_template('pages/charts_index.html', **kwargs)