Module: check_mk
Branch: master
Commit: c4b2c16cce98e6dcfdaf39988d0fd9ce0a45aa42
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=c4b2c16cce98e6…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Mon Jan 9 15:02:11 2012 +0100
New ValueSpec for EmailAddress
---
web/htdocs/valuespec.py | 17 ++++++++++++++++-
1 files changed, 16 insertions(+), 1 deletions(-)
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index 8c0fa99..cbefb10 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -24,7 +24,7 @@
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
-import math, os, time
+import math, os, time, re
from lib import *
# Abstract base class of all value declaration classes.
@@ -242,6 +242,21 @@ class TextAscii(ValueSpec):
if not self._allow_empty and value.strip() == "":
raise MKUserError(varprefix, _("An empty value is not allowed
here."))
+
+class EmailAddress(TextAscii):
+ def __init__(self, **kwargs):
+ TextAscii.__init__(self, **kwargs)
+ self._re_email = re.compile('^[A-Z0-9._%+-]+(a)[A-Z0-9.-]+\.[A-Z]{2,4}$'4}$',
re.I)
+
+ def value_to_text(self, value):
+ return '<a href="mailto:%s">%s</a>' % (value,
value)
+
+ def validate_value(self, value, varprefix):
+ TextAscii.validate_value(self, value, varprefix)
+ if value:
+ if not self._re_email.match(value):
+ raise MKUserError(varprefix, _("You entered an invalid email
address."))
+
class TextUnicode(TextAscii):
def __init__(self, **kwargs):
TextAscii.__init__(self, **kwargs)