Пример #1
0
    def get_context_data(self, **kwargs):
        context = super(ChromeView, self).get_context_data(**kwargs)

        label_id = context['label_id']
        version = context['version']
        label_id_list = label_id.split('-')
        reg_part = label_id_list[0]
        context['q'] = self.request.GET.get('q', '')
        context['formatted_id'] = label_to_text(label_id_list, True, True)
        context['node_type'] = type_from_label(label_id_list)

        error_handling.check_regulation(reg_part)

        try:
            self.set_chrome_context(context, reg_part, version)
            self.check_tree(context)
            self.add_main_content(context)
        except (IndexError, TypeError):
            raise Http404

        if self.has_sidebar:
            sidebar_view = SideBarView.as_view()
            response = sidebar_view(self.request, label_id=label_id,
                                    version=version)
            self._assert_good(response)
            response.render()
            context['sidebar_content'] = response.content

        return context
Пример #2
0
    def get_context_data(self, **kwargs):
        context = super(ChromeView, self).get_context_data(**kwargs)

        label_id = context['label_id']
        version = context['version']
        label_id_list = label_id.split('-')
        reg_part = label_id_list[0]
        context['q'] = self.request.GET.get('q', '')
        context['formatted_id'] = label_to_text(label_id_list, True, True)
        context['node_type'] = type_from_label(label_id_list)

        error_handling.check_regulation(reg_part)

        try:
            self.set_chrome_context(context, reg_part, version)
            self.check_tree(context)
            self.add_main_content(context)
        except (IndexError, TypeError):
            raise Http404

        if self.has_sidebar:
            sidebar_view = SideBarView.as_view()
            response = sidebar_view(self.request, label_id=label_id,
                                    version=version)
            self._assert_good(response)
            response.render()
            context['sidebar_content'] = response.content

        return context
Пример #3
0
    def test_type_from_label(self):
        for label in [('200', '5', 'A'), ('250',), ('250', '5'),
                      ('200', '5', 'a', 'i', 'C')]:
            self.assertEqual(node_types.REGTEXT,
                             node_types.type_from_label(label))

        for label in [('250', 'A2'), ('250', 'A'), ('250', 'A', '3(b)')]:
            self.assertEqual(node_types.APPENDIX,
                             node_types.type_from_label(label))

        for label in [('250', 'Interp'), ('250', 'A', 'Interp'),
                      ('250', 'A', 'Interp'), ('250', '5', 'b', 'Interp'),
                      ('250', '5', 'b', 'Interp', '1'),
                      ('250', '5', 'Interp', '5', 'r')]:
            self.assertEqual(node_types.INTERP,
                             node_types.type_from_label(label))

        self.assertEqual(node_types.EMPTYPART,
                         node_types.type_from_label(['250', 'Subpart']))
        self.assertEqual(node_types.SUBPART,
                         node_types.type_from_label(['250', 'Subpart', 'C']))
Пример #4
0
 def reduce_results(self, results, page):
     """Ignore results found in non-displayable nodes such as the root,
     subparts, etc. Further, the page size returned by the API does not
     match what we display, so we need to reduce the result count
     accordingly. @TODO this is a hack -- we should be able to limit
     results in the request instead"""
     # API page size is API_PAGE_SIZE, but we show only PAGE_SIZE
     page_idx = (page % (API_PAGE_SIZE / PAGE_SIZE)) * PAGE_SIZE
     original_count = len(results['results'])
     is_root = lambda r: len(r['label']) == 1
     is_subpart = lambda r: node_types.type_from_label(r['label']) in (
         node_types.EMPTYPART, node_types.SUBPART, node_types.SUBJGRP)
     results['results'] = [r for r in results['results']
                           if not is_root(r) and not is_subpart(r)]
     num_results_ignored = original_count - len(results['results'])
     results['total_hits'] -= num_results_ignored
     results['results'] = results['results'][page_idx:page_idx + PAGE_SIZE]
Пример #5
0
    def get_context_data(self, **kwargs):
        context = super(ChromeView, self).get_context_data(**kwargs)

        label_id = context['label_id']
        version = context['version']
        label_id_list = label_id.split('-')
        reg_part = label_id_list[0]
        context['q'] = self.request.GET.get('q', '')
        context['formatted_id'] = label_to_text(label_id_list, True, True)
        context['node_type'] = type_from_label(label_id_list)

        error_handling.check_regulation(reg_part)
        self.set_chrome_context(context, reg_part, version)

        self.check_tree(context)
        self.add_main_content(context)
        context['sidebar_content'] = self.sidebar(label_id, version)

        return context
Пример #6
0
    def get_context_data(self, **kwargs):
        context = super(ChromeView, self).get_context_data(**kwargs)

        label_id = context['label_id']
        version = context['version']
        label_id_list = label_id.split('-')
        reg_part = label_id_list[0]
        context['q'] = self.request.GET.get('q', '')
        context['formatted_id'] = label_to_text(label_id_list, True, True)
        context['node_type'] = type_from_label(label_id_list)

        error_handling.check_regulation(reg_part)
        self.set_chrome_context(context, reg_part, version)

        self.check_tree(context)
        self.add_main_content(context)
        context['sidebar_content'] = self.sidebar(label_id, version)

        return context
Пример #7
0
 def reduce_results(self, results, page):
     """Ignore results found in non-displayable nodes such as the root,
     subparts, etc. Further, the page size returned by the API does not
     match what we display, so we need to reduce the result count
     accordingly. @TODO this is a hack -- we should be able to limit
     results in the request instead"""
     # API page size is API_PAGE_SIZE, but we show only PAGE_SIZE
     page_idx = (page % (API_PAGE_SIZE // PAGE_SIZE)) * PAGE_SIZE
     original_count = len(results['results'])
     is_root = lambda r: len(r['label']) == 1
     is_subpart = lambda r: node_types.type_from_label(r['label']) in (
         node_types.EMPTYPART, node_types.SUBPART, node_types.SUBJGRP)
     results['results'] = [
         r for r in results['results']
         if not is_root(r) and not is_subpart(r)
     ]
     num_results_ignored = original_count - len(results['results'])
     results['total_hits'] -= num_results_ignored
     results['results'] = results['results'][page_idx:page_idx + PAGE_SIZE]
Пример #8
0
def appendix_supplement(data):
    """Handle items pointing to an appendix or supplement"""
    node_type = node_types.type_from_label(data['index'])
    if len(data['index']) == 2 and node_type in (node_types.APPENDIX,
                                                 node_types.INTERP):
        element = {}
        if node_type == node_types.INTERP:
            element['is_supplement'] = True
        else:
            element['is_appendix'] = True

        segments = try_split(data['title'])
        if segments:
            element['label'], element['sub_label'] = segments[:2]
        elif '[' in data['title']:
            position = data['title'].find('[')
            element['label'] = data['title'][:position].strip()
            element['sub_label'] = data['title'][position:]
        else:
            element['label'] = data['title']

        element['section_id'] = '-'.join(data['index'])
        return element