<commit_before>from django import forms
from molly.conf import all_apps

APPLICATION_CHOICES = (
    ('', 'Show all'),
) + tuple((app.local_name, app.title) for app in all_apps())

class SearchForm(forms.Form):
    query = forms.CharField(label='Search')
    application = forms.ChoiceField(
        label='Filter',
        widget=forms.HiddenInput(),
        choices=APPLICATION_CHOICES,
        required=False,
    )<commit_msg>Applications for validating in the search form are now picked up when a SearchForm is initialized, not at server start-up (removing a circular import dependency).<commit_after>from django import forms
from molly.conf import all_apps

class SearchForm(object):
    def __new__(cls, *args, **kwargs):
        try:
            return cls._search_form_class(*args, **kwargs)
        except AttributeError:
            cls._search_form_class = cls._get_search_form_class()
            return cls._search_form_class(*args, **kwargs)

    @classmethod
    def _get_search_form_class(cls):
        APPLICATION_CHOICES = (
            ('', 'Show all'),
        ) + tuple((app.local_name, app.title) for app in all_apps() if app.application_name)

        class SearchForm(forms.Form):
            query = forms.CharField(label='Search')
            application = forms.ChoiceField(
                label='Filter',
                widget=forms.HiddenInput(),
                choices=APPLICATION_CHOICES,
                required=False,
            )

        return SearchForm
{'fraction_non_alphanumeric': 0.09893048128342247, 'fraction_numerical': 0.0, 'mean_word_length': 2.733167082294264, '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': '6624176', 'n_tokens_mistral': 419, 'n_tokens_neox': 404, 'n_words': 102}