<commit_before>from django import forms

from .models import Resource, Volunteer


class VolunteerForm(forms.ModelForm):
    class Meta:
        model = Volunteer
        fields = ('real_name', 'email_address', 'phone_number')
        labels = {'real_name': '<NAME>'}

    def __init__(self, *args, **kwargs):
        resources = kwargs.pop('resources')
        super().__init__(*args, **kwargs)

        for resource in resources:
            if resource.visible:
                resource_type = Resource.Type(resource.type)
                if resource_type == Resource.Type.boolean:
                    field = forms.BooleanField(required=False)
                else:
                    attrs = {
                        'min': resource.min_value,
                        'max': resource.max_value
                    }

                    if resource.max_value - resource.min_value <= 20:
                        attrs['type'] = 'range'

                    widget = forms.NumberInput(attrs=attrs)

                    field = forms.IntegerField(min_value=resource.min_value,
                                               max_value=resource.max_value,
                                               widget=widget,
                                               initial=str(resource.default_value))

            else:
                # field = forms.
                field.widget = forms.HiddenInput()
                field.value = resource.default_value

            field.label = resource.name

            self.fields[self.get_id_for_resource(resource)] = field

        for field in self.fields.values():
            field.widget.attrs['class'] = 'form-control'

    def get_id_for_resource(self, resource):
        return 'q{}'.format(resource.id)
<commit_msg>change max to target as per spec<commit_after>from django import forms

from .models import Resource, Volunteer


class VolunteerForm(forms.ModelForm):
    class Meta:
        model = Volunteer
        fields = ('real_name', 'email_address', 'phone_number')
        labels = {'real_name': '<NAME>'}

    def __init__(self, *args, **kwargs):
        resources = kwargs.pop('resources')
        super().__init__(*args, **kwargs)

        for resource in resources:
            if resource.visible:
                resource_type = Resource.Type(resource.type)
                if resource_type == Resource.Type.boolean:
                    field = forms.BooleanField(required=False)
                else:
                    attrs = {
                        'min': resource.min_value,
                        'target': resource.target_value
                    }

                    if resource.target_value - resource.min_value <= 20:
                        attrs['type'] = 'range'

                    widget = forms.NumberInput(attrs=attrs)

                    field = forms.IntegerField(min_value=resource.min_value,
                                               target_value=resource.target_value,
                                               widget=widget,
                                               initial=str(resource.default_value))

            else:
                # field = forms.
                field.widget = forms.HiddenInput()
                field.value = resource.default_value

            field.label = resource.name

            self.fields[self.get_id_for_resource(resource)] = field

        for field in self.fields.values():
            field.widget.attrs['class'] = 'form-control'

    def get_id_for_resource(self, resource):
        return 'q{}'.format(resource.id)

{'fraction_non_alphanumeric': 0.09457190822607722, 'fraction_numerical': 0.001119194180190263, 'mean_word_length': 1.4706288873531443, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7176764', 'n_tokens_mistral': 879, 'n_tokens_neox': 818, 'n_words': 174}