forms.py 1.2 KB

123456789101112131415161718192021
  1. from datetime import timedelta
  2. import floppyforms as forms
  3. from django.utils import timezone as tz
  4. from django.utils.translation import ugettext_lazy as _
  5. from misago.forms import Form
  6. class GenerateStatisticsForm(Form):
  7. provider_model = forms.ChoiceField(label=_('Report Type'),
  8. help_text=_('Select statistics provider.'))
  9. date_start = forms.DateField(label=_('Time Period'),
  10. help_text=_('Enter start and end date for time period you want to take data from to use in graph.'),
  11. initial=tz.now() - timedelta(days=7))
  12. date_end = forms.DateField(initial=tz.now())
  13. stats_precision = forms.ChoiceField(label=_('Graph Precision'),
  14. choices=(('day', _('For each day')), ('week', _('For each week')), ('month', _('For each month')), ('year', _('For each year'))))
  15. def __init__(self, *args, **kwargs):
  16. provider_choices = kwargs.get('provider_choices')
  17. del kwargs['provider_choices']
  18. super(GenerateStatisticsForm, self).__init__(*args, **kwargs)
  19. self.fields['provider_model'] = forms.ChoiceField(choices=provider_choices)