'Helper for filter_permitted(), accepts one character per mode'

def _get_query_filter_permitted(user, mode='r', filter_trash=True):

    query = models.Q()
    if (not user.is_admin()):
        query = (models.Q(full_access=user) | models.Q(full_access__isnull=True))
        query = ((query | models.Q(full_access=user.default_group)) | models.Q(full_access__in=user.other_groups.all()))
        if ((mode == 'r') or (mode == 'x')):
            query = (query | models.Q(read_access=user))
            query = ((query | models.Q(read_access=user.default_group)) | models.Q(read_access__in=user.other_groups.all()))
    if filter_trash:
        query = (query & models.Q(trash=False))
    return query
