'Returns queryset containing all instances somehow connected to given
page. This includes permissions to page itself and permissions inherited
from higher pages.
NOTE: this returns just PagePermission instances, to get complete access
list merge return of this function with Global permissions.'

def for_page(self, page):

    page = page.get_draft_object()
    from cms.models import ACCESS_DESCENDANTS, ACCESS_CHILDREN, ACCESS_PAGE_AND_CHILDREN, ACCESS_PAGE_AND_DESCENDANTS, ACCESS_PAGE
    if ((page.depth is None) or (page.path is None) or (page.numchild is None)):
        raise ValueError('Cannot    use    unsaved    page    for    permission    lookup,    missing    MPTT    attributes.')
    paths = [page.path[0:pos] for pos in range(0, len(page.path), page.steplen)[1:]]
    parents = (Q(page__path__in=paths) & (Q(grant_on=ACCESS_DESCENDANTS) | Q(grant_on=ACCESS_PAGE_AND_DESCENDANTS)))
    direct_parents = (Q(page__pk=page.parent_id) & (Q(grant_on=ACCESS_CHILDREN) | Q(grant_on=ACCESS_PAGE_AND_CHILDREN)))
    page_qs = (Q(page=page) & ((Q(grant_on=ACCESS_PAGE_AND_DESCENDANTS) | Q(grant_on=ACCESS_PAGE_AND_CHILDREN)) | Q(grant_on=ACCESS_PAGE)))
    query = ((parents | direct_parents) | page_qs)
    return self.filter(query).order_by('page__depth')
