Skip to content

Commit

Permalink
Get rid of tile book-keeping. Nothing was using this, and it's an unn…
Browse files Browse the repository at this point in the history
…ecessary annotation write.

svn path=/plone.app.tiles/trunk/; revision=44802
  • Loading branch information
optilude committed Oct 31, 2010
1 parent 9ca97a4 commit e6df665
Show file tree
Hide file tree
Showing 10 changed files with 281 additions and 576 deletions.
11 changes: 0 additions & 11 deletions plone/app/tiles/browser/add.pt
Expand Up @@ -11,17 +11,6 @@

<form name="quickAdd" method="post" tal:attributes="action request/URL">

<div class="field" tal:condition="view/showId">
<label for="id" i18n:translate="label_tile_id">Tile id</label>
<div class="formHelp" i18n:translate="help_tile_id">
A unique identifier for the tile. Used to key tile data.
</div>
<div class="error"
tal:condition="view/errors/id | nothing"
tal:content="view/errors/id | nothing" />
<input type="text" name="id" id="id" tal:attributes="value request/id | nothing" />
</div>

<div class="field">
<label i18n:translate="label_tile_type">Tile type</label>

Expand Down
8 changes: 2 additions & 6 deletions plone/app/tiles/browser/edit.py
Expand Up @@ -74,8 +74,7 @@ def handleSave(self, action):
typeName = self.tileType.__name__

# Traverse to a new tile in the context, with no data
tile = self.context.restrictedTraverse('@@%s/%s' % (typeName,
self.tileId,))
tile = self.context.restrictedTraverse('@@%s/%s' % (typeName, self.tileId,))

dataManager = ITileDataManager(tile)
dataManager.set(data)
Expand All @@ -92,10 +91,7 @@ def handleSave(self, action):
notify(ObjectModifiedEvent(tile))

# Get the tile URL, possibly with encoded data
IStatusMessage(self.request).addStatusMessage(
_(u"Tile saved to ${url}", mapping={'url': tileURL}),
type=u'info',
)
IStatusMessage(self.request).addStatusMessage(_(u"Tile saved",), type=u'info')

# Calculate the edit URL and append some data in a JSON structure,
# to help the UI know what to do.
Expand Down
18 changes: 5 additions & 13 deletions plone/app/tiles/browser/traversal.py
@@ -1,15 +1,15 @@
from zope.interface import Interface, implements
from zope.component import queryMultiAdapter, queryUtility
from zope.component import queryMultiAdapter, getUtility, queryUtility
from zope.component import getAllUtilitiesRegisteredFor

from zope.security import checkPermission
from zope.publisher.interfaces import IPublishTraverse

from plone.memoize.view import memoize
from plone.uuid.interfaces import IUUIDGenerator

from plone.tiles.interfaces import ITileType

from plone.app.tiles.interfaces import ITileBookkeeping
from plone.app.tiles.interfaces import ITileAddView, ITileEditView

from plone.app.tiles import MessageFactory as _
Expand Down Expand Up @@ -113,26 +113,18 @@ def tileTypes(self):
types.sort(self.tileSortKey)
return types

@memoize
def showId(self):
return ITileBookkeeping(self.context, None) is None

def __call__(self):
self.errors = {}
self.request['disable_border'] = True

if 'form.button.Create' in self.request:
newTileType = self.request.get('type', None)
newTileId = self.request.get('id', None)
if newTileType is None:
self.errors['type'] = _(u"You must select the type of " + \
u"tile to create")

if newTileId is None:
bookkeeping = ITileBookkeeping(self.context, None)
if bookkeeping is not None:
# XXX: This is not very concurrency-safe, but oh well
newTileId = "tile-%d" % (bookkeeping.counter() + 1)

generator = getUtility(IUUIDGenerator)
newTileId = generator()

if newTileId is None:
self.errors['id'] = _(u"You must specify an id")
Expand Down
8 changes: 3 additions & 5 deletions plone/app/tiles/configure.zcml
Expand Up @@ -6,16 +6,14 @@
<include package="plone.tiles" />
<include package="plone.tiles" file="meta.zcml"/>

<include package="plone.uuid" />

<include package="plone.app.drafts" />
<include package="plone.app.z3cform" />

<!-- Views -->
<include package=".browser" />

<!-- Bookkeeping -->
<subscriber handler=".bookkeeping.recordTileAdded" />
<subscriber handler=".bookkeeping.recordTileRemoved" />
<adapter factory=".bookkeeping.AnnotationsTileBookkeeping" />

<!-- Drafting -->
<adapter factory=".drafting.draftingTileDataContext" />
<adapter factory=".drafting.TileDataDraftSyncer" name="plone.app.tiles.tiledata" />
Expand Down
13 changes: 3 additions & 10 deletions plone/app/tiles/drafting.py
Expand Up @@ -19,10 +19,6 @@
from plone.app.drafts.proxy import DraftProxy
from plone.app.drafts.utils import getCurrentDraft

from plone.app.tiles.bookkeeping import ANNOTATIONS_KEY
from plone.app.tiles.bookkeeping import COUNTER_KEY


@implementer(ITileDataContext)
@adapter(Interface, IDrafting, ITile)
def draftingTileDataContext(context, request, tile):
Expand Down Expand Up @@ -56,13 +52,10 @@ def __call__(self):
targetAnnotations = IAnnotations(self.target)

for key, value in draftAnnotations.iteritems():
if (key.startswith(ANNOTATIONS_KEY_PREFIX) or
key in (ANNOTATIONS_KEY, COUNTER_KEY)):
if key.startswith(ANNOTATIONS_KEY_PREFIX):
targetAnnotations[key] = value

annotationsDeleted = getattr(self.draft,
'_proxyAnnotationsDeleted', set())
annotationsDeleted = getattr(self.draft, '_proxyAnnotationsDeleted', set())
for key in annotationsDeleted:
if (key.startswith(ANNOTATIONS_KEY_PREFIX) or
key in (ANNOTATIONS_KEY, COUNTER_KEY)):
if key.startswith(ANNOTATIONS_KEY_PREFIX) and key in targetAnnotations:
del targetAnnotations[key]
37 changes: 0 additions & 37 deletions plone/app/tiles/interfaces.py
@@ -1,7 +1,5 @@
from zope.interface import Interface
from zope.publisher.interfaces.browser import IBrowserView


class ITileAddView(IBrowserView):
"""A tile add view as found by the @@add-tile traversal view.
Expand All @@ -18,38 +16,3 @@ class ITileEditView(IBrowserView):
this interface. Per-tile type overrides can be created by registering
named adapters matching the tile name.
"""


class ITileBookkeeping(Interface):
"""Tile bookkeeping information.
Adapt a content object to this interface to obtain information about tiles
associated with that content item. The default implementation stores this
information in annotations, and maintains it using event handlers for
``IObjectAddedEvent`` and ``IObjectRemovedEvent`` for ``ITile``.
"""

def added(tileType, tileId):
"""Record that a tile of the given type (a string) and id (also a
string) was added.
"""

def removed(tileType, tileId):
"""Record that a tile with the given id (a string) was removed.
"""

def typeOf(tileId):
"""Given a tile id, return its type (a strong), or None if the tile
cannot be found.
"""

def counter():
"""Get the number of tiles that have been added. Note that the counter
is *not* decremented even if tiles are removed.
"""

def enumerate(tileType=None):
"""Obtain an iterator for all tiles which have been recorded. The
iterator returns tuples of strings ``(tileId, tileType)``. If
``tileType`` is given, return only tiles of that type.
"""
1 change: 1 addition & 0 deletions plone/app/tiles/profiles/default/metadata.xml
@@ -1,6 +1,7 @@
<metadata>
<version>1</version>
<dependencies>
<dependency>profile-plone.app.tiles:default</dependency>
<dependency>profile-plone.app.drafts:default</dependency>
</dependencies>
</metadata>
51 changes: 51 additions & 0 deletions plone/app/tiles/testing.py
@@ -0,0 +1,51 @@
from zope.component import getUtility
from zope.component import provideUtility

from plone.app.testing import PloneSandboxLayer
from plone.app.testing import PLONE_FIXTURE
from plone.app.testing import IntegrationTesting
from plone.app.testing import FunctionalTesting
from plone.app.testing import applyProfile

from zope.configuration import xmlconfig

class PloneAppTiles(PloneSandboxLayer):

defaultBases = (PLONE_FIXTURE,)

def setUpZope(self, app, configurationContext):
# Load ZCML
import plone.app.tiles
xmlconfig.file('configure.zcml', plone.app.tiles, context=configurationContext)
xmlconfig.file('demo.zcml', plone.app.tiles, context=configurationContext)

def setUpPloneSite(self, portal):
applyProfile(portal, 'plone.app.tiles:default')

# Temporarily set up a more predictable UUID generator so that we can
# rely on the uuids in tests

def testSetUp(self):
from plone.uuid.interfaces import IUUIDGenerator

class FauxUUIDGenerator(object):

counter = 0

def __call__(self):
self.counter += 1
return 'tile-%d' % self.counter

self._uuidGenerator = getUtility(IUUIDGenerator)

provideUtility(FauxUUIDGenerator(), provides=IUUIDGenerator)

def testTearDown(self):
from plone.uuid.interfaces import IUUIDGenerator
provideUtility(self._uuidGenerator, provides=IUUIDGenerator)

PLONE_APP_TILES_FIXTURE = PloneAppTiles()
PLONE_APP_TILES_INTEGRATION_TESTING = \
IntegrationTesting(bases=(PLONE_APP_TILES_FIXTURE,), name="plone.app.tiles:Integration")
PLONE_APP_TILES_FUNCTIONAL_TESTING = \
FunctionalTesting(bases=(PLONE_APP_TILES_FIXTURE,), name="plone.app.tiles:Functional")

0 comments on commit e6df665

Please sign in to comment.