Skip to content

Commit

Permalink
add adapter for ftw.simplelayout's block state.
Browse files Browse the repository at this point in the history
  • Loading branch information
jone committed Jul 29, 2015
1 parent 1de9889 commit 3f20280
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ftw/publisher/core/adapters/configure.zcml
Expand Up @@ -137,6 +137,11 @@
provides="ftw.publisher.core.interfaces.IDataCollector"
factory=".ftw_simplelayout.SimplelayoutPageAnnotations"
name="ftw.simplelayout:SimplelayoutPageAnnotations" />
<adapter
for="ftw.simplelayout.interfaces.ISimplelayoutBlock"
provides="ftw.publisher.core.interfaces.IDataCollector"
factory=".ftw_simplelayout.SimplelayoutBlockAnnotations"
name="ftw.simplelayout:SimplelayoutBlockAnnotations" />
</configure>

</configure>
17 changes: 17 additions & 0 deletions ftw/publisher/core/adapters/ftw_simplelayout.py
@@ -1,6 +1,7 @@
from AccessControl.SecurityInfo import ClassSecurityInformation
from ftw.publisher.core.interfaces import IDataCollector
from ftw.simplelayout.handlers import unwrap_persistence
from ftw.simplelayout.interfaces import IBlockConfiguration
from ftw.simplelayout.interfaces import IPageConfiguration
from zope.interface import implements

Expand All @@ -19,3 +20,19 @@ def getData(self):
security.declarePrivate('setData')
def setData(self, data, metadata):
IPageConfiguration(self.context).store(data)


class SimplelayoutBlockAnnotations(object):
implements(IDataCollector)
security = ClassSecurityInformation()

def __init__(self, context):
self.context = context

security.declarePrivate('getData')
def getData(self):
return unwrap_persistence(IBlockConfiguration(self.context).load())

security.declarePrivate('setData')
def setData(self, data, metadata):
IBlockConfiguration(self.context).store(data)
29 changes: 29 additions & 0 deletions ftw/publisher/core/tests/test_ftw_simplelayout_adapters.py
Expand Up @@ -3,6 +3,7 @@
from ftw.publisher.core.interfaces import IDataCollector
from ftw.publisher.core.testing import PUBLISHER_CORE_INTEGRATION_TESTING
from ftw.simplelayout.interfaces import IPageConfiguration
from ftw.simplelayout.interfaces import IBlockConfiguration
from plone.app.testing import setRoles
from plone.app.testing import TEST_USER_ID
from plone.uuid.interfaces import IUUID
Expand Down Expand Up @@ -73,3 +74,31 @@ def test_data_setter(self):
]},
]
}, IPageConfiguration(page).load())


class TestSimplelayoutBlockAnnotations(TestCase):
layer = PUBLISHER_CORE_INTEGRATION_TESTING

def setUp(self):
self.portal = self.layer['portal']
setRoles(self.portal, TEST_USER_ID, ['Manager'])

def test_data_getter(self):
page = create(Builder('sl content page').titled(u'The Page'))
block = create(Builder('sl textblock').titled(u'The Block').within(page))

IBlockConfiguration(block).store({'scale': 'sl_textblock_small'})

component = getAdapter(block, IDataCollector,
name='ftw.simplelayout:SimplelayoutBlockAnnotations')
self.assertEquals({'scale': 'sl_textblock_small'},
json.loads(json.dumps(component.getData())))

def test_data_setter(self):
page = create(Builder('sl content page').titled(u'The Page'))
block = create(Builder('sl textblock').titled(u'The Block').within(page))
component = getAdapter(block, IDataCollector,
name='ftw.simplelayout:SimplelayoutBlockAnnotations')
component.setData({'scale': 'sl_textblock_small'}, {})
self.assertEquals({'scale': 'sl_textblock_small'},
IBlockConfiguration(block).load())

0 comments on commit 3f20280

Please sign in to comment.