def where_entry_visible(query, date=None):
    """ Generate a where clause for currently-visible entries

    Arguments:

    date -- The date to generate it relative to (defaults to right now)
    """

    return orm.select(
        e for e in query
        if e.status == model.PublishStatus.PUBLISHED.value or
        (e.status == model.PublishStatus.SCHEDULED.value and
         (e.utc_date <= (date or arrow.utcnow().datetime))
         )
    )