cms/apps/pages/utils.py
def duplicate_page(original_page, page_changes=None):
    '''
        Takes a page and duplicates it as a child of the original's parent page.
        Expects to be passed the original page and an optional function
    '''
    from .admin import page_admin
    original_content = original_page.content

    with update_index():
        page = deepcopy(original_page)
        page.pk = None

        if callable(page_changes):
            page = page_changes(page, original_page)

        page.save()

        content = deepcopy(original_content)
        content.pk = None
        content.page = page
        content.save()

        # This doesn't copy m2m relations on the copied inline
        for content_cls, admin_cls in page_admin.content_inlines:
            if not isinstance(content, content_cls):
                continue

            model_cls = admin_cls.model
            fk = _get_foreign_key(Page, model_cls, fk_name=admin_cls.fk_name)

            related_items = model_cls.objects.filter(**{fk.name: original_page.pk}).distinct().all()
            for item in related_items:
                new_object = deepcopy(item)
                new_object.pk = None
                setattr(new_object, fk.name, page)
                new_object = overlay_obj(new_object, item, exclude=[fk.name, 'pk', 'id'], commit=True)
                new_object.save()

    return page

        Takes a page and duplicates it as a child of the original's parent page.
        Expects to be passed the original page and an optional function
    
Takes a page and duplicates it as a child of the original's parent page.
Expects to be passed the original page and an optional function
Takes a page and duplicates it as a child of the original ' s parent page . Expects to be passed the original page and an optional function
def duplicate_page(original_page, page_changes=None):
    from .admin import page_admin
    original_content = original_page.content
    with update_index():
        page = deepcopy(original_page)
        page.pk = None
        if callable(page_changes):
            page = page_changes(page, original_page)
        page.save()
        content = deepcopy(original_content)
        content.pk = None
        content.page = page
        content.save()
        for content_cls, admin_cls in page_admin.content_inlines:
            if not isinstance(content, content_cls):
                continue
            model_cls = admin_cls.model
            fk = _get_foreign_key(Page, model_cls, fk_name=admin_cls.fk_name)
            related_items = model_cls.objects.filter(**{fk.name: original_page.pk}).distinct().all()
            for item in related_items:
                new_object = deepcopy(item)
                new_object.pk = None
                setattr(new_object, fk.name, page)
                new_object = overlay_obj(new_object, item, exclude=[fk.name, 'pk', 'id'], commit=True)
                new_object.save()
    return page
def duplicate_page ( original_page , page_changes = None ) : from . admin import page_admin original_content = original_page . content with update_index ( ) : page = deepcopy ( original_page ) page . pk = None if callable ( page_changes ) : page = page_changes ( page , original_page ) page . save ( ) content = deepcopy ( original_content ) content . pk = None content . page = page content . save ( ) for content_cls , admin_cls in page_admin . content_inlines : if not isinstance ( content , content_cls ) : continue model_cls = admin_cls . model fk = _get_foreign_key ( Page , model_cls , fk_name = admin_cls . fk_name ) related_items = model_cls . objects . filter ( ** { fk . name : original_page . pk } ) . distinct ( ) . all ( ) for item in related_items : new_object = deepcopy ( item ) new_object . pk = None setattr ( new_object , fk . name , page ) new_object = overlay_obj ( new_object , item , exclude = [ fk . name , 'pk' , 'id' ] , commit = True ) new_object . save ( ) return page
Takes a page and duplicates it as a child of the original's parent page.
Takes a page and duplicates it as a child of the original ' s parent page .
'''
        Takes a page and duplicates it as a child of the original's parent page.
        Expects to be passed the original page and an optional function
    ''' # This doesn't copy m2m relations on the copied inline
original_page
page_changes