Factor out the getPattern logic from params
authorSverre Rabbelier <srabbelier@gmail.com>
Fri, 30 Jan 2009 22:00:49 +0000
changeset 1094 e143974a6e27
parent 1093 05ac761edb27
child 1095 0122dc66e5d2
Factor out the getPattern logic from params This is to facilitate it's use by the document view later on. Patch by: Sverre Rabbelier
app/soc/views/helper/params.py
--- a/app/soc/views/helper/params.py	Fri Jan 30 22:00:23 2009 +0000
+++ b/app/soc/views/helper/params.py	Fri Jan 30 22:00:49 2009 +0000
@@ -269,11 +269,24 @@
   """
 
   names = params['logic'].getKeyFieldNames()
+  scope_path_pattern = params['scope_path_pattern']
+
+  return getPattern(names, scope_path_pattern)
+
+
+def getPattern(names, scope_path_pattern):
+  """Returns the Django patterns for the specified names.
+
+  Args:
+    names: the field names that should be included in the pattern
+    scope_path_pattern: the pattern to use if the name is 'scope_path'
+  """
+
   patterns = []
 
   for name in names:
     if name == 'scope_path':
-      pattern = params['scope_path_pattern']
+      pattern = scope_path_pattern
     else:
       pattern = r'(?P<%s>%s)' % (name, linkable.LINK_ID_PATTERN_CORE)
     patterns.append(pattern)