def get_context_data(self, **kwargs):
        #   skip our parent
        context = super(PartialView, self).get_context_data(**kwargs)

        label_id = context['label_id']
        label = label_id.split('-')
        reg_part = label[0]
        version = context['version']

        context['navigation'] = self.section_navigation(label_id, version)

        interp = generator.get_tree_paragraph(reg_part + '-Interp', version)
        if not interp:
            raise Http404

        subterp_sects = filter_by_subterp(interp['children'], label, version)
        if not subterp_sects:
            raise Http404

        context['markup_page_type'] = 'reg-section'
        html_label = node_types.to_markup_id(label_id.split('-'))
        interp['children'] = subterp_sects

        # interp['label] is defined so that the template receives the
        # appropriate markup ID, matching the rendered subterp and not
        # the parent node in the tree
        interp['label'] = label
        layers = list(self.determine_layers(reg_part + '-Interp', version))
        builder = CFRHTMLBuilder(layers)
        builder.tree = interp
        builder.generate_html()
        interp = builder.tree
        interp['html_label'] = html_label
        context['tree'] = {'children': [interp]}
        return context
Example #2
0
    def get_context_data(self, **kwargs):
        #   skip our parent
        context = super(PartialView, self).get_context_data(**kwargs)

        label_id = context['label_id']
        label = label_id.split('-')
        reg_part = label[0]
        version = context['version']

        context['navigation'] = self.section_navigation(label_id, version)

        interp = generator.get_tree_paragraph(reg_part + '-Interp', version)
        if not interp:
            raise Http404

        subterp_sects = filter_by_subterp(interp['children'], label, version)
        if not subterp_sects:
            raise Http404

        context['markup_page_type'] = 'reg-section'
        html_label = node_types.to_markup_id(label_id.split('-'))
        interp['children'] = subterp_sects

        # interp['label] is defined so that the template receives the
        # appropriate markup ID, matching the rendered subterp and not
        # the parent node in the tree
        interp['label'] = label
        layers = list(self.determine_layers(reg_part + '-Interp', version))
        builder = CFRHTMLBuilder(layers)
        builder.tree = interp
        builder.generate_html()
        interp = builder.tree
        interp['html_label'] = html_label
        context['tree'] = {'children': [interp]}
        return context
    def test_list_level_regulations_no_level(self):
        builder = CFRHTMLBuilder()

        parts = ['101', '1']
        node_type = REGTEXT

        result = builder.list_level(parts, node_type)
        self.assertEquals(result, 0)
    def test_list_level_regulations_no_level(self):
        builder = CFRHTMLBuilder(None, None, None)

        parts = ['101', '1']
        node_type = REGTEXT

        result = builder.list_level(parts, node_type)
        self.assertEquals(result, 0)
    def test_header_parsing(self):
        builder = CFRHTMLBuilder(None, None, None)

        node = {
            "label": ["234", "a", "1"],
            "title": "Title (Regulation R)",
            'node_type': APPENDIX
        }
        titleless_node = {"title": "Title", 'node_type': REGTEXT}

        parsed_title = builder.parse_doc_title(node['title'])
        no_title = builder.parse_doc_title(titleless_node['title'])

        self.assertEqual("(Regulation R)", parsed_title)
        self.assertEqual(no_title, None)
Example #6
0
    def get_context_data(self, **kwargs):
        context = super(PartialView, self).get_context_data(**kwargs)

        label_id = context['label_id']
        version = context['version']

        tree = generator.get_tree_paragraph(label_id, version)
        if tree is None:
            raise Http404

        layers = list(self.determine_layers(label_id, version))
        builder = CFRHTMLBuilder(layers)
        builder.tree = tree
        builder.generate_html()
        return self.transform_context(context, builder)
    def get_context_data(self, **kwargs):
        context = super(PartialView, self).get_context_data(**kwargs)

        label_id = context['label_id']
        version = context['version']

        tree = generator.get_tree_paragraph(label_id, version)
        if tree is None:
            raise Http404

        layers = list(self.determine_layers(label_id, version))
        builder = CFRHTMLBuilder(layers)
        builder.tree = tree
        builder.generate_html()
        return self.transform_context(context, builder)
 def test_process_node_title_section_space_diff(self):
     """" Diffs and sections spaces need to place nicely together. """
     builder = CFRHTMLBuilder()
     diff = {'204': {'title': [('delete', 7, 9), ('insert', 10, 'AAC')],
                     'text':  [('delete', 0, 2), ('insert', 4, 'AAB')],
                     'op': ''}}
     da = diff_applier.DiffApplier(diff, None)
     node = {
         "label_id": u"204",
         "title": u"§ 101.6 abcd",
         'node_type': APPENDIX
     }
     builder.diff_applier = da
     builder.process_node_title(node)
     self.assertEqual(
         u'§&nbsp;101.6<del> a</del>b<ins>AAC</ins>cd', node['header'])
    def test_list_level_interpretations(self):
        builder = CFRHTMLBuilder()

        parts = ['101', '12', 'a', 'Interp', '1']
        node_type = INTERP

        result = builder.list_level(parts, node_type)
        self.assertEquals(result, 1)

        parts.append('j')
        result = builder.list_level(parts, node_type)
        self.assertEquals(result, 2)

        parts.append('B')
        result = builder.list_level(parts, node_type)
        self.assertEquals(result, 3)
    def test_list_level_interpretations(self):
        builder = CFRHTMLBuilder(None, None, None)

        parts = ['101', '12', 'a', 'Interp', '1']
        node_type = INTERP

        result = builder.list_level(parts, node_type)
        self.assertEquals(result, 1)

        parts.append('j')
        result = builder.list_level(parts, node_type)
        self.assertEquals(result, 2)

        parts.append('B')
        result = builder.list_level(parts, node_type)
        self.assertEquals(result, 3)
    def test_interp_node_with_citations(self):
        inline, p, sr = Mock(), Mock(), Mock()
        builder = CFRHTMLBuilder(inline, p, sr)

        node = {
            'text': 'Interpretation with a link',
            'children': [],
            'node_type': INTERP,
            'label': ['999', '5', 'Interp']
        }
        p.apply_layers.return_value = node
        inline.get_layer_pairs.return_value = []
        sr.get_layer_pairs.return_value = []
        builder.process_node(node)
        layer_parameters = inline.get_layer_pairs.call_args[0]
        self.assertEqual('Interpretation with a link', layer_parameters[1])
        self.assertEqual('999-5-Interp', layer_parameters[0])
    def test_interp_node_with_citations(self):
        inline, p, sr = Mock(), Mock(), Mock()
        builder = CFRHTMLBuilder(inline, p, sr)

        node = {
            'text': 'Interpretation with a link',
            'children': [],
            'node_type': INTERP,
            'label': ['999', '5', 'Interp']
        }
        p.apply_layers.return_value = node
        inline.get_layer_pairs.return_value = []
        sr.get_layer_pairs.return_value = []
        builder.process_node(node)
        layer_parameters = inline.get_layer_pairs.call_args[0]
        self.assertEqual('Interpretation with a link', layer_parameters[1])
        self.assertEqual('999-5-Interp', layer_parameters[0])
    def test_header_parsing(self):
        builder = CFRHTMLBuilder(None, None, None)

        node = {
            "label": ["234", "a", "1"],
            "title": "Title (Regulation R)",
            'node_type': APPENDIX
        }
        titleless_node = {
            "title": "Title",
            'node_type': REGTEXT
        }

        parsed_title = builder.parse_doc_title(node['title'])
        no_title = builder.parse_doc_title(titleless_node['title'])

        self.assertEqual("(Regulation R)", parsed_title)
        self.assertEqual(no_title, None)
    def test_modify_interp_node_header(self):
        node = {
            'children': [],
            'header': 'This interprets 22(a), a paragraph',
            'label': ['872', '22', 'a', 'Interp'],
            'node_type': INTERP,
        }
        icl = InternalCitationLayer(None)
        icl.sectional = True
        builder = CFRHTMLBuilder([icl])

        builder.modify_interp_node(node)
        header = 'This interprets {0}, a paragraph'.format(
            icl.render_url(['872', '22', 'a'], '22(a)'))
        self.assertEqual(header, node['header_markup'])

        node['label'] = ['872', '22']
        builder.modify_interp_node(node)
        self.assertEqual(node['header'], node['header_markup'])
Example #15
0
    def get_context_data(self, **kwargs):
        # We don't want to run the content data of PartialView -- it assumes
        # we will be applying layers
        context = super(PartialView, self).get_context_data(**kwargs)

        label_id = context['label_id']
        versions = Versions(context['version'], context['newer_version'],
                            self.request.GET.get('from_version'))

        tree = generator.get_tree_paragraph(label_id, versions.older)

        if tree is None:
            # TODO We need a more complicated check here to see if the diffs
            # add the requested section. If not -> 404
            tree = {}

        diff_applier = generator.get_diff_applier(label_id, versions.older,
                                                  versions.newer)
        if diff_applier is None:
            raise error_handling.MissingContentException()
        layers = list(generator.diff_layers(versions, label_id))

        builder = CFRHTMLBuilder(layers, diff_applier)
        builder.tree = tree
        builder.generate_html()

        child_of_root = builder.tree
        if builder.tree['node_type'] == REGTEXT:
            child_of_root = {
                'node_type': EMPTYPART,
                'children': [builder.tree]
            }
        context['tree'] = {'children': [child_of_root]}
        context['markup_page_type'] = 'diff'

        regpart = label_id.split('-')[0]
        old_toc = fetch_toc(regpart, versions.older)
        diff = generator.get_diff_json(regpart, versions.older, versions.newer)
        context['TOC'] = diff_toc(versions, old_toc, diff)
        context['navigation'] = self.footer_nav(label_id, context['TOC'],
                                                versions)
        return context
    def test_modify_interp_node(self):
        node = {
            'node_type': INTERP,
            'label': ['872', '22', 'Interp'],
            'children': [{'label': ['872', '22', 'Interp', '1']},
                         {'label': ['872', '22', 'a', 'Interp']},
                         {'label': ['872', '22', 'b', 'Interp']}]
        }
        builder = CFRHTMLBuilder()
        builder.modify_interp_node(node)
        self.assertTrue(node['section_header'])
        self.assertEqual(node['header_children'],
                         [{'label': ['872', '22', 'a', 'Interp']},
                          {'label': ['872', '22', 'b', 'Interp']}])
        self.assertEqual(node['par_children'],
                         [{'label': ['872', '22', 'Interp', '1']}])

        node['label'] = ['872', '222', 'a', 'Interp']
        builder.modify_interp_node(node)
        self.assertFalse(node['section_header'])
    def test_list_level_appendices(self):
        builder = CFRHTMLBuilder()

        parts = ['101', 'A', '1', 'a']
        node_type = APPENDIX

        result = builder.list_level(parts, node_type)
        self.assertEquals(result, 1)

        parts.append('2')
        result = builder.list_level(parts, node_type)
        self.assertEquals(result, 2)

        parts.append('k')
        result = builder.list_level(parts, node_type)
        self.assertEquals(result, 3)

        parts.append('B')
        result = builder.list_level(parts, node_type)
        self.assertEquals(result, 4)
    def test_list_level_regulations(self):
        builder = CFRHTMLBuilder()

        parts = ['101', '1', 'a']
        node_type = REGTEXT

        result = builder.list_level(parts, node_type)
        self.assertEquals(result, 1)

        parts.append('2')
        result = builder.list_level(parts, node_type)
        self.assertEquals(result, 2)

        parts.append('k')
        result = builder.list_level(parts, node_type)
        self.assertEquals(result, 3)

        parts.append('B')
        result = builder.list_level(parts, node_type)
        self.assertEquals(result, 4)
Example #19
0
    def get_context_data(self, **kwargs):
        # We don't want to run the content data of PartialView -- it assumes
        # we will be applying layers
        context = super(PartialView, self).get_context_data(**kwargs)

        label_id = context['label_id']
        versions = Versions(context['version'], context['newer_version'],
                            self.request.GET.get('from_version'))

        tree = generator.get_tree_paragraph(label_id, versions.older)

        if tree is None:
            # TODO We need a more complicated check here to see if the diffs
            # add the requested section. If not -> 404
            tree = {}

        diff_applier = generator.get_diff_applier(
            label_id, versions.older, versions.newer)
        if diff_applier is None:
            raise error_handling.MissingContentException()
        layers = list(generator.diff_layers(versions, label_id))

        builder = CFRHTMLBuilder(layers, diff_applier)
        builder.tree = tree
        builder.generate_html()

        child_of_root = builder.tree
        if builder.tree['node_type'] == REGTEXT:
            child_of_root = {
                'node_type': EMPTYPART,
                'children': [builder.tree]}
        context['tree'] = {'children': [child_of_root]}
        context['markup_page_type'] = 'diff'

        regpart = label_id.split('-')[0]
        old_toc = fetch_toc(regpart, versions.older)
        diff = generator.get_diff_json(regpart, versions.older, versions.newer)
        context['TOC'] = diff_toc(versions, old_toc, diff)
        context['navigation'] = self.footer_nav(
            label_id, context['TOC'], versions)
        return context
    def test_modify_interp_node_header(self):
        node = {
            'children': [],
            'header': 'This interprets 22(a), a paragraph',
            'label': ['872', '22', 'a', 'Interp'],
            'node_type': INTERP,
        }
        icl = InternalCitationLayer(None)
        icl.sectional = True
        ila = InlineLayersApplier()
        ila.add_layer(icl)
        builder = CFRHTMLBuilder(ila, None, None)

        builder.modify_interp_node(node)
        self.assertEqual('This interprets '
                         + icl.render_url(['872', '22', 'a'], '22(a)')
                         + ', a paragraph', node['header_markup'])

        node['label'] = ['872', '22']
        builder.modify_interp_node(node)
        self.assertEqual(node['header'], node['header_markup'])
    def test_modify_interp_node_header(self):
        node = {
            'children': [],
            'header': 'This interprets 22(a), a paragraph',
            'label': ['872', '22', 'a', 'Interp'],
            'node_type': INTERP,
        }
        icl = InternalCitationLayer(None)
        icl.sectional = True
        builder = CFRHTMLBuilder([icl])

        builder.modify_interp_node(node)
        header = 'This interprets {0}, a paragraph'.format(
            icl.render_url(['872', '22', 'a'], '22(a)'))
        self.assertEqual(header, node['header_markup'])

        node['label'] = ['872', '22']
        builder.modify_interp_node(node)
        self.assertEqual(node['header'], node['header_markup'])
    def test_list_level_regulations(self):
        builder = CFRHTMLBuilder(None, None, None)

        parts = ['101', '1', 'a']
        node_type = REGTEXT

        result = builder.list_level(parts, node_type)
        self.assertEquals(result, 1)

        parts.append('2')
        result = builder.list_level(parts, node_type)
        self.assertEquals(result, 2)

        parts.append('k')
        result = builder.list_level(parts, node_type)
        self.assertEquals(result, 3)

        parts.append('B')
        result = builder.list_level(parts, node_type)
        self.assertEquals(result, 4)
    def test_list_level_appendices(self):
        builder = CFRHTMLBuilder(None, None, None)

        parts = ['101', 'A', '1', 'a']
        node_type = APPENDIX

        result = builder.list_level(parts, node_type)
        self.assertEquals(result, 1)

        parts.append('2')
        result = builder.list_level(parts, node_type)
        self.assertEquals(result, 2)

        parts.append('k')
        result = builder.list_level(parts, node_type)
        self.assertEquals(result, 3)

        parts.append('B')
        result = builder.list_level(parts, node_type)
        self.assertEquals(result, 4)
Example #24
0
def generate_html(regulation_tree, layer_appliers):
    builder = CFRHTMLBuilder(*layer_appliers)
    builder.tree = regulation_tree
    builder.generate_html()
    return builder
 def test_human_label(self):
     self.assertEqual(
         'Regulation 111', CFRHTMLBuilder.human_label({'label': ['111']}))
     self.assertEqual(
         u'§ 111.22(f)',
         CFRHTMLBuilder.human_label({'label': ['111', '22', 'f']}))
 def test_no_section_sign(self):
     text = CFRHTMLBuilder.section_space(' abc')
     self.assertEquals(text, ' abc')
     self.assertTrue(True)
 def test_no_section_sign(self):
     text = CFRHTMLBuilder.section_space(' abc')
     self.assertEquals(text, ' abc')