def delete_chart(report_id, chart_id): report = session.query(Report).filter_by(id=report_id).first() if not has_privileges(report): return abort(401) session.query(Chart).filter_by(id=chart_id, report=report_id).delete() report.modified = datetime.datetime.now() session.commit() return jsonify(data=None)
def report_view(report_id): form = LoginForm(session) report = session.query(Report).filter_by(id=report_id).first() author = session.query(User).filter_by(id=report.user).first() if report.public: return render_template('report_edit.html', form=form, user=current_user, report=report, author=author.user, edit=False) elif has_privileges(report): return redirect(url_for('report_edit', report_id=report_id)) else: return abort(404)
def chart_edit(report_id): report = session.query(Report).filter_by(id=report_id).first() if not has_privileges(report): return abort(401) form = LoginForm(session) return render_template('edit.html', form=form, user=current_user)
def remove_report(report_id): report = session.query(Report).filter_by(id=report_id, user=current_user.id).first() session.delete(report) session.commit() return redirect(url_for("profile"))
def get_endpoints(): available_endpoints = session.query(Endpoint).all() endpoints = [] for endpoint in available_endpoints: endpoints.append({'id': endpoint.id, 'url': endpoint.url }) return jsonify(endpoints=endpoints)
def make_private(report_id): report = session.query(Report).filter_by(id=report_id, user=current_user.id).first() if report is not None: report.public = False session.commit() return redirect(url_for("profile"))
def update_report(report_id): report = session.query(Report).filter_by(id=report_id).first() if not has_privileges(report): return abort(401) report.name = request.form['name'] session.commit() return jsonify(data=None)
def new_chart(report_id): report = session.query(Report).filter_by(id=report_id).first() if not has_privileges(report): return abort(401) chart = Chart('Default title') chart.id = -1 form = LoginForm(session) return render_template('edit.html', form=form, user=current_user, report=report, chart=chart, new=True)
def shorten(uri): long_prefix = get_long_prefix(uri) prefix = session.query(Prefix).filter_by(uri=long_prefix).first() if prefix is None: prefix = Prefix(get_long_prefix(uri)) session.add(prefix) session.commit() return uri.replace(prefix.uri, prefix.prefix + ':')
def chart_save(report_id, chart_id): report = session.query(Report).filter_by(id=report_id).first() if not has_privileges(report): return abort(401) if chart_id == 'new': name = request.form['name'] chart = Chart(name) report.charts.append(chart) else: chart = session.query(Chart).filter_by(id=chart_id).first() chart.json = request.form['chart'] report.modified = datetime.datetime.now() session.commit() report = session.query(Report).filter_by(id=chart.report).first() return redirect(url_for("report_edit", report_id=report.id))
def load_user(user_id): user = session.query(User).get(user_id) return user
def enlarge(uri): short_prefix = get_short_prefix(uri) prefix = session.query(Prefix).filter_by(prefix=short_prefix).first() return uri.replace(prefix.prefix +':', prefix.uri)