'Recent activity (actions) for a given user'

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

    M = models
    qry = db.session.query(M.Log, M.Dashboard, M.Slice).outerjoin(M.Dashboard, (M.Dashboard.id == M.Log.dashboard_id)).outerjoin(M.Slice, (M.Slice.id == M.Log.slice_id)).filter(sqla.and_((~ M.Log.action.in_((u'queries', u'shortner', u'sql_json'))), (M.Log.user_id == user_id))).order_by(M.Log.dttm.desc()).limit(1000)
    payload = []
    for log in qry.all():
        item_url = None
        item_title = None
        if log.Dashboard:
            item_url = log.Dashboard.url
            item_title = log.Dashboard.dashboard_title
        elif log.Slice:
            item_url = log.Slice.slice_url
            item_title = log.Slice.slice_name
        payload.append({u'action': log.Log.action, u'item_url': item_url, u'item_title': item_title, u'time': log.Log.dttm})
    return json_success(json.dumps(payload, default=utils.json_int_dttm_ser))
