<commit_before>from django.http import HttpRequest

#   Don't import PartialInterpView directly; this will cause an import cycle
from regulations import views
from regulations.generator.node_types import to_markup_id


class InterpretationsLayer(object):
    """Fetches the (rendered) interpretation for this node, if available"""
    shorthand = 'interp'

    def __init__(self, layer, version=None):
        self.layer = layer
        self.version = version

    def apply_layer(self, text_index):
        """Return a pair of field-name + interpretation if one applies."""
        if text_index in self.layer and self.layer[text_index]:
            layer_element = self.layer[text_index][0]
            reference = layer_element['reference']

            partial_view = views.partial.PartialInterpView.as_view(inline=True)
            request = HttpRequest()
            request.GET['layers'] = 'terms,graphics,internal,keyterms,paragraph'
            request.method = 'GET'
            response = partial_view(request, label_id=reference,
                                    version=self.version)
            response.render()

            context = {
                'for_markup_id': text_index,
                'label_id': reference,
                'markup': response.content,
            }

            #  exclude 'Interp'
            ref_parts = reference.split('-')[:-1]
            context['section_id'] = '%s-Interp' % ref_parts[0]

            if len(ref_parts) == 2:
                #  Part-Section/Appendix
                context['label'] = ref_parts[1]
            elif ref_parts[1].isalpha():
                #  Part-Appendix-Segment
                context['label'] = '-'.join(ref_parts[1:])
            else:
                #  Part-Section-Paragraphs
                context['label'] = (ref_parts[1] + '('
                                    + ')('.join(ref_parts[2:]) + ')')

            return 'interp', context
<commit_msg>Remove graphics from interpretations slide down<commit_after>from django.http import HttpRequest

#   Don't import PartialInterpView directly; this will cause an import cycle
from regulations import views
from regulations.generator.node_types import to_markup_id


class InterpretationsLayer(object):
    """Fetches the (rendered) interpretation for this node, if available"""
    shorthand = 'interp'

    def __init__(self, layer, version=None):
        self.layer = layer
        self.version = version

    def apply_layer(self, text_index):
        """Return a pair of field-name + interpretation if one applies."""
        if text_index in self.layer and self.layer[text_index]:
            layer_element = self.layer[text_index][0]
            reference = layer_element['reference']

            partial_view = views.partial.PartialInterpView.as_view(inline=True)
            request = HttpRequest()
            request.GET['layers'] = 'terms,internal,keyterms,paragraph'
            request.method = 'GET'
            response = partial_view(request, label_id=reference,
                                    version=self.version)
            response.render()

            context = {
                'for_markup_id': text_index,
                'label_id': reference,
                'markup': response.content,
            }

            #  exclude 'Interp'
            ref_parts = reference.split('-')[:-1]
            context['section_id'] = '%s-Interp' % ref_parts[0]

            if len(ref_parts) == 2:
                #  Part-Section/Appendix
                context['label'] = ref_parts[1]
            elif ref_parts[1].isalpha():
                #  Part-Appendix-Segment
                context['label'] = '-'.join(ref_parts[1:])
            else:
                #  Part-Section-Paragraphs
                context['label'] = (ref_parts[1] + '('
                                    + ')('.join(ref_parts[2:]) + ')')

            return 'interp', context

{'fraction_non_alphanumeric': 0.1095225938218024, 'fraction_numerical': 0.004595353586928772, 'mean_word_length': 1.9636913767019668, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1084534', 'n_tokens_mistral': 1069, 'n_tokens_neox': 1013, 'n_words': 227}