Пример #1
0
 def form_heading(self):
     localizer = get_localizer(self.request)
     title = localizer.translate(
         get_node_info(self.model.node_info_name).title)
     heading = localizer.translate(
         _('add_form_heading',
           default='Add: ${title}',
           mapping={'title': title}))
     return heading
Пример #2
0
 def form_heading(self):
     localizer = get_localizer(self.request)
     title = localizer.translate(
         get_node_info(self.model.node_info_name).title)
     heading = localizer.translate(
         _('add_form_heading',
           default='Add: ${title}',
           mapping={'title': title}))
     return heading
Пример #3
0
 def form_heading(self):
     info = get_node_info(self.model.node_info_name)
     if info is None:
         return _('edit', default='Edit')
     localizer = get_localizer(self.request)
     heading = localizer.translate(
         _('edit_form_heading',
           default='Edit: ${title}',
           mapping={'title': localizer.translate(info.title)}))
     return heading
Пример #4
0
 def form_heading(self):
     info = get_node_info(self.model.node_info_name)
     if info is None:
         return _('edit', default='Edit')
     localizer = get_localizer(self.request)
     heading = localizer.translate(
         _('edit_form_heading',
           default='Edit: ${title}',
           mapping={'title': localizer.translate(info.title)}))
     return heading
Пример #5
0
 def items(self):
     ret = list()
     addables = self.model.nodeinfo.addables
     if not addables:
         return ret
     for addable in addables:
         info = get_node_info(addable)
         if not info:
             continue
         ret.append(self.make_item(addable, info))
     return ret
Пример #6
0
 def items(self):
     ret = list()
     addables = self.model.nodeinfo.addables
     if not addables:
         return ret
     for addable in addables:
         info = get_node_info(addable)
         if not info:
             continue
         ret.append(self.make_item(addable, info))
     return ret
Пример #7
0
    def test_node_info(self):
        @node_info(name='mynode',
                   title='My Node',
                   description='My Node Descriptrion',
                   factory=None,
                   icon='icon',
                   addables=['othernode'])
        class MyNode(BaseNode):
            pass

        info = get_node_info('mynode')
        self.assertTrue(info.node is MyNode)
        self.assertEqual(info.title, 'My Node')
        self.assertEqual(info.description, 'My Node Descriptrion')
        self.assertEqual(info.factory, None)
        self.assertEqual(info.addables, ['othernode'])
        self.assertEqual(info.icon, 'icon')
        self.assertEqual(MyNode.node_info_name, 'mynode')
Пример #8
0
    def test_node_info(self):
        @node_info(
            name='mynode',
            title='My Node',
            description='My Node Descriptrion',
            factory=None,
            icon='icon',
            addables=['othernode'])
        class MyNode(BaseNode):
            pass

        info = get_node_info('mynode')
        self.assertTrue(info.node is MyNode)
        self.assertEqual(info.title, 'My Node')
        self.assertEqual(info.description, 'My Node Descriptrion')
        self.assertEqual(info.factory, None)
        self.assertEqual(info.addables, ['othernode'])
        self.assertEqual(info.icon, 'icon')
        self.assertEqual(MyNode.node_info_name, 'mynode')
Пример #9
0
    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)
Пример #10
0
    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)
Пример #11
0
    def test_EditFormHeading(self):
        @plumbing(EditFormHeading)
        class EditForm(Form):
            pass

        self.assertEqual(BaseNode().node_info_name, '')
        self.assertEqual(get_node_info(''), None)

        edit_form = EditForm()
        edit_form.model = BaseNode()
        edit_form.request = self.layer.new_request()
        self.assertEqual(edit_form.form_heading, 'edit')

        @node_info(
            name='editnode',
            title='Edit Node')
        class EditNode(BaseNode):
            pass

        edit_form = EditForm()
        edit_form.model = EditNode()
        edit_form.request = self.layer.new_request()
        self.assertEqual(edit_form.form_heading, 'Edit: Edit Node')
Пример #12
0
 def info(self):
     factory = self.request.params.get('factory')
     allowed = self.model.nodeinfo.addables
     if not factory or not allowed or factory not in allowed:
         return None
     return get_node_info(factory)
Пример #13
0
    def test_add_items_dropdown(self):
        @node_info(
            name='mynode',
            addables=['mynode'])
        class MyNode(BaseNode):
            pass

        # Dummy model
        root = MyNode()
        root['somechild'] = MyNode()
        # child.attrs.title = 'My Node'

        # Dropdown menu containing links to the addforms of allowed child nodes
        with self.layer.authenticated('manager'):
            request = self.layer.new_request()
            rendered = render_tile(root['somechild'], request, 'add_dropdown')

        # Non JS link to add form
        expected = 'href="http://example.com/somechild/add?factory=mynode"'
        self.assertTrue(rendered.find(expected) != -1)

        # Ajax target for add form
        expected = 'ajax:target="http://example.com/somechild?factory=mynode"'
        self.assertTrue(rendered.find(expected) != -1)

        # Ajax action rule for add form
        expected = 'ajax:action="add:#content:inner"'
        self.assertTrue(rendered.find(expected) != -1)

        # Allow another node type as child
        nodeinfo = NodeInfo()
        register_node_info('anothernode', nodeinfo)
        get_node_info('mynode').addables = ['mynode', 'anothernode']

        with self.layer.authenticated('manager'):
            request = self.layer.new_request()
            rendered = render_tile(root['somechild'], request, 'add_dropdown')

        # Non JS links to add form
        expected = 'href="http://example.com/somechild/add?factory=mynode"'
        self.assertTrue(rendered.find(expected) != -1)

        expected = 'href="http://example.com/somechild/add?factory=anothernode"'
        self.assertTrue(rendered.find(expected) != -1)

        # Ajax targets for add form
        expected = 'ajax:target="http://example.com/somechild?factory=mynode"'
        self.assertTrue(rendered.find(expected) != -1)

        expected = 'ajax:target="http://example.com/somechild?factory=anothernode"'
        self.assertTrue(rendered.find(expected) != -1)

        # Test node without addables, results in empty listing.
        # XXX: hide entire widget if no items
        @node_info(name='nochildaddingnode')
        class NoChildAddingNode(BaseNode):
            pass

        with self.layer.authenticated('manager'):
            request = self.layer.new_request()
            rendered = render_tile(NoChildAddingNode(), request, 'add_dropdown')

        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">
        </ul>
        </li>...
        """, rendered)

        # Test node with invalid addable, results in empty listing
        # XXX: hide entire widget if no items
        @node_info(
            name='invalidchildnodeinfo',
            addables=['invalid'])
        class InvalidChildNodeInfoNode(BaseNode):
            pass

        with self.layer.authenticated('manager'):
            request = self.layer.new_request()
            rendered = render_tile(
                InvalidChildNodeInfoNode(),
                request,
                'add_dropdown'
            )
        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">
        </ul>
        </li>...
        """, rendered)
Пример #14
0
 def info(self):
     factory = self.request.params.get('factory')
     allowed = self.model.nodeinfo.addables
     if not factory or not allowed or factory not in allowed:
         return None
     return get_node_info(factory)