<commit_before>from django import forms
from sciences.models import Science


def _science_choices(queryset, prefix=''):
    choices = []
    for science in queryset:
        choices.append((science.id, prefix+science.__str__()))
        res = _science_choices(science.sub_science.all(), prefix=prefix+'-')
        choices = choices + res
    return choices


class ScienceModelForm(forms.ModelForm):

    def __init__(self, *args, **kwargs):
        super(ScienceModelForm, self).__init__(*args, **kwargs)
        sciences = Science.objects.filter(primary_science=True)
        choices = _science_choices(sciences)
        self.fields["sciences"].choices = choices<commit_msg>science sorted by name in _science_choices<commit_after>from django import forms
from sciences.models import Science


def _science_choices(queryset, prefix=''):
    choices = []
    queryset = sorted(queryset, key=lambda science: science.name)
    for science in queryset:
        choices.append((science.id, prefix+science.__str__()))
        res = _science_choices(science.sub_science.all(), prefix=prefix+'-')
        choices = choices + res
    return choices


class ScienceModelForm(forms.ModelForm):

    def __init__(self, *args, **kwargs):
        super(ScienceModelForm, self).__init__(*args, **kwargs)
        sciences = Science.objects.filter(primary_science=True)
        choices = _science_choices(sciences)
        self.fields["sciences"].choices = choices
{'fraction_non_alphanumeric': 0.11387163561076605, 'fraction_numerical': 0.0, 'mean_word_length': 3.948805460750853, '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': '3094128', 'n_tokens_mistral': 411, 'n_tokens_neox': 410, 'n_words': 91}