コード例 #1
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
コード例 #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
コード例 #3
0
    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)
コード例 #4
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)
コード例 #5
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)
コード例 #6
0
ファイル: partial.py プロジェクト: eregs/regulations-site
    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)
コード例 #7
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)
コード例 #8
0
 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'])
コード例 #9
0
    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)
コード例 #10
0
    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)
コード例 #11
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])
コード例 #12
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])
コード例 #13
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)
コード例 #14
0
    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'])
コード例 #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
コード例 #16
0
    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'])
コード例 #17
0
    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)
コード例 #18
0
    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)
コード例 #19
0
ファイル: diff.py プロジェクト: eregs/regulations-site
    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
コード例 #20
0
    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'])
コード例 #21
0
    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'])
コード例 #22
0
    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)
コード例 #23
0
    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)
コード例 #24
0
def generate_html(regulation_tree, layer_appliers):
    builder = CFRHTMLBuilder(*layer_appliers)
    builder.tree = regulation_tree
    builder.generate_html()
    return builder
コード例 #25
0
 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']}))
コード例 #26
0
 def test_no_section_sign(self):
     text = CFRHTMLBuilder.section_space(' abc')
     self.assertEquals(text, ' abc')
     self.assertTrue(True)
コード例 #27
0
 def test_no_section_sign(self):
     text = CFRHTMLBuilder.section_space(' abc')
     self.assertEquals(text, ' abc')