def add_cfr_part(self, doc_number, version_info, amendment): """While processing an amendment, if it refers to a CFR part which hasn't been seen before, we need to perform some accounting, fetching related meta data, etc.""" part = amendment['cfr_part'] if part not in version_info: logger.error("No version info for %s", part) elif self.cfr_part is None or self.cfr_part != amendment['cfr_part']: meta = utils.regulation_meta(part, version_info[part]['right']) flat_toc = fetch_toc(part, version_info[part]['right'], flatten=True) self.section_titles = { elt['index'][1]: elt['title'] for elt in flat_toc if len(elt['index']) == 2 } self.cfr_part = part self.cfr_title = meta.get('cfr_title_number') self.section = None title = '{} CFR {}'.format(self.cfr_title, part) markup_id = '{}-cfr-{}'.format(doc_number, part) self.toc.append( NavItem(url=reverse('cfr_changes', kwargs={ 'doc_number': doc_number, 'section': part }), title=Title('Authority', title, 'Authority'), markup_id=markup_id, category=title, section_id='')) # disable AJAX
def regulation(request, label_id): context = {} current_version, new_version = get_versions(label_id) if new_version: context['new_version'] = new_version context['current_version'] = current_version context['label_id'] = label_id context['reg_first_section'] = utils.first_section( label_id, current_version['version']) context['reg_part'] = label_id.split('-')[0] regulation_meta = utils.regulation_meta( label_id, current_version['version'], True) context['meta'] = regulation_meta c = RequestContext(request, context) t = select_template([ 'regulations/landing_%s.html' % label_id, 'regulations/landing_base.html', 'regulations/generic_landing.html']) return HttpResponse(t.render(c))
def new_cfr_part(self, amendment): """While processing an amendment, if it refers to a CFR part which hasn't been seen before, we need to perform some accounting, fetching related meta data, etc.""" part = amendment['cfr_part'] meta = utils.regulation_meta(part, self.version_info[part]['right']) flat_toc = fetch_toc(part, self.version_info[part]['right'], flatten=True) self.section_titles = { elt['index'][1]: elt['title'] for elt in flat_toc if len(elt['index']) == 2 } self.current_part = ToCPart(title=meta.get('cfr_title_number'), part=part, name=meta.get('statutory_name'), sections=[], authority_url=reverse('cfr_changes', kwargs={ 'doc_number': self.doc_number, 'section': part })) self.current_section = None self.toc.append(self.current_part)
def add_cfr_part(self, doc_number, version_info, amendment): """While processing an amendment, if it refers to a CFR part which hasn't been seen before, we need to perform some accounting, fetching related meta data, etc.""" part = amendment['cfr_part'] if part not in version_info: logger.warning("No version info for %s", part) elif self.cfr_part is None or self.cfr_part != amendment['cfr_part']: meta = utils.regulation_meta(part, version_info[part]['right']) flat_toc = fetch_toc(part, version_info[part]['right'], flatten=True) self.section_titles = { elt['index'][1]: elt['title'] for elt in flat_toc if len(elt['index']) == 2} self.cfr_part = part self.cfr_title = meta.get('cfr_title_number') self.section = None title = '{} CFR {}'.format(self.cfr_title, part) markup_id = '{}-cfr-{}'.format(doc_number, part) self.toc.append(NavItem( url=reverse('cfr_changes', kwargs={ 'doc_number': doc_number, 'section': part}), title=Title('Authority', title, 'Authority'), markup_id=markup_id, category=title, section_id='')) # disable AJAX
def context(self, http_client, request): meta = regulation_meta(self.cfr_part, self.version) return { 'cfr_title': meta.get('cfr_title_number'), 'cfr_part': self.cfr_part, 'version': self.version, }
def new_cfr_part(self, amendment): """While processing an amendment, if it refers to a CFR part which hasn't been seen before, we need to perform some accounting, fetching related meta data, etc.""" part = amendment['cfr_part'] meta = utils.regulation_meta(part, self.version_info[part]['right']) flat_toc = fetch_toc(part, self.version_info[part]['right'], flatten=True) self.section_titles = {elt['index'][1]: elt['title'] for elt in flat_toc if len(elt['index']) == 2} self.current_part = ToCPart( title=meta.get('cfr_title_number'), part=part, name=meta.get('statutory_name'), sections=[], authority_url=reverse('cfr_changes', kwargs={ 'doc_number': self.doc_number, 'section': part})) self.current_section = None self.toc.append(self.current_part)
def set_chrome_context(self, context, reg_part, version): context['reg_part'] = reg_part context['history'] = fetch_grouped_history(reg_part) toc = fetch_toc(reg_part, version) for el in toc: el['url'] = SectionUrl().of(el['index'], version, self.partial_class.sectional_links) for sub in el.get('sub_toc', []): sub['url'] = SectionUrl().of( sub['index'], version, self.partial_class.sectional_links) context['TOC'] = toc context['meta'] = utils.regulation_meta(reg_part, version) context['version_switch_view'] = self.version_switch_view context['diff_redirect_label'] = self.diff_redirect_label( context['label_id'], toc)
def set_chrome_context(self, context, reg_part, version): context['reg_part'] = reg_part context['history'] = fetch_grouped_history(reg_part) toc = fetch_toc(reg_part, version) for el in toc: el['url'] = SectionUrl().of( el['index'], version, self.partial_class.sectional_links) for sub in el.get('sub_toc', []): sub['url'] = SectionUrl().of( sub['index'], version, self.partial_class.sectional_links) context['TOC'] = toc context['meta'] = utils.regulation_meta(reg_part, version) context['version_switch_view'] = self.version_switch_view context['diff_redirect_label'] = self.diff_redirect_label( context['label_id'], toc)
def regulation(request, label_id): context = {} current_version, new_version = get_versions(label_id) if new_version: context["new_version"] = new_version context["current_version"] = current_version context["label_id"] = label_id context["reg_first_section"] = utils.first_section(label_id, current_version["version"]) context["reg_part"] = label_id.split("-")[0] context["meta"] = utils.regulation_meta(label_id, current_version["version"]) c = RequestContext(request, context) t = select_template( ["regulations/landing_%s.html" % label_id, "regulations/landing_base.html", "regulations/generic_landing.html"] ) return HttpResponse(t.render(c))
def new_cfr_part(self, amendment): """While processing an amendment, if it refers to a CFR part which hasn't been seen before, we need to perform some accounting, fetching related meta data, etc.""" part = amendment["cfr_part"] if part not in self.version_info: logger.warning("No version info for %s", part) else: meta = utils.regulation_meta(part, self.version_info[part]["right"]) flat_toc = fetch_toc(part, self.version_info[part]["right"], flatten=True) self.section_titles = {elt["index"][1]: elt["title"] for elt in flat_toc if len(elt["index"]) == 2} self.current_part = ToCPart( title=meta.get("cfr_title_number"), part=part, name=meta.get("statutory_name"), sections=[], authority_url=reverse("cfr_changes", kwargs={"doc_number": self.doc_number, "section": part}), ) self.current_section = None self.toc.append(self.current_part)
def get_regulations_list(all_versions): """ Given a list of regulation versions, add data about those regulations to that list. """ regs = [] reg_parts = sorted(all_versions.keys()) for part in reg_parts: version = all_versions.get(part)[0]['version'] reg_meta = utils.regulation_meta(part, version, True) first_section = utils.first_section(part, version) amendments = filter_future_amendments(all_versions.get(part, None)) reg = {'part': part, 'meta': reg_meta, 'reg_first_section': first_section, 'amendments': amendments} regs.append(reg) return regs
def get_regulations_list(all_versions): """ Given a list of regulation versions, add data about those regulations to that list. """ regs = [] reg_parts = sorted(all_versions.keys(), key=utils.make_sortable) for part in reg_parts: version = all_versions[part][0]['version'] reg_meta = utils.regulation_meta(part, version) first_section = utils.first_section(part, version) amendments = filter_future_amendments(all_versions.get(part, None)) reg = {'part': part, 'meta': reg_meta, 'reg_first_section': first_section, 'amendments': amendments} regs.append(reg) return regs
def set_chrome_context(self, context, reg_part, version): context['reg_part'] = reg_part context['history'] = fetch_grouped_history(reg_part) toc = fetch_toc(reg_part, version) for el in toc: el['url'] = SectionUrl().of(el['index'], version, self.partial_class.sectional_links) for sub in el.get('sub_toc', []): sub['url'] = SectionUrl().of( sub['index'], version, self.partial_class.sectional_links) context['TOC'] = toc context['meta'] = utils.regulation_meta(reg_part, version) # Throw 404 if regulation doesn't exist if not context['meta']: raise error_handling.MissingContentException() context['version_span'] = version_span( context['history'], context['meta']['effective_date']) context['version_switch_view'] = self.version_switch_view context['diff_redirect_label'] = self.diff_redirect_label( context['label_id'], toc)
def set_chrome_context(self, context, reg_part, version): context['reg_part'] = reg_part context['history'] = fetch_grouped_history(reg_part) toc = fetch_toc(reg_part, version) for el in toc: el['url'] = SectionUrl().of( el['index'], version, self.partial_class.sectional_links) for sub in el.get('sub_toc', []): sub['url'] = SectionUrl().of( sub['index'], version, self.partial_class.sectional_links) context['TOC'] = toc context['meta'] = utils.regulation_meta(reg_part, version) # Throw 404 if regulation doesn't exist if not context['meta']: raise error_handling.MissingContentException() context['version_span'] = version_span( context['history'], context['meta']['effective_date']) context['version_switch_view'] = self.version_switch_view context['diff_redirect_label'] = self.diff_redirect_label( context['label_id'], toc)
def test_regulation_meta_404(self, api_reader): """We shouldn't crash if meta data isn't available""" ret_vals = [None, {}, {"111-22": "something"}] for ret_val in ret_vals: api_reader.ApiReader.return_value.layer.return_value = ret_val self.assertEqual({}, utils.regulation_meta("111", "vvv"))
def test_regulation_meta_404(self, api_reader): """We shouldn't crash if meta data isn't available""" ret_vals = [None, {}, {'111-22': 'something'}] for ret_val in ret_vals: api_reader.ApiReader.return_value.layer.return_value = ret_val self.assertEqual({}, utils.regulation_meta('111', 'vvv'))