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.

64 lines
1.9 KiB

10 years ago
10 years ago
10 years ago
  1. from django import forms
  2. from hc.front.validators import (CronExpressionValidator, TimezoneValidator,
  3. WebhookValidator)
  4. class NameTagsForm(forms.Form):
  5. name = forms.CharField(max_length=100, required=False)
  6. tags = forms.CharField(max_length=500, required=False)
  7. def clean_tags(self):
  8. result = []
  9. for part in self.cleaned_data["tags"].split(" "):
  10. part = part.strip()
  11. if part != "":
  12. result.append(part)
  13. return " ".join(result)
  14. class TimeoutForm(forms.Form):
  15. timeout = forms.IntegerField(min_value=60, max_value=2592000)
  16. grace = forms.IntegerField(min_value=60, max_value=2592000)
  17. class CronForm(forms.Form):
  18. schedule = forms.CharField(required=False, max_length=100,
  19. validators=[CronExpressionValidator()])
  20. tz = forms.CharField(required=False, max_length=36,
  21. validators=[TimezoneValidator()])
  22. grace = forms.IntegerField(min_value=1, max_value=43200)
  23. class AddPdForm(forms.Form):
  24. error_css_class = "has-error"
  25. value = forms.CharField(max_length=32)
  26. class AddOpsGenieForm(forms.Form):
  27. error_css_class = "has-error"
  28. value = forms.CharField(max_length=40)
  29. class AddEmailForm(forms.Form):
  30. error_css_class = "has-error"
  31. value = forms.EmailField(max_length=100)
  32. class AddUrlForm(forms.Form):
  33. error_css_class = "has-error"
  34. value = forms.URLField(max_length=1000, validators=[WebhookValidator()])
  35. class AddWebhookForm(forms.Form):
  36. error_css_class = "has-error"
  37. value_down = forms.URLField(max_length=1000, required=False,
  38. validators=[WebhookValidator()])
  39. value_up = forms.URLField(max_length=1000, required=False,
  40. validators=[WebhookValidator()])
  41. def get_value(self):
  42. return "{value_down}\n{value_up}".format(**self.cleaned_data)