diff options
author | Palaparthy Adityachandra | 2020-08-15 11:43:46 +0530 |
---|---|---|
committer | GitHub | 2020-08-15 11:43:46 +0530 |
commit | f8972ccd73c598cf0b0f20f13b4b8cf2179719e3 (patch) | |
tree | 47ad199e95c7b11ee4752c23a4cc04155872b580 /statistics_app/forms.py | |
parent | f4ce8c9e3f20d0d4c873bfb8b0dd4d83ac0b8a58 (diff) | |
parent | 7d750d0559d4ff027900e58609cce842f07795b9 (diff) | |
download | workshop_booking-f8972ccd73c598cf0b0f20f13b4b8cf2179719e3.tar.gz workshop_booking-f8972ccd73c598cf0b0f20f13b4b8cf2179719e3.tar.bz2 workshop_booking-f8972ccd73c598cf0b0f20f13b4b8cf2179719e3.zip |
Merge pull request #158 from FOSSEE/fix_stats
Fix statistics app
Diffstat (limited to 'statistics_app/forms.py')
-rw-r--r-- | statistics_app/forms.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/statistics_app/forms.py b/statistics_app/forms.py new file mode 100644 index 0000000..16d79c8 --- /dev/null +++ b/statistics_app/forms.py @@ -0,0 +1,49 @@ +# Django imports +from django import forms + +# Local Imports +from workshop_app.models import states, WorkshopType + + +class FilterForm(forms.Form): + from_date = forms.DateField( + widget=forms.DateInput( + attrs={'type': 'date', 'class': 'form-control'} + ) + ) + to_date = forms.DateField( + widget=forms.DateInput( + attrs={'type': 'date', 'class': 'form-control'} + ) + ) + workshop_type = forms.ModelChoiceField( + queryset=WorkshopType.objects.all(), required=False, + widget=forms.Select(attrs={'class': 'form-control'}) + ) + state = forms.ChoiceField( + choices=states, required=False, + widget=forms.Select(attrs={'class': 'form-control'}) + ) + show_workshops = forms.BooleanField( + help_text="Show my workshops only", required=False, + ) + sort = forms.ChoiceField( + choices=(("date", "Oldest"), ("-date", "Latest")), + help_text="Sort by", + widget=forms.Select(attrs={'class': 'form-control'}) + ) + def __init__(self, *args, **kwargs): + start = kwargs.pop("start") if "start" in kwargs else None + end = kwargs.pop("end") if "end" in kwargs else None + selected_state = kwargs.pop("state") if "state" in kwargs else None + selected_type = kwargs.pop("type") if "type" in kwargs else None + show_workshops = (kwargs.pop("show_workshops") + if "show_workshops" in kwargs else None) + sort = kwargs.pop("sort") if "sort" in kwargs else None + super(FilterForm, self).__init__(*args, **kwargs) + self.fields["from_date"].initial = start + self.fields["to_date"].initial = end + self.fields["state"].initial = selected_state + self.fields["workshop_type"].initial = selected_type + self.fields["show_workshops"].initial = show_workshops + self.fields["sort"].initial = sort |