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.

66 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(max_length=100,
  19. validators=[CronExpressionValidator()])
  20. tz = forms.CharField(max_length=36, validators=[TimezoneValidator()])
  21. grace = forms.IntegerField(min_value=1, max_value=43200)
  22. class AddPdForm(forms.Form):
  23. error_css_class = "has-error"
  24. value = forms.CharField(max_length=32)
  25. class AddOpsGenieForm(forms.Form):
  26. error_css_class = "has-error"
  27. value = forms.CharField(max_length=40)
  28. class AddEmailForm(forms.Form):
  29. error_css_class = "has-error"
  30. value = forms.EmailField(max_length=100)
  31. class AddUrlForm(forms.Form):
  32. error_css_class = "has-error"
  33. value = forms.URLField(max_length=1000, validators=[WebhookValidator()])
  34. class AddWebhookForm(forms.Form):
  35. error_css_class = "has-error"
  36. value_down = forms.URLField(max_length=1000, required=False,
  37. validators=[WebhookValidator()])
  38. value_up = forms.URLField(max_length=1000, required=False,
  39. validators=[WebhookValidator()])
  40. post_data = forms.CharField(max_length=1000, required=False)
  41. def get_value(self):
  42. d = self.cleaned_data
  43. return "\n".join((d["value_down"], d["value_up"], d["post_data"]))