app/soc/views/sitemap/sitemap.py
author Lennard de Rijk <ljvderijk@gmail.com>
Tue, 24 Feb 2009 19:43:51 +0000
changeset 1484 6b00a2a43eaf
parent 1332 6655b1e89adb
child 1789 6f112b2ebd1f
permissions -rw-r--r--
Changed the method and variable name in student_proposal to match the access type. Patch by: Lennard de Rijk Reviewed by: to-be-reviewed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
494
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
     1
#!/usr/bin/python2.5
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
     2
#
1308
35b75ffcbb37 Partially reverted "Update the copyright notice for 2009."
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1307
diff changeset
     3
# Copyright 2008 the Melange authors.
31
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     4
#
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     8
#
494
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
31
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    10
#
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    15
# limitations under the License.
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    16
637
86ec079d8302 Some docstring and missing blank lines fixes in soc.views.sitemap modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 614
diff changeset
    17
"""Module contains sidemap related functions.
494
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
    18
"""
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
    19
31
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    20
__authors__ = [
494
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
    21
    '"Sverre Rabbelier" <sverre@rabbelier.nl>',
31
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    22
  ]
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    23
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    24
1332
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1324
diff changeset
    25
import soc.logic.system
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1324
diff changeset
    26
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1324
diff changeset
    27
494
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
    28
SITEMAP = []
493
6976c4d8d0ac Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 284
diff changeset
    29
31
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    30
494
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
    31
def addPages(pages):
1332
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1324
diff changeset
    32
  """Adds the specified pages to the sitemap.
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1324
diff changeset
    33
  """
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1324
diff changeset
    34
494
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
    35
  global SITEMAP
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
    36
  SITEMAP += pages
613
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
    37
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
    38
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
    39
def getDjangoURLPatterns(params):
637
86ec079d8302 Some docstring and missing blank lines fixes in soc.views.sitemap modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 614
diff changeset
    40
  """Retrieves a list of sidebar entries for this View.
613
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
    41
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
    42
  Params usage:
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
    43
    The params dictionary is passed to the getKeyFieldsPatterns
637
86ec079d8302 Some docstring and missing blank lines fixes in soc.views.sitemap modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 614
diff changeset
    44
    method, see it's docstring on how it is used.
86ec079d8302 Some docstring and missing blank lines fixes in soc.views.sitemap modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 614
diff changeset
    45
    
613
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
    46
    django_patterns: The django_patterns value is returned directly
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
    47
      if it is non-False.
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
    48
    django_patterns_defaults: The dajngo_patterns_defaults value is
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
    49
      used to construct the url patterns. It is expected to be a
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
    50
      list of tuples. The tuples should contain an url, a module
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
    51
      name, and the name of the url. The name is used as the
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
    52
      page_name passed as keyword argument, but also as the name
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
    53
      by which the url is known to Django internally.
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
    54
    url_name: The url_name argument is passed as argument to each
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
    55
      url, together with the link_id pattern, the link_id core
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
    56
      pattern, and the key fields for this View.
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
    57
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
    58
  Args:
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
    59
    params: a dict with params for this View
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
    60
  """
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
    61
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
    62
  # Return the found result
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
    63
  if params['django_patterns']:
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
    64
    return params['django_patterns']
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
    65
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
    66
  # Construct defaults manualy
1089
810d466514c9 Copy the default django patterns rather than modifying them
Sverre Rabbelier <srabbelier@gmail.com>
parents: 680
diff changeset
    67
  default_django_patterns = params['django_patterns_defaults']
810d466514c9 Copy the default django patterns rather than modifying them
Sverre Rabbelier <srabbelier@gmail.com>
parents: 680
diff changeset
    68
  default_patterns = default_django_patterns[:]
660
5a381b290691 Introduced django_extra_patterns
Sverre Rabbelier <srabbelier@gmail.com>
parents: 637
diff changeset
    69
  default_patterns += params['extra_django_patterns']
613
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
    70
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
    71
  patterns = []
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
    72
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
    73
  for url, module, name in default_patterns:
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
    74
    name = name % params
660
5a381b290691 Introduced django_extra_patterns
Sverre Rabbelier <srabbelier@gmail.com>
parents: 637
diff changeset
    75
    module = module % params
613
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
    76
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
    77
    url = url % {
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
    78
        'url_name': params['url_name'],
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
    79
        'lnp': params['link_id_arg_pattern'],
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
    80
        'ulnp': params['link_id_pattern_core'],
680
7f047b2a2d3a Added a new create regexp in urls for just scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents: 660
diff changeset
    81
        'key_fields': params['key_fields_pattern'],
7f047b2a2d3a Added a new create regexp in urls for just scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents: 660
diff changeset
    82
        'scope': params['scope_path_pattern'],
1324
8cf30dee8048 Factor out the 'key fields without link_id' logic from document
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1308
diff changeset
    83
        'sans_link_id': params['sans_link_id_pattern'],
613
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
    84
        }
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
    85
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
    86
    kwargs = {'page_name': name}
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
    87
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
    88
    item = (url, module, kwargs, name)
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
    89
    patterns.append(item)
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
    90
1332
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1324
diff changeset
    91
  if soc.logic.system.isDebug():
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1324
diff changeset
    92
    patterns += [('^seed_db$', 'soc.models.seed_db.seed'),
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1324
diff changeset
    93
                 ('^clear_db$', 'soc.models.seed_db.clear'),
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1324
diff changeset
    94
                 ('^reseed_db$', 'soc.models.seed_db.reseed')]
6655b1e89adb Add a script to (re)seed the datastore
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1324
diff changeset
    95
613
4880ffa9f3ba Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
    96
  return patterns