def dashboard(): """Load all views.""" opts = dict() views = [] 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 = paginator(count=len(views)) opts.update(limit=pagination.limit, skip=pagination.skip) else: pagination = None kwargs = dict( views=views, view=None, paginator=pagination, can_edit_global=auth(authtype='edit_global'), total_modules=sum([len(view['modules']) for view in views]), ) return render_template('pages/charts_index.html', **kwargs)
def view(id): """Load a json view config from the DB.""" if auth_enabled(authtype='view'): if not auth_check('view', view_id=id): flash('You do not have access to view this dashboard.', 'error') return redirect(url_for('jsondash.dashboard')) viewjson = adapter.read(c_id=id) if not viewjson: flash('Could not find view: {}'.format(id), 'error') return redirect(url_for('jsondash.dashboard')) # Remove _id, it's not JSON serializeable. viewjson.pop('_id') # Chart family is encoded in chart type value for lookup. active_charts = [ v.get('family') for v in viewjson['modules'] if v.get('family') ] kwargs = dict(id=id, view=viewjson, active_charts=active_charts) return render_template('pages/chart_detail.html', **kwargs)
def clone(c_id): """Clone a json view config from the DB.""" if not auth(authtype='clone'): flash('You do not have access to clone dashboards.', 'error') return redirect(url_for('jsondash.dashboard')) viewjson = adapter.read(c_id=c_id) if not viewjson: flash('Could not find view: {}'.format(id), 'error') return redirect(url_for('jsondash.dashboard')) # Update some fields. data = dict( name='Clone of {}'.format(viewjson['name']), modules=viewjson['modules'], date=dt.now(), id=str(uuid.uuid1()), ) data.update(**metadata()) # Add to DB adapter.create(data=data) return redirect(url_for('jsondash.view', id=data['id']))