Copy the link_name regex patterns into linkable.py, in preparation for
authorTodd Larsen <tlarsen@google.com>
Wed, 12 Nov 2008 07:28:12 +0000
changeset 475 8bd9db1d7a30
parent 474 0bf5af57cef9
child 476 3b0662786f95
Copy the link_name regex patterns into linkable.py, in preparation for removing them from path_link_name.py (eventually). Patch by: Todd Larsen
app/soc/models/linkable.py
--- a/app/soc/models/linkable.py	Tue Nov 11 21:07:38 2008 +0000
+++ b/app/soc/models/linkable.py	Wed Nov 12 07:28:12 2008 +0000
@@ -21,6 +21,8 @@
 ]
 
 
+import re
+
 from google.appengine.ext import db
 
 from django.utils.translation import ugettext_lazy
@@ -28,6 +30,21 @@
 from soc.models import base
 
 
+# start with ASCII digit or lowercase
+#   (additional ASCII digit or lowercase
+#     -OR-
+#   underscore and ASCII digit or lowercase)
+#     zero or more of OR group
+#
+# * starting or ending underscores are *not* permitted
+# * double internal underscores are *not* permitted
+#
+LINK_ID_PATTERN_CORE = r'[0-9a-z](?:[0-9a-z]|_[0-9a-z])*'
+LINK_ID_ARG_PATTERN = r'(?P<link_id>%s)' % LINK_ID_PATTERN_CORE
+LINK_ID_PATTERN = r'^%s$' % LINK_ID_PATTERN_CORE
+LINK_ID_REGEX = re.compile(LINK_ID_PATTERN)
+
+
 class Linkable(base.ModelWithFieldAttributes):
   """A base class for Model classes that are "linkable".
   
@@ -71,12 +88,13 @@
   be allowed. 
   """
   #: Required field storing "ID" used in URLS. Lower ASCII characters,
-  #: digits and underscores only.
+  #: digits and underscores only.  Valid link IDs successfully match
+  #: the LINK_ID_REGEX.
   id = db.StringProperty(required=True,
       verbose_name=ugettext_lazy('Link ID'))
   id.help_text = ugettext_lazy(
       '"ID" used in URLs.'
-      ' Lower ASCII characters, digits and underscores only.')
+      ' Lower ASCII characters, digits, and underscores only.')
 
   #: Optional Self Reference property to another Linkable entity which defines
   #: the "scope" of this Linkable entity. The back-reference in the Linkable