<commit_before>from django import forms

from .models import Content


class DoctypeChoiceField(forms.ChoiceField):
    """Field for choosing amongst the doctypes of a given polymorphic model."""
    def __init__(self, model, exclude_base=False, *args, **kwargs):
        mapping_type_models = model.get_mapping_type_models(exclude_base=exclude_base)
        choices = []
        for mapping_type_name, content_type in mapping_type_models:
            choices.append((mapping_type_name, content_type.name))
        super(DoctypeChoiceField, self).__init__(choices=choices, *args, **kwargs)


class ContentDoctypeForm(forms.Form):
    """Form for choosing a Content subclass doctype."""
    doctype = DoctypeChoiceField(Content, exclude_base=True, label='Type')

<commit_msg>Replaced DoctypeChoiceField with a lazily evaluated function<commit_after>from django import forms
from django.utils.functional import lazy

from .models import Content


def mapping_type_choices(model, exclude_base=True):
    def get_choices():
        mapping_type_models = model.get_mapping_type_models(exclude_base=exclude_base)
        choices = []
        for mapping_type_name, content_type in mapping_type_models:
            choices.append((mapping_type_name, content_type.name))
        return choices
    return get_choices


class ContentDoctypeForm(forms.Form):
    """Form for choosing a Content subclass doctype."""
    doctype = forms.ChoiceField(
        choices=lazy(mapping_type_choices(Content, exclude_base=True), list)(),
        label='Type'
    )


{'fraction_non_alphanumeric': 0.08732212160413971, 'fraction_numerical': 0.0, 'mean_word_length': 4.409090909090909, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4701363', 'n_tokens_mistral': 454, 'n_tokens_neox': 432, 'n_words': 106}