#!/usr/bin/env python2.5
#
# Copyright 2011 the Melange authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Module for constructing GSoC related URL patterns
"""

__authors__ = [
  '"Lennard de Rijk" <ljvderijk@gmail.com>',
  ]


from soc.models import linkable


def namedLinkIdPattern(names):
  """Returns a link ID pattern consisting of named parts.

  The returned pattern does not start or end with a /, the parts are however
  concatenated with a /.

  Args:
    names: The names that should be given to the different parts.
  """
  named_patterns = []
  for name in names:
    named_patterns.append(r'(?P<%s>%s)' % (name, linkable.LINK_ID_PATTERN_CORE))

  return r'/'.join(named_patterns)

PROGRAM_PATTERN = namedLinkIdPattern(['sponsor', 'program'])
STUDENT_PATTERN = namedLinkIdPattern(['sponsor', 'program', 'student'])
MENTOR_PATTERN = namedLinkIdPattern(['sponsor', 'program', 'organization', 'mentor'])
ORG_ADMIN_PATTERN = namedLinkIdPattern(['sponsor', 'program', 'organization', 'org_admin'])
PROPOSAL_PATTERN = namedLinkIdPattern(['sponsor', 'program', 'student', 'proposal'])
PROJECT_PATTERN = namedLinkIdPattern(['sponsor', 'program', 'organization', 'project'])
@@ -1200,23 +1200,61 @@
 s)%0A%0A
-PROGRAM_PATTERN
+SPONSOR   = namedLinkIdPattern(%5B'sponsor'%5D)%0APROGRAM  
  = n
@@ -1302,24 +1302,18 @@
 %0ASTUDENT
-_PATTERN
+  
  = named
@@ -1365,22 +1365,17 @@
 '%5D)%0A
-MENTOR_PATTERN
+PROPOSAL 
  = n
@@ -1420,51 +1420,40 @@
 ', '
-organization', 'mentor'%5D)%0AORG_ADMIN_PATTERN
+student', 'proposal'%5D)%0AMENTOR   
  = n
@@ -1514,36 +1514,26 @@
 ', '
-org_admin'%5D)%0APROPOSAL_PATTER
+mentor'%5D)%0AORG_ADMI
 N = 
@@ -1575,35 +1575,41 @@
 gram', '
-student', 'proposal
+organization', 'org_admin
 '%5D)%0APROJ
@@ -1611,24 +1611,18 @@
 %0APROJECT
-_PATTERN
+  
  = named
@@ -1681,12 +1681,13 @@
  'project'%5D)
+%0A

Remove _PATTERN suffix, add SPONSOR, align