コード例 #1
0
class ChromeView(TemplateView):
    """ Base class for views which wish to include chrome. """
    template_name = 'regulations/chrome.html'
    has_sidebar = True
    #   Which view name to use when switching versions
    version_switch_view = 'chrome_section_view'

    def check_tree(self, context):
        """Throw an exception if the requested section doesn't exist"""
        label_id, version = context['label_id'], context['version']
        relevant_tree = generator.get_tree_paragraph(label_id, version)
        if relevant_tree is None:
            raise error_handling.MissingSectionException(label_id, version,
                                                         context)

    def get(self, request, *args, **kwargs):
        """Override GET so that we can catch and propagate any errors in the
        included partial(s)"""

        try:
            return super(ChromeView, self).get(request, *args, **kwargs)
        except BadComponentException, e:
            return e.response
        except error_handling.MissingSectionException, e:
            return error_handling.handle_missing_section_404(
                request, e.label_id, e.version, e.context)
コード例 #2
0
    def test_handle_missing_section_404(self, api_reader, add_to_chrome):
        api_reader.ApiReader.return_value.regversions.return_value =\
            {'versions': [{'version': '2', 'by_date':'2013-03-26'}]}
        add_to_chrome.return_value = None

        request = RequestFactory().get('/fake-path')

        extra_content = {'passed': 1, 'env': 'source'}
        response = error_handling.handle_missing_section_404(
            request, '204-1', '2', extra_content)
        self.assertEqual(response, None)
        self.assertTrue(add_to_chrome.called)
コード例 #3
0
    def test_handle_missing_section_404(self, api_reader, add_to_chrome):
        api_reader.ApiReader.return_value.regversions.return_value =\
            {'versions': [{'version': '2', 'by_date': '2013-03-26'}]}
        add_to_chrome.return_value = None

        request = RequestFactory().get('/fake-path')

        extra_content = {'passed': 1, 'env': 'source'}
        response = error_handling.handle_missing_section_404(
            request, '204-1', '2', extra_content)
        self.assertEqual(response, None)
        self.assertTrue(add_to_chrome.called)
コード例 #4
0
ファイル: chrome.py プロジェクト: annalee/regulations-site
    def get(self, request, *args, **kwargs):
        """Override GET so that we can catch and propagate any errors in the
        included partial(s)"""

        try:
            return super(ChromeView, self).get(request, *args, **kwargs)
        except BadComponentException as e:
            return e.response
        except error_handling.MissingSectionException as e:
            return error_handling.handle_missing_section_404(
                request, e.label_id, e.version, e.context)
        except error_handling.MissingContentException as e:
            return error_handling.handle_generic_404(request)
コード例 #5
0
    def get(self, request, *args, **kwargs):
        """Override GET so that we can catch and propagate any errors in the
        included partial(s)"""

        try:
            return super(ChromeView, self).get(request, *args, **kwargs)
        except BadComponentException as e:
            return e.response
        except error_handling.MissingSectionException as e:
            return error_handling.handle_missing_section_404(
                request, e.label_id, e.version, e.context)
        except error_handling.MissingContentException as e:
            return error_handling.handle_generic_404(request)