forms.py 2.46 KB
Newer Older
1 2 3
from django import forms
from dal import autocomplete, forward

Nicolas Joyard's avatar
Nicolas Joyard committed
4
from representatives.models import Chamber, Group
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27


class RepresentativeSearchForm(forms.Form):
    search = forms.CharField(
        required=False,
        label='Name',
        widget=forms.TextInput(attrs={'placeholder': ''})
    )
    scoremin = forms.FloatField(
        required=False,
        label='Between',
        widget=forms.NumberInput(attrs={'placeholder': 'Min. score'})
    )
    scoremax = forms.FloatField(
        required=False,
        label='and',
        widget=forms.NumberInput(attrs={'placeholder': 'Max. score'})
    )
    chamber = forms.ModelChoiceField(
        queryset=Chamber.objects.all(),
        required=False,
        widget=autocomplete.ModelSelect2(
            url='chamber-autocomplete',
28
            attrs={'data-html': 'true'}
29 30 31 32 33 34 35
        )
    )
    country = forms.ModelChoiceField(
        queryset=Group.objects.filter(kind='country'),
        required=False,
        widget=autocomplete.ModelSelect2(
            url='group-autocomplete',
36 37
            forward=(forward.Const('country', 'kind'),),
            attrs={'data-html': 'true'}
38 39 40 41 42 43 44
        )
    )
    party = forms.ModelChoiceField(
        queryset=Group.objects.filter(kind='group'),
        required=False,
        widget=autocomplete.ModelSelect2(
            url='group-autocomplete',
45 46
            forward=(forward.Const('group', 'kind'),),
            attrs={'data-html': 'true'}
47 48 49 50 51 52 53
        )
    )
    committee = forms.ModelChoiceField(
        queryset=Group.objects.filter(kind='committee'),
        required=False,
        widget=autocomplete.ModelSelect2(
            url='group-autocomplete',
54 55
            forward=(forward.Const('committee', 'kind'),),
            attrs={'data-html': 'true'}
56 57 58 59 60 61 62
        )
    )
    delegation = forms.ModelChoiceField(
        queryset=Group.objects.filter(kind='delegation'),
        required=False,
        widget=autocomplete.ModelSelect2(
            url='group-autocomplete',
63 64
            forward=(forward.Const('delegation', 'kind'),),
            attrs={'data-html': 'true'}
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
        )
    )


class DossierSearchForm(forms.Form):
    search = forms.CharField(
        required=False,
        label='Name',
        widget=forms.TextInput(attrs={'placeholder': ''})
    )
    chamber = forms.ModelChoiceField(
        queryset=Chamber.objects.all(),
        required=False,
        widget=autocomplete.ModelSelect2(
            url='chamber-autocomplete',
80
            attrs={'data-html': 'true'}
81 82
        )
    )