def regtext_changes_context(cls, amendments, version_info, label_id,
                                doc_number, toc_position):
        """Generate diffs for the changed section"""
        cfr_part = label_id.split('-')[0]
        relevant = []
        for amd in amendments:
            changes = amd.get('changes', [])
            keys = {change[0] for change in changes}
            if any(is_contained_in(key, label_id) for key in keys):
                relevant.append(amd)

        versions = Versions(version_info[cfr_part]['left'],
                            version_info[cfr_part]['right'])
        left_tree = ApiReader().regulation(label_id, versions.older)
        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 = CFRChangeHTMLBuilder(layers,
                                       diff_applier,
                                       id_prefix=[str(doc_number), 'cfr'],
                                       index_prefix=[1, toc_position])
        builder.tree = left_tree or {}
        builder.generate_html()

        return {
            'instructions': [a['instruction'] for a in relevant],
            'subparts':
            list(cls.subpart_changes(doc_number, relevant, label_id)),
            'tree': builder.tree,
        }
Exemple #2
0
    def regtext_changes_context(cls, amendments, version_info, label_id,
                                doc_number, toc_position):
        """Generate diffs for the changed section"""
        cfr_part = label_id.split('-')[0]
        relevant = []
        for amd in amendments:
            changes = amd.get('changes', [])
            keys = {change[0] for change in changes}
            if any(is_contained_in(key, label_id) for key in keys):
                relevant.append(amd)

        versions = Versions(version_info[cfr_part]['left'],
                            version_info[cfr_part]['right'])
        left_tree = ApiReader().regulation(label_id, versions.older)
        appliers = get_appliers(label_id, versions)

        builder = CFRChangeHTMLBuilder(
            *appliers, id_prefix=[str(doc_number), 'cfr'],
            index_prefix=[1, toc_position]
        )
        builder.tree = left_tree or {}
        builder.generate_html()

        return {
            'instructions': [a['instruction'] for a in relevant],
            'subparts': list(cls.subpart_changes(doc_number, relevant,
                                                 label_id)),
            'tree': builder.tree,
        }
Exemple #3
0
    def regtext_changes_context(amendments, version_info, label_id,
                                doc_number):
        """Generate diffs for the changed section"""
        cfr_part = label_id.split('-')[0]
        relevant = []
        for amd in amendments:
            changes = amd.get('changes', [])
            if isinstance(changes, dict):
                changes = list(changes.items())
            keys = {change[0] for change in changes}
            if any(is_contained_in(key, label_id) for key in keys):
                relevant.append(amd)

        versions = Versions(version_info[cfr_part]['left'],
                            version_info[cfr_part]['right'])
        tree = ApiReader().regulation(label_id, versions.older)
        appliers = get_appliers(label_id, versions)

        builder = CFRChangeHTMLBuilder(*appliers,
                                       id_prefix=[str(doc_number), 'cfr'])
        builder.tree = tree
        builder.generate_html()
        return {
            'instructions': [a['instruction'] for a in relevant],
            'tree': builder.tree
        }
Exemple #4
0
 def apply_layer(self, text_index):
     """
     Return a tuple of 'footnotes' and collection of footnotes.
     Footnotes are "collected" from the node and its children.
     .. note::
        This does not handle the case where the same note reference
        is used in multiple children.
     """
     footnotes = []
     for label in self.layer.keys():
         if is_contained_in(label, text_index):
             footnotes += [x["footnote_data"] for x in self.layer[label] if "footnote_data" in x]
     return "footnotes", sorted(footnotes, key=lambda x: x["ref"])
 def attach_metadata(self, node):
     """
     Return a tuple of 'footnotes' and collection of footnotes.
     Footnotes are "collected" from the node and its children.
     .. note::
        This does not handle the case where the same note reference
        is used in multiple children.
     """
     footnotes = []
     for label in self.layer.keys():
         if is_contained_in(label, node['label_id']):
             footnotes += [x['footnote_data']
                           for x in self.layer[label]
                           if 'footnote_data' in x]
     node['footnotes'] = list(sorted(footnotes, key=lambda x: x['ref']))
 def apply_layer(self, text_index):
     """
     Return a tuple of 'footnotes' and collection of footnotes.
     Footnotes are "collected" from the node and its children.
     .. note::
        This does not handle the case where the same note reference
        is used in multiple children.
     """
     footnotes = []
     for label in self.layer.keys():
         if is_contained_in(label, text_index):
             footnotes += [
                 x['footnote_data'] for x in self.layer[label]
                 if 'footnote_data' in x
             ]
     return 'footnotes', sorted(footnotes, key=lambda x: x['ref'])
Exemple #7
0
    def regtext_changes_context(amendments, version_info, label_id,
                                doc_number):
        """Generate diffs for the changed section"""
        cfr_part = label_id.split('-')[0]
        relevant = []
        for amd in amendments:
            changes = amd.get('changes', [])
            if isinstance(changes, dict):
                changes = list(changes.items())
            keys = {change[0] for change in changes}
            if any(is_contained_in(key, label_id) for key in keys):
                relevant.append(amd)

        versions = Versions(version_info[cfr_part]['left'],
                            version_info[cfr_part]['right'])
        tree = ApiReader().regulation(label_id, versions.older)
        appliers = get_appliers(label_id, versions)

        builder = CFRChangeHTMLBuilder(
            *appliers, id_prefix=[str(doc_number), 'cfr'])
        builder.tree = tree
        builder.generate_html()
        return {'instructions': [a['instruction'] for a in relevant],
                'tree': builder.tree}
 def test_is_contained_in(self):
     self.assertTrue(utils.is_contained_in('22-51-12', '22-51'))
     self.assertTrue(utils.is_contained_in('22-51-13', '22-51'))
     self.assertTrue(utils.is_contained_in('22-51', '22-51'))
     self.assertFalse(utils.is_contained_in('22-512', '22-51'))