示例#1
0
    def test_sidebar_modules(self):
        '''
        Tests for the sidebar module registration mechanism.

        The standard "ping" signal return value looks like this:

        tuple(<dash_apps_ping>, {
                'title': 'Nixon',
                'links': [{'url':'/syspanel/nixon/google',
                          'text':'Google', 'active_text': 'google'}],
                'type': 'syspanel',
            })
        '''
        self.mox.StubOutWithMock(signals, 'dash_modules_detect')
        signals_call = (
                (self._signal, {
                    'title': 'Nixon',
                    'links': [{'url':'/dash/nixon/google',
                            'text':'Google', 'active_text': 'google'}],
                    'type': 'dash',
                }),
                (self._signal, {
                    'title': 'Nixon',
                    'links': [{'url':'/syspanel/nixon/google',
                            'text':'Google', 'active_text': 'google'}],
                    'type': 'syspanel',
                }),
            )
        signals.dash_modules_detect().AndReturn(signals_call)
        signals.dash_modules_detect().AndReturn(signals_call)
        self.mox.ReplayAll()

        context = template.Context({'request': self.request})

        # Dash module is rendered correctly, and only in dash sidebar
        ttext = '{% load sidebar_modules %}{% dash_sidebar_modules request %}'
        t = template.Template(ttext)
        self.assertEqual(single_line(t.render(context)),
                         '<h3>Nixon</h3> <ul class="sub_nav"> <li>'
                         '<a href="/dash/nixon/google">Google</a></li> </ul>')

        # Syspanel module is rendered correctly and only in syspanel sidebar
        ttext = ('{% load sidebar_modules %}'
                 '{% syspanel_sidebar_modules request %}')
        t = template.Template(ttext)
        self.assertEqual(single_line(t.render(context)),
                         '<h3>Nixon</h3> <ul class="sub_nav"> <li>'
                         '<a href="/syspanel/nixon/google">Google</a></li>'
                         ' </ul>')

        self.mox.VerifyAll()
示例#2
0
def syspanel_sidebar_modules(request):
    signals_call = signals.dash_modules_detect()
    if signals_call:
        return {'modules': [module[1] for module in signals_call
                                if module[1]['type'] == "syspanel"],
                    'request': request}
    else:
        return {}
def dash_sidebar_modules(request):
    signals_call = signals.dash_modules_detect()
    if signals_call:
        if signals_call[0][1]['type'] == "dash":
            return {'modules': [module[1] for module in signals_call],
                    'request': request }
    else:
        return {}
示例#4
0
def syspanel_sidebar_modules(request):
    signals_call = signals.dash_modules_detect()
    if signals_call:
        if signals_call[0][1]['type'] == "syspanel":
            return {
                'modules': [module[1] for module in signals_call],
                'request': request
            }
    else:
        return {}
示例#5
0
    def test_sidebar_modules(self):
        '''
        Tests for the sidebar module registration mechanism.

        The standard "ping" signal return value looks like this:

        tuple(<dash_apps_ping>, {
                'title': 'Nixon',
                'links': [{'url':'/syspanel/nixon/google',
                          'text':'Google', 'active_text': 'google'}],
                'type': 'syspanel',
            })
        '''
        self.mox.StubOutWithMock(signals, 'dash_modules_detect')
        signals_call = (
            (self._signal, {
                'title':
                'Nixon',
                'links': [{
                    'url': '/dash/nixon/google',
                    'text': 'Google',
                    'active_text': 'google'
                }],
                'type':
                'dash',
            }),
            (self._signal, {
                'title':
                'Nixon',
                'links': [{
                    'url': '/syspanel/nixon/google',
                    'text': 'Google',
                    'active_text': 'google'
                }],
                'type':
                'syspanel',
            }),
        )
        signals.dash_modules_detect().AndReturn(signals_call)
        signals.dash_modules_detect().AndReturn(signals_call)
        self.mox.ReplayAll()

        context = template.Context({'request': self.request})

        # Dash module is rendered correctly, and only in dash sidebar
        ttext = '{% load sidebar_modules %}{% dash_sidebar_modules request %}'
        t = template.Template(ttext)
        self.assertEqual(
            single_line(t.render(context)),
            '<h3>Nixon</h3> <ul class="sub_nav"> <li><a href="/dash/nixon/google">Google</a></li> </ul>'
        )

        # Syspanel module is rendered correctly and only in syspanel sidebar
        ttext = '{% load sidebar_modules %}{% syspanel_sidebar_modules request %}'
        t = template.Template(ttext)
        self.assertEqual(
            single_line(t.render(context)),
            '<h3>Nixon</h3> <ul class="sub_nav"> <li><a href="/syspanel/nixon/google">Google</a></li> </ul>'
        )

        self.mox.VerifyAll()