def delete_chart(chart_id): """Delete the specified chart""" chart = Chart.query.get(chart_id) if chart is None: flash("Error: Chart not found!", "alert-warning") elif not current_user.is_admin and not chart.user.id == current_user.id: flash( "You don't have permission to delete that.", "alert-warning", ) else: # Before deleting the chart, check to see if any other users have # favorited this chart. If so, simply transfer ownership to them current_user.unfavorite_chart(chart) if chart.favorite_users: user = chart.favorite_users[0] chart.user = user db.session.commit() flash( "Chart ownership was transferred to {{ user.name }} since " "the chart was in that user's favorites list.", "alert-success", ) else: db.session.delete(chart) db.session.commit() flash("Chart deleted", "alert-success") return redirect(request.args.get('next') or url_for('reports.my_charts'))
def unfavorite_chart(chart_id): """Remove a chart from the user's favorite charts""" chart = Chart.query.get(chart_id) if chart is None: flash( "No chart with that chart_id found!", "alert-warning", ) else: current_user.unfavorite_chart(chart) db.session.commit() flash( "Removed Chart: {name} from favorites list".format(name=chart.name), "alert-success", ) return redirect(request.args.get('next') or url_for('reports.my_charts'))
def unfavorite_chart(chart_id): """Remove a chart from the user's favorite charts""" chart = Chart.query.get(chart_id) if chart is None: flash( "No chart with that chart_id found!", "alert-warning", ) else: current_user.unfavorite_chart(chart) db.session.commit() flash( "Removed Chart: {name} from favorites list".format( name=chart.name), "alert-success", ) return redirect(request.args.get('next') or url_for('reports.my_charts'))