<commit_before>from django import forms
from django.utils.translation import ugettext_lazy as _

from .models import Organisation, GERMAN_STATES


class OrganisationSearchForm(forms.Form):
    q = forms.CharField(
        required=False,
        label=_('Search'),
        widget=forms.TextInput(
            attrs={
                'type': 'search',
                'class': 'form-control',
                'placeholder': _('e.g. Polizeisport')
            }))

    amount_gte = forms.IntegerField(
        required=False,
        widget=forms.HiddenInput)

    amount_lte = forms.IntegerField(
        required=False,
        widget=forms.HiddenInput)

    state = forms.ChoiceField(
        choices=GERMAN_STATES,
        required=False,
        widget=forms.HiddenInput)

    treasury = forms.TypedChoiceField(
        label=_('Include treasury'),
        choices=[
            ('0', _('Exclude treasury')),
            ('', 'Include treasury'),
            ('1', _('Only treasury')),
        ],
        empty_value=None,
        required=False,
        coerce=lambda x: bool(int(x))
    )

    year = forms.TypedChoiceField(
        choices=(
            (2007, '2007'),
            (2008, '2008'),
            (2009, '2009'),
            (2010, '2010'),
            (2011, '2011'),
            (2012, '2012'),
            (2013, '2013'),
            (2014, '2014')
        ),
        required=False,
        coerce=int,
        empty_value='',
        widget=forms.HiddenInput)

    def __init__(self, data, **kwargs):
        data = data.copy()
        super(OrganisationSearchForm, self).__init__(data=data, **kwargs)

    def _search(self, query):
        return Organisation.objects.search(
            query=self.cleaned_data.get('q'),
            state=self.cleaned_data.get('state'),
            year=self.cleaned_data.get('year'),
            treasury=self.cleaned_data.get('treasury'),
            amount__gte=self.cleaned_data.get('amount_gte'),
            amount__lte=self.cleaned_data.get('amount_lte')
        )

    def search(self):
        if not self.is_valid():
            return Organisation.objects.all(), {}

        sqs = self._search(self.cleaned_data['q'])

        return sqs
<commit_msg>Make exclude treasury default option<commit_after>from django import forms
from django.utils.translation import ugettext_lazy as _

from .models import Organisation, GERMAN_STATES


class OrganisationSearchForm(forms.Form):
    q = forms.CharField(
        required=False,
        label=_('Search'),
        widget=forms.TextInput(
            attrs={
                'type': 'search',
                'class': 'form-control',
                'placeholder': _('e.g. Polizeisport')
            }))

    amount_gte = forms.IntegerField(
        required=False,
        widget=forms.HiddenInput)

    amount_lte = forms.IntegerField(
        required=False,
        widget=forms.HiddenInput)

    state = forms.ChoiceField(
        choices=GERMAN_STATES,
        required=False,
        widget=forms.HiddenInput)

    treasury = forms.TypedChoiceField(
        label=_('Include treasury'),
        choices=[
            ('0', _('Exclude treasury')),
            ('-', _('Include treasury')),
            ('1', _('Only treasury')),
        ],
        initial=False,
        empty_value=None,
        required=False,
        coerce=lambda x: None if x == '-' else bool(int(x))
    )

    year = forms.TypedChoiceField(
        choices=(
            (2007, '2007'),
            (2008, '2008'),
            (2009, '2009'),
            (2010, '2010'),
            (2011, '2011'),
            (2012, '2012'),
            (2013, '2013'),
            (2014, '2014')
        ),
        required=False,
        coerce=int,
        empty_value='',
        widget=forms.HiddenInput)

    def __init__(self, data, **kwargs):
        data = data.copy()
        super(OrganisationSearchForm, self).__init__(data=data, **kwargs)

    def _search(self, query):
        return Organisation.objects.search(
            query=self.cleaned_data.get('q'),
            state=self.cleaned_data.get('state'),
            year=self.cleaned_data.get('year'),
            treasury=self.cleaned_data.get('treasury'),
            amount__gte=self.cleaned_data.get('amount_gte'),
            amount__lte=self.cleaned_data.get('amount_lte')
        )

    def search(self):
        if not self.is_valid():
            return Organisation.objects.all(), {}

        sqs = self._search(self.cleaned_data['q'])

        return sqs

{'fraction_non_alphanumeric': 0.13247673903411608, 'fraction_numerical': 0.02924235711120957, 'mean_word_length': 1.99800796812749, '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': '497633', 'n_tokens_mistral': 1422, 'n_tokens_neox': 1302, 'n_words': 237}