'Add and save slices to a dashboard'

@api
@has_access_api
@expose(u'/add_slices/<dashboard_id>/', methods=[u'POST'])
def add_slices(self, dashboard_id):

    data = json.loads(request.form.get(u'data'))
    session = db.session()
    Slice = models.Slice
    dash = session.query(models.Dashboard).filter_by(id=dashboard_id).first()
    check_ownership(dash, raise_if_false=True)
    new_slices = session.query(Slice).filter(Slice.id.in_(data[u'slice_ids']))
    dash.slices += new_slices
    session.merge(dash)
    session.commit()
    session.close()
    return u'SLICES    ADDED'
