You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
807 B

  1. from datetime import datetime as dt
  2. from django import forms
  3. from django.core.exceptions import ValidationError
  4. import pytz
  5. class TimestampField(forms.Field):
  6. def to_python(self, value):
  7. if value is None:
  8. return None
  9. try:
  10. value_int = int(value)
  11. except ValueError:
  12. raise ValidationError(message="Must be an integer")
  13. # 10000000000 is year 2286 (a sanity check)
  14. if value_int < 0 or value_int > 10000000000:
  15. raise ValidationError(message="Out of bounds")
  16. return dt.fromtimestamp(value_int, pytz.UTC)
  17. class FlipsFiltersForm(forms.Form):
  18. start = TimestampField(required=False)
  19. end = TimestampField(required=False)
  20. seconds = forms.IntegerField(required=False, min_value=0, max_value=31536000)