Example #1
0
def move_sl_block_into_slot(old_page, new_page, block, slot_name):
    page_configuration = IPageConfiguration(new_page)
    page_state = page_configuration.load()

    # initiate layout if it is in its initial state
    if slot_name == 'default' and page_state == page_configuration._default_page_config():

        # setup different layouts
        if ISimplelayoutTwoColumnView.providedBy(old_page):
            # two columns
            page_state[slot_name] = [
                {'cols': [ {'blocks': []}, {'blocks': []} ]}
            ]

        elif ISimplelayoutTwoColumnOneOnTopView.providedBy(old_page):
            # two columns and a top row
            page_state[slot_name] = [
                {'cols': [{'blocks': []}]},
                {'cols': [ {'blocks': []}, {'blocks': []} ]}
            ]

    if slot_name not in page_state:
        # normal single column layout
        page_state[slot_name] = [{'cols': [{'blocks': []}]}]

    if slot_name == 'default':
        slot = page_state['default']

        # two column layout
        if ISimplelayoutTwoColumnView.providedBy(old_page):
            if ISlotA.providedBy(block):  # left column
                slot[0]['cols'][0]['blocks'].append({'uid': IUUID(block)})
            elif ISlotB.providedBy(block):  # right column
                slot[0]['cols'][1]['blocks'].append({'uid': IUUID(block)})
            else:
                raise ValueError('Block has unused slot in layout.')

        # two columns and a top row layout
        elif ISimplelayoutTwoColumnOneOnTopView.providedBy(old_page):
            if ISlotA.providedBy(block):  # top row
                slot[0]['cols'][0]['blocks'].append({'uid': IUUID(block)})
            elif ISlotB.providedBy(block):  # bottom row, left column
                slot[1]['cols'][0]['blocks'].append({'uid': IUUID(block)})
            elif ISlotC.providedBy(block):  # bottom row, right column
                slot[1]['cols'][1]['blocks'].append({'uid': IUUID(block)})
            else:
                raise ValueError('Block has unused slot in layout.')

        else:
            slot[0]['cols'][0]['blocks'].append({'uid': IUUID(block)})

    else:
        page_state[slot_name][0]['cols'][0]['blocks'].append({
            'uid': IUUID(block)})

    page_configuration.store(page_state)
    def test_page_copy(self):
        noLongerProvides(self.paragraph, ISlotA)
        alsoProvides(self.paragraph, ISlotB)

        self.assertFalse(ISlotA.providedBy(self.paragraph))
        self.assertTrue(ISlotB.providedBy(self.paragraph))

        self.assertEqual(aq_parent(aq_inner(self.page)).getId(), 'testfolder')
        copied = self.folder.manage_copyObjects([self.page.getId()])
        self.subfolder.manage_pasteObjects(copied)

        page = self.subfolder.get('page1')
        paragraph = page.get('p1')
        self.assertEqual(aq_parent(aq_inner(page)).getId(), 'subfolder')

        # The paragraph should not be changed, since we move the page.
        self.assertFalse(ISlotA.providedBy(paragraph))
        self.assertTrue(ISlotB.providedBy(paragraph))
    def test_block_moving(self):
        alsoProvides(
            self.paragraph,
            [ISimpleLayoutBlock, ISlotB, ISlotD])

        alsoProvides(self.page2, ISimplelayoutView)

        notify(ObjectMovedEvent(
                self.paragraph,
                self.page, 'p1',
                self.page2, 'p2'))

        # old slot interfaces are no longer provided
        self.assertFalse(ISlotB.providedBy(self.paragraph))
        self.assertFalse(ISlotD.providedBy(self.paragraph))

        # current view config interfaces should be provided
        self.assertTrue(ISlotA.providedBy(self.paragraph))
        self.assertTrue(IOneColumn.providedBy(self.paragraph))