def test_ActionAdd(self): info = NodeInfo() info.title = 'Addable' info.addables = ['addable'] register_node_info('addable', info) action = ActionAdd() addmodel = BaseNode() request = self.layer.new_request() ActionContext(addmodel, request, 'listing') self.assertEqual(action(addmodel, request), u'') with self.layer.authenticated('viewer'): rule = request.has_permission('add', addmodel) self.assertTrue(isinstance(rule, ACLDenied)) self.assertEqual(action(addmodel, request), u'') with self.layer.authenticated('editor'): rule = request.has_permission('add', addmodel) self.assertTrue(isinstance(rule, ACLAllowed)) self.assertEqual(action(addmodel, request), u'') addmodel.node_info_name = 'addable' self.assertTrue(addmodel.nodeinfo is info) rendered = action(addmodel, request) self.checkOutput( """ ...<li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown"> <span>Add</span> <span class="caret"></span> </a> <ul class="dropdown-menu" role="addmenu"> <li> <a href="http://example.com/add?factory=addable" ajax:bind="click" ajax:target="http://example.com/?factory=addable" ajax:action="add:#content:inner" ajax:path="href"> <span class="glyphicon glyphicon-asterisk"></span> Addable </a> </li> </ul> </li>... """, rendered)
def test_NodeInfo(self): # The ``INodeInfo`` providing object holds information about the # application node nodeinfo = NodeInfo() nodeinfo.node = BaseNode nodeinfo.addables = ['basenode'] nodeinfo.title = 'Base Node' nodeinfo.description = 'Base Node Description' nodeinfo.factory = None nodeinfo.icon = 'base-node-icon' # check interface self.assertTrue(INodeInfo.providedBy(nodeinfo)) # check superclass self.assertTrue(isinstance(nodeinfo, Properties)) # Register node info register_node_info('basenode', nodeinfo) # Lookup Node info nodeinfo = get_node_info('basenode') self.assertTrue(nodeinfo.node is BaseNode) self.assertEqual(nodeinfo.addables, ['basenode']) self.assertEqual(nodeinfo.title, 'Base Node') self.assertEqual(nodeinfo.description, 'Base Node Description') self.assertEqual(nodeinfo.factory, None) self.assertEqual(nodeinfo.icon, 'base-node-icon') # ``__getattr__``. No AttributeError is raised if attribute missing self.assertTrue(nodeinfo.inexistent is None) # ``__getitem__`` self.assertEqual(nodeinfo['addables'], ['basenode']) # ``__contains__`` self.assertTrue('node' in nodeinfo) # ``get`` self.assertTrue(nodeinfo.get('node') is BaseNode)
logger.error(str(e)) return iter(list()) iterkeys = __iter__ @locktree def __getitem__(self, name): # XXX: temporary hack until paster/webob/pyramid handle urllib # quoted slashes in path components name = unquote_slash(name) try: return BaseNode.__getitem__(self, name) except KeyError: try: model = self.backend[name] except AttributeError: raise KeyError(name) user = User(model, name, self) self[name] = user return user info = NodeInfo() info.title = _('users_node', 'Users') info.description = _('users_node_description', 'Container for Users') info.node = Users info.addables = ['user'] info.icon = 'cone.ugm.static/images/users16_16.png' registerNodeInfo('users', info)
self[key] = revision return revision @locktree def __delitem__(self, key): todelete = self[key] if hasattr(self, '_todelete'): self._todelete.append(todelete) else: self._todelete = [todelete] AdapterNode.__delitem__(self, key) @locktree def __call__(self): if hasattr(self, '_todelete'): config = solr_config(self) for revision in self._todelete: unindex_doc(config, revision) del self.model[revision.__name__] del self._todelete self.model() self.metadata() info = NodeInfo() info.title = 'Media' info.description = 'A media object.' info.node = MediaAdapter info.addables = ['revision'] info.icon = 'mdb-static/images/media16_16.png' registerNodeInfo('media', info)
class User(AdapterNode): __metaclass__ = plumber __plumbing__ = LocalManagerUserACL node_info_name = 'user' @instance_property def properties(self): props = Properties() return props @instance_property def metadata(self): metadata = Metadata() metadata.title = _('user_node', 'User') metadata.description = _('user_node_description', 'User') return metadata @locktree def __call__(self): self.model() info = NodeInfo() info.title = _('user_node', 'User') info.description = _('user_node_description', 'User') info.node = User info.addables = [] registerNodeInfo('user', info)
props.in_navtree = True props.action_list = True props.action_add = True return props @property def metadata(self): md = BaseMetadata() md.title = "c3s App" return md info = NodeInfo() info.title = "C3SApp" info.description = "This is a c3s app" info.addables = ["band"] # info.icon = 'url/to/icon' info.node = C3SApp registerNodeInfo("c3sapp", info) class Band(BaseNode): __metaclass__ = plumber __plumbing__ = UUIDAttributeAware node_info_name = "band" @property def properties(self): props = Properties() props.in_navtree = True
props = Properties() props.in_navtree = True props.action_list = True props.action_add = True return props @property def metadata(self): md = BaseMetadata() md.title = 'c3s App' return md info = NodeInfo() info.title = 'C3SApp' info.description = 'This is a c3s app' info.addables = ['band'] #info.icon = 'url/to/icon' info.node = C3SApp registerNodeInfo('c3sapp', info) class Band(BaseNode): __metaclass__ = plumber __plumbing__ = UUIDAttributeAware node_info_name = 'band' @property def properties(self): props = Properties() props.in_navtree = True
todelete = self[key] if hasattr(self, '_todelete'): self._todelete.append(todelete) else: self._todelete = [todelete] AdapterNode.__delitem__(self, key) @locktree def __call__(self): if hasattr(self, '_todelete'): config = solr_config(self) for media in self._todelete: unindex_doc(config, media) for revision in media.values(): unindex_doc(config, revision) path = os.path.join(self.model.__name__, *media.model.mediapath + ['media.info']) os.remove(path) del self.model[media.__name__] del self._todelete self.model() self.metadata() info = NodeInfo() info.title = 'Repository' info.description = 'A repository.' info.node = RepositoryAdapter info.addables = ['media'] info.icon = 'mdb-static/images/repository16_16.png' registerNodeInfo('repository', info)
props = Properties() props.in_navtree = True props.action_list = True props.action_add = True return props @property def metadata(self): md = BaseMetadata() md.title = 'My App' return md info = NodeInfo() info.title = 'MyApp' info.description = 'This is my app' info.addables = ['band'] #info.icon = 'url/to/icon' info.node = MyApp registerNodeInfo('myapp', info) class Band(BaseNode): __metaclass__ = plumber __plumbing__ = UUIDAttributeAware node_info_name = 'band' @property def properties(self): props = Properties() props.in_navtree = True
@locktree def __delitem__(self, key): todelete = self[key] if hasattr(self, '_todelete'): self._todelete.append(todelete) else: self._todelete = [todelete] BaseNode.__delitem__(self, key) @locktree def __call__(self): if not hasattr(self, '_todelete'): return config = solr_config(self) for repository in self._todelete: for media in repository.values(): unindex_doc(config, media) for revision in media.values(): unindex_doc(config, revision) path = os.path.join(self.dbpath, repository.__name__) shutil.rmtree(path) del self._todelete info = NodeInfo() info.title = 'Repositories' info.description = 'Collection of repositories.' info.node = Repositories info.addables = ['repository'] info.icon = 'mdb-static/images/repositories16_16.png' registerNodeInfo('repositories', info)