From 58916f2f4e99c38901585f15a5cd280a968e9457 Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Sun, 23 Aug 2009 16:29:07 -0700 Subject: Add a comment name validator. --- quoins/controllers.py | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/quoins/controllers.py b/quoins/controllers.py index e419d40..a3a1c5d 100644 --- a/quoins/controllers.py +++ b/quoins/controllers.py @@ -79,6 +79,33 @@ def send_email(msg, frm, to): s.close() log.info('Sent mail to: %s' % to) +class QuoinsName(validators.FancyValidator): + messages = { + 'percent': 'Names with %% are not permitted', + 'in_use': 'This name is in use', + 'anonymous': 'The name anonymous is not permitted', + 'openid': 'Names beginning with "OpenID" are not permitted', + } + + def _to_python(self, value, state): + # Leading or trailing whitespace in a name is not interesting. + return value.strip() + + def validate_python(self, value, state): + if not value: return None + if '%' in value: + raise validators.Invalid(self.message("percent", state), + value, state) + if DBSession.query(TGUser).filter_by(display_name=value).first(): + raise validators.Invalid(self.message("in_use", state), + value, state) + if value.lower()=='anonymous': + raise validators.Invalid(self.message("anonymous", state), + value, state) + if value.lower().startswith('openid'): + raise validators.Invalid(self.message("openid", state), + value, state) + class SimpleForm(forms.Form): template = """