forms.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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)
  26. class SearchSessionsForm(Form):
  27. username = forms.CharField(max_length=255, required=False)
  28. ip_address = forms.CharField(max_length=255, required=False)
  29. useragent = forms.CharField(max_length=255, required=False)
  30. type = forms.ChoiceField(choices=(
  31. ('all', _("All types")),
  32. ('registered', _("Registered Members Sessions")),
  33. ('hidden', _("Hidden Sessions")),
  34. ('guest', _("Guests Sessions")),
  35. ('crawler', _("Crawler Sessions")),
  36. ), required=False)
  37. layout = (
  38. (
  39. _("Search Sessions"),
  40. (
  41. ('ip_address', {'label': _("IP Address"), 'attrs': {'placeholder': _("IP begins with...")}}),
  42. ('username', {'label': _("Username"), 'attrs': {'placeholder': _("Username begings with...")}}),
  43. ('useragent', {'label': _("User Agent"), 'attrs': {'placeholder': _("User Agent contains...")}}),
  44. ('type', {'label': _("Session Type")}),
  45. ),
  46. ),
  47. )