'Return a dictionary containing the counts of all contents in each state
keyed by the distinct states.
Note: does not include deleted/hidden contents.'

def state_counts(self, history):

    filters = [(sql.column('deleted') == false()), (sql.column('visible') == true())]
    contents_subquery = self._union_of_contents_query(history, filters=filters).subquery()
    statement = sql.select([sql.column('state'), func.count('*')]).select_from(contents_subquery).group_by(sql.column('state'))
    counts = self.app.model.context.execute(statement).fetchall()
    return dict(counts)
