forms.py 1.5 KB

12345678910111213141516171819202122232425262728
  1. from datetime import timedelta
  2. from django import 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()
  8. date_start = forms.DateField(initial=tz.now() - timedelta(days=7))
  9. date_end = forms.DateField(initial=tz.now())
  10. stats_precision = forms.ChoiceField(choices=(('day', _('For each day')), ('week', _('For each week')), ('month', _('For each month')), ('year', _('For each year'))))
  11. layout = (
  12. (None, (
  13. ('provider_model', {'label': _('Report Type'), 'help_text': _('Select statistics provider.')}),
  14. ('nested', (
  15. ('date_start', {'label': _('Time'), 'help_text': _('Enter start and end date for time period you want to take data from to use in graph.'), 'attrs': {'placeholder': _('Start Date: YYYY-MM-DD')}, 'width': 50}),
  16. ('date_end', {'attrs': {'placeholder': _('End Date: YYYY-MM-DD')}, 'width': 50}),
  17. )),
  18. ('stats_precision', {'label': _('Graph Precision')}),
  19. )),
  20. )
  21. def __init__(self, *args, **kwargs):
  22. provider_choices = kwargs.get('provider_choices')
  23. del kwargs['provider_choices']
  24. super(GenerateStatisticsForm, self).__init__(*args, **kwargs)
  25. self.fields['provider_model'] = forms.ChoiceField(choices=provider_choices)