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.

71 lines
2.1 KiB

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