<commit_before>from typing import List, Union

from django import forms
from django.conf import settings
from django.core.exceptions import ValidationError
from django.forms.widgets import FILE_INPUT_CONTRADICTION

from .value import (
    LocalizedFileValue,
    LocalizedIntegerValue,
    LocalizedStringValue,
    LocalizedValue,
)
from .widgets import (
    AdminLocalizedIntegerFieldWidget,
    LocalizedCharFieldWidget,
    LocalizedFieldWidget,
    LocalizedFileWidget,
)


class LocalizedFieldForm(forms.MultiValueField):
    """Form for a localized field, allows editing the field in multiple
    languages."""

    widget = LocalizedFieldWidget
    field_class = forms.fields.CharField
    value_class = LocalizedValue

    def __init__(
        self, *args, required: Union[bool, List[str]] = False, **kwargs
    ):
        """Initializes a new instance of :see:LocalizedFieldForm."""

        fields = []
        """
        Do not print initial value in html in the form of a hidden input. This will result in loss of information
        """
        kwargs["show_hidden_initial"] = False

        for lang_code, _ in settings.LANGUAGES:
            field_options = dict(
                required=required
                if type(required) is bool
                else (lang_code in required),
                label=lang_code,
            )
            fields.append(self.field_class(**field_options))

        super(LocalizedFieldForm, self).__init__(
            fields,
            required=required if type(required) is bool else True,
            require_all_fields=False,
            *args,
            **kwargs
        )

        # set 'required' attribute for each widget separately
        for field, widget in zip(self.fields, self.widget.widgets):<commit_msg>Change from docstring comment to normal<commit_after>from typing import List, Union

from django import forms
from django.conf import settings
from django.core.exceptions import ValidationError
from django.forms.widgets import FILE_INPUT_CONTRADICTION

from .value import (
    LocalizedFileValue,
    LocalizedIntegerValue,
    LocalizedStringValue,
    LocalizedValue,
)
from .widgets import (
    AdminLocalizedIntegerFieldWidget,
    LocalizedCharFieldWidget,
    LocalizedFieldWidget,
    LocalizedFileWidget,
)


class LocalizedFieldForm(forms.MultiValueField):
    """Form for a localized field, allows editing the field in multiple
    languages."""

    widget = LocalizedFieldWidget
    field_class = forms.fields.CharField
    value_class = LocalizedValue

    def __init__(
        self, *args, required: Union[bool, List[str]] = False, **kwargs
    ):
        """Initializes a new instance of :see:LocalizedFieldForm."""

        fields = []

        # Do not print initial value in html in the form of a hidden input. This will result in loss of information
        kwargs["show_hidden_initial"] = False

        for lang_code, _ in settings.LANGUAGES:
            field_options = dict(
                required=required
                if type(required) is bool
                else (lang_code in required),
                label=lang_code,
            )
            fields.append(self.field_class(**field_options))

        super(LocalizedFieldForm, self).__init__(
            fields,
            required=required if type(required) is bool else True,
            require_all_fields=False,
            *args,
            **kwargs
        )

        # set 'required' attribute for each widget separately
        for field, widget in zip(self.fields, self.widget.widgets):
{'fraction_non_alphanumeric': 0.07144858503782572, 'fraction_numerical': 0.0, 'mean_word_length': 2.598790322580645, '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': '1174156', 'n_tokens_mistral': 933, 'n_tokens_neox': 895, 'n_words': 278}