'Favorite slices for a user'

@api
@has_access_api
@expose(u'/fave_slices/<user_id>/', methods=[u'GET'])
def fave_slices(self, user_id):

    qry = db.session.query(models.Slice, models.FavStar.dttm).join(models.FavStar, sqla.and_((models.FavStar.user_id == int(user_id)), (models.FavStar.class_name == u'slice'), (models.Slice.id == models.FavStar.obj_id))).order_by(models.FavStar.dttm.desc())
    payload = []
    for o in qry.all():
        d = {u'id': o.Slice.id, u'title': o.Slice.slice_name, u'url': o.Slice.slice_url, u'dttm': o.dttm}
        if o.Slice.created_by:
            user = o.Slice.created_by
            d[u'creator'] = str(user)
            d[u'creator_url'] = u'/superset/profile/{}/'.format(user.username)
        payload.append(d)
    return json_success(json.dumps(payload, default=utils.json_int_dttm_ser))
