'Copy a page [ and all its descendants to a new location ]
Doesn\'t checks for add page permissions anymore, this is done in PageAdmin.
Note for issue #1166: when copying pages there is no need to check for
conflicting URLs as pages are copied unpublished.'

def copy_page(self, target, site, position='first-child', copy_permissions=True):

    from cms.extensions import extension_pool
    from cms.models import Placeholder, Title
    if (not self.publisher_is_draft):
        raise PublicIsUnmodifiable('copy    page    is    not    allowed    for    public    pages')
    titles = Title.objects.all()
    placeholders = Placeholder.objects.all()
    pages = self.get_descendants(True).order_by('path').iterator()
    site_reverse_ids = Page.objects.filter(site=site, reverse_id__isnull=False).values_list('reverse_id', flat=True)
    pages_by_old_pk = {}
    def _do_copy(page, parent=None):
        origin_id = page.pk
        page.pk = None
        page.path = None
        page.depth = None
        page.numchild = 0
        page.publisher_public_id = None
        page.is_home = False
        page.site = site
        parent = (parent or pages_by_old_pk.get(page.parent_id))
        if parent:
            page.parent = parent
            page.parent_id = parent.pk
        else:
            page.parent = None
            page.parent_id = None
        if (page.reverse_id in site_reverse_ids):
            page.reverse_id = None
        page.save()
        for title in titles.filter(page=origin_id).iterator():
            title.pk = None
            title.page = page
            title.published = False
            title.slug = page_utils.get_available_slug(title)
            if title.publisher_public_id:
                title.publisher_public = None
            title.save()
        for ph in placeholders.filter(page=origin_id).iterator():
            plugins = ph.get_plugins_list()
            try:
                ph = page.placeholders.get(slot=ph.slot)
            except Placeholder.DoesNotExist:
                ph.pk = None
                ph.save()
                page.placeholders.add(ph)
            if plugins:
                copy_plugins_to(plugins, ph)
        if (get_cms_setting('PERMISSION') and copy_permissions):
            from cms.models.permissionmodels import PagePermission
            permissions = PagePermission.objects.filter(page__id=origin_id)
            for permission in permissions.iterator():
                permission.pk = None
                permission.page = page
                permission.save()
        extension_pool.copy_extensions(Page.objects.get(pk=origin_id), page)
        return page
    if (position in ('first-child', 'last-child')):
        parent = target
    elif target.parent_id:
        parent = target.parent
    else:
        parent = None
    old_page = next(pages)
    old_page_id = old_page.pk
    new_page = _do_copy(old_page, parent=parent)
    if target:
        new_page = new_page.move(target, pos=position)
    pages_by_old_pk[old_page_id] = new_page
    for child_page in pages:
        child_page_id = child_page.pk
        new_child_page = _do_copy(child_page)
        pages_by_old_pk[child_page_id] = new_child_page
    menu_pool.clear(site_id=site.pk)
    return new_page
