# HG changeset patch # User Goffi # Date 1336682494 -7200 # Node ID 77029ecf98178bd09f5da49e7583e90d45b20c46 # Parent 8540825f85e0300241611035a5daacc56acebcb0 added auto-create support diff -r 8540825f85e0 -r 77029ecf9817 idavoll/backend.py --- a/idavoll/backend.py Thu May 17 00:31:36 2012 +0200 +++ b/idavoll/backend.py Thu May 10 22:41:34 2012 +0200 @@ -288,6 +288,8 @@ def getSubscriptions(self, entity): return self.storage.getSubscriptions(entity) + def supportsAutoCreate(self): + return True def supportsInstantNodes(self): return True @@ -536,6 +538,9 @@ self.backend.registerNotifier(self._notify) self.backend.registerPreDelete(self._preDelete) + if self.backend.supportsAutoCreate(): + self.features.append("auto-create") + if self.backend.supportsInstantNodes(): self.features.append("instant-nodes") @@ -625,11 +630,25 @@ def getConfigurationOptions(self): return self.backend.nodeOptions + def _publish_errb(self, failure, request): + if failure.type == error.NodeNotFound and self.backend.supportsAutoCreate(): + d = self.backend.createNode(request.nodeIdentifier, + request.sender) + d.addCallback(lambda ignore, + request: self.backend.publish(request.nodeIdentifier, + request.items, + request.sender), + request) + return d + + raise failure + def publish(self, request): d = self.backend.publish(request.nodeIdentifier, request.items, request.sender) + d.addErrback(self._publish_errb, request) return d.addErrback(self._mapErrors)