Validate constitution_url (ASA-#76)
authorAlex Dehnert <adehnert@mit.edu>
Mon, 10 Sep 2012 08:50:40 +0000 (04:50 -0400)
committerAlex Dehnert <adehnert@mit.edu>
Mon, 10 Sep 2012 08:50:40 +0000 (04:50 -0400)
__init__.py

index d0f6993c2df941ae3b4bcc6f890e4a7f18653d85..62ec848eea86c20692bfbdd13bf0bafa15b4a54d 100644 (file)
@@ -9,6 +9,8 @@ from django.contrib.auth import REDIRECT_FIELD_NAME
 from django.http import HttpResponseRedirect
 from django.contrib import auth
 from django.core.exceptions import ObjectDoesNotExist
+from django.core.validators import URLValidator, ValidationError
+
 import settings
 
 def zephyr(msg, clas='message', instance='log', rcpt='nobody',):
@@ -18,6 +20,15 @@ def zephyr(msg, clas='message', instance='log', rcpt='nobody',):
     )
     proc.communicate(msg)
 
+def UrlOrAfsValidator(value):
+    if value.startswith('/mit/') or value.startswith('/afs/'):
+        return
+    else:
+        try:
+            URLValidator()(value)
+        except ValidationError:
+            raise ValidationError('Provide a valid URL or AFS path')
+
 class ScriptsRemoteUserMiddleware(RemoteUserMiddleware):
     header = 'SSL_CLIENT_S_DN_Email'