def test_footer(self):
        toc = [
            navigation.NavItem(url='/preamble/2016_02749/cfr_changes/478',
                               title=navigation.Title('Authority',
                                                      '27 CFR 478',
                                                      'Authority'),
                               markup_id='2016_02749-cfr-478',
                               category='27 CFR 478'),
            navigation.NavItem(url='/preamble/2016_02749/cfr_changes/478-99',
                               title=navigation.Title('§ 478.99 Certain',
                                                      '§ 478.99', 'Certain'),
                               markup_id='2016_02749-cfr-478-99',
                               category='27 CFR 478'),
            navigation.NavItem(url='/preamble/2016_02749/cfr_changes/478-120',
                               title=navigation.Title('§ 478.120 Firearms',
                                                      '§ 478.120', 'Firearms'),
                               markup_id='2016_02749-cfr-478-120',
                               category='27 CFR 478')
        ]

        nav = navigation.footer([], toc, '2016_02749-cfr-478')
        assert nav['previous'] is None
        assert nav['next'].section_id == '2016_02749-cfr-478-99'

        nav = navigation.footer([], toc, '2016_02749-cfr-478-99')
        assert nav['previous'].section_id == '2016_02749-cfr-478'
        assert nav['next'].section_id == '2016_02749-cfr-478-120'

        nav = navigation.footer([], toc, '2016_02749-cfr-478-120')
        assert nav['previous'].section_id == '2016_02749-cfr-478-99'
        assert nav['next'] is None
    def test_footer(self):
        toc = [
            navigation.NavItem(
                url='/preamble/2016_02749/cfr_changes/478',
                title=navigation.Title('Authority', '27 CFR 478', 'Authority'),
                markup_id='2016_02749-cfr-478',
                category='27 CFR 478'),
            navigation.NavItem(
                url='/preamble/2016_02749/cfr_changes/478-99',
                title=navigation.Title(
                    '§ 478.99 Certain', '§ 478.99', 'Certain'),
                markup_id='2016_02749-cfr-478-99',
                category='27 CFR 478'),
            navigation.NavItem(
                url='/preamble/2016_02749/cfr_changes/478-120',
                title=navigation.Title(
                    '§ 478.120 Firearms', '§ 478.120', 'Firearms'),
                markup_id='2016_02749-cfr-478-120',
                category='27 CFR 478')
        ]

        nav = navigation.footer([], toc, '2016_02749-cfr-478')
        assert nav['previous'] is None
        assert nav['next'].section_id == '2016_02749-cfr-478-99'

        nav = navigation.footer([], toc, '2016_02749-cfr-478-99')
        assert nav['previous'].section_id == '2016_02749-cfr-478'
        assert nav['next'].section_id == '2016_02749-cfr-478-120'

        nav = navigation.footer([], toc, '2016_02749-cfr-478-120')
        assert nav['previous'].section_id == '2016_02749-cfr-478-99'
        assert nav['next'] is None
    def test_footer(self):
        toc = navigation.make_preamble_nav(self.nodes)

        nav = navigation.footer(toc, [], 'doc_id-preamble-doc_id-I')
        assert nav['next'].section_id == 'doc_id-preamble-doc_id-II'
        assert nav['previous'] is None

        nav = navigation.footer(toc, [], 'doc_id-preamble-doc_id-II')
        assert nav['previous'].section_id == 'doc_id-preamble-doc_id-I'
        assert nav['next'] is None
    def test_footer(self):
        toc = navigation.make_preamble_nav(self.nodes)

        nav = navigation.footer(toc, [], 'doc_id-preamble-doc_id-I')
        assert nav['next'].section_id == 'doc_id-preamble-doc_id-II'
        assert nav['previous'] is None

        nav = navigation.footer(toc, [], 'doc_id-preamble-doc_id-II')
        assert nav['previous'].section_id == 'doc_id-preamble-doc_id-I'
        assert nav['next'] is None
    def test_footer(self):
        toc = navigation.make_preamble_nav(self.nodes)

        nav = navigation.footer(toc, [], 'doc_id-preamble-doc_id-I')
        assert_equal(nav['next'].section_id, 'doc_id-preamble-doc_id-II')
        assert_is_none(nav['previous'])

        nav = navigation.footer(toc, [], 'doc_id-preamble-doc_id-II')
        assert_equal(nav['previous'].section_id, 'doc_id-preamble-doc_id-I')
        assert_is_none(nav['next'])
Example #6
0
    def test_footer(self):
        toc = navigation.make_preamble_nav(self.nodes)

        nav = navigation.footer(toc, [], 'doc_id-preamble-doc_id-I')
        assert_equal(nav['next'].section_id, 'doc_id-preamble-doc_id-II')
        assert_is_none(nav['previous'])

        nav = navigation.footer(toc, [], 'doc_id-preamble-doc_id-II')
        assert_equal(nav['previous'].section_id, 'doc_id-preamble-doc_id-I')
        assert_is_none(nav['next'])
    def get(self, request, doc_number, section):
        context = common_context(doc_number)
        full_id = '{}-cfr-{}'.format(doc_number, section)

        versions, amendments = merge_cfr_changes(doc_number, context['notice'])
        label_parts = section.split('-')

        if len(label_parts) == 1:
            sub_context = self.authorities_context(amendments,
                                                   cfr_part=section)
            section_label = 'Authority'
        else:
            toc_position = next(
                idx for idx, nav in enumerate(context['cfr_change_toc'])
                if nav.section_id == full_id)
            sub_context = self.regtext_changes_context(
                amendments,
                versions,
                doc_number=doc_number,
                label_id=section,
                toc_position=toc_position,
            )
            section_label = sub_context['tree']['human_label']
        sub_context['meta'] = context['meta']

        context.update({
            'sub_context':
            sub_context,
            'sub_template':
            'regulations/cfr_changes.html',
            'full_id':
            full_id,
            'section_label':
            section_label,
            'type':
            'cfr',
            'navigation':
            navigation.footer(context['preamble_toc'],
                              context['cfr_change_toc'], full_id),
        })

        if not request.is_ajax() and request.GET.get('partial') != 'true':
            template = 'regulations/preamble-chrome.html'
        else:
            template = 'regulations/preamble-partial.html'
        return TemplateResponse(request=request,
                                template=template,
                                context=context)
    def get(self, request, *args, **kwargs):
        label_parts = kwargs.get('paragraphs', '').split('/')
        doc_number = label_parts[0]
        context = common_context(doc_number)

        # Redirect to first section on top-level preamble
        if len(label_parts) == 1:
            section = first_preamble_section(context['preamble'])
            if not section:
                raise Http404
            return redirect('chrome_preamble',
                            paragraphs='/'.join(section['label']))

        subtree = find_subtree(context['preamble'], label_parts)
        if subtree is None:
            raise Http404

        sub_context = generate_html_tree(subtree,
                                         request,
                                         id_prefix=[doc_number, 'preamble'])
        template = sub_context['node']['template_name']
        nav = navigation.footer(
            context['preamble_toc'],
            context['cfr_change_toc'],
            full_id=sub_context['node']['full_id'],
        )
        sub_context['meta'] = context['meta']

        context.update({
            'sub_context': sub_context,
            'sub_template': template,
            'full_id': sub_context['node']['full_id'],
            'section_label': sub_context['node']['human_label'],
            'type': 'preamble',
            'navigation': nav,
        })

        if not request.is_ajax() and request.GET.get('partial') != 'true':
            template = 'regulations/preamble-chrome.html'
        else:
            template = 'regulations/preamble-partial.html'
        return TemplateResponse(request=request,
                                template=template,
                                context=context)
Example #9
0
    def get(self, request, doc_number, section):
        context = common_context(doc_number)
        full_id = '{}-cfr-{}'.format(doc_number, section)

        versions, amendments = merge_cfr_changes(doc_number, context['notice'])
        label_parts = section.split('-')

        if len(label_parts) == 1:
            sub_context = self.authorities_context(
                amendments, cfr_part=section)
            section_label = 'Authority'
        else:
            toc_position = next(
                idx for idx, nav in enumerate(context['cfr_change_toc'])
                if nav.section_id == full_id)
            sub_context = self.regtext_changes_context(
                amendments,
                versions,
                doc_number=doc_number,
                label_id=section,
                toc_position=toc_position,
            )
            section_label = sub_context['tree']['human_label']
        sub_context['meta'] = context['meta']

        context.update({
            'sub_context': sub_context,
            'sub_template': 'regulations/cfr_changes.html',
            'full_id': full_id,
            'section_label': section_label,
            'type': 'cfr',
            'navigation': navigation.footer(
                context['preamble_toc'],
                context['cfr_change_toc'],
                full_id
            ),
        })

        if not request.is_ajax() and request.GET.get('partial') != 'true':
            template = 'regulations/preamble-chrome.html'
        else:
            template = 'regulations/preamble-partial.html'
        return TemplateResponse(request=request, template=template,
                                context=context)
Example #10
0
    def get(self, request, *args, **kwargs):
        label_parts = kwargs.get('paragraphs', '').split('/')
        doc_number = label_parts[0]
        context = common_context(doc_number)

        # Redirect to first section on top-level preamble
        if len(label_parts) == 1:
            section = first_preamble_section(context['preamble'])
            if not section:
                raise Http404
            return redirect(
                'chrome_preamble', paragraphs='/'.join(section['label']))

        subtree = find_subtree(context['preamble'], label_parts)
        if subtree is None:
            raise Http404

        sub_context = generate_html_tree(subtree, request,
                                         id_prefix=[doc_number, 'preamble'])
        template = sub_context['node']['template_name']
        nav = navigation.footer(
            context['preamble_toc'],
            context['cfr_change_toc'],
            full_id=sub_context['node']['full_id'],
        )
        sub_context['meta'] = context['meta']

        context.update({
            'sub_context': sub_context,
            'sub_template': template,
            'full_id': sub_context['node']['full_id'],
            'section_label': sub_context['node']['human_label'],
            'type': 'preamble',
            'navigation': nav,
        })

        if not request.is_ajax() and request.GET.get('partial') != 'true':
            template = 'regulations/preamble-chrome.html'
        else:
            template = 'regulations/preamble-partial.html'
        return TemplateResponse(request=request, template=template,
                                context=context)