app/soc/logic/site/sidebar.py
author Todd Larsen <tlarsen@google.com>
Sat, 04 Oct 2008 07:17:00 +0000
changeset 282 600e0a9bfa06
parent 253 da304c6f8fff
child 283 52e5039ac0fc
permissions -rw-r--r--
A site layout ("site map") of the web application, including URL regular expression patterns, Django views, and metadata for constructing sidebar menus and (eventually) breadcrumbs. One function, soc.logic.site.map.getDjangoUrlPatterns(), converts these details into urlpatterns for use by Django. Patch by: Todd Larsen Review by: to-be-reviewed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
197
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     2
#
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     3
# Copyright 2008 the Melange authors.
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     4
#
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     8
#
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    10
#
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    15
# limitations under the License.
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    16
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    17
"""Site-wide sidebar menu creation.
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    18
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    19
"""
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    20
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    21
__authors__ = [
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    22
  '"Todd Larsen" <tlarsen@google.com>',
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    23
  ]
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    24
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    25
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    26
from google.appengine.api import users
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    27
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    28
from django.utils import datastructures
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    29
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    30
from soc.logic import menu
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    31
from soc.logic.site import id_user
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    32
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    33
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    34
def buildUserSidebar(id=None, **ignored):
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    35
  """Returns a list of menu items for the User portion of the sidebar.
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    36
  
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    37
  Args:
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    38
    is_admin: Boolean indicating that current user is a "Developer"
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    39
      (site super-user); default is None, in which case
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    40
      id_user.isIdDeveloper() is called 
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    41
    **ignored: other keyword arguments supplied to other sidebar builder
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    42
      functions, but ignored by this one
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    43
  """
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    44
  if id is None:
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    45
    id = users.get_current_user()
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    46
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    47
  if not id:
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    48
    return [
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    49
      # user is logged out, so User top-level menu doubles as a sign-in link
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    50
      menu.MenuItem(
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    51
        'User (sign in)',
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    52
        value=users.create_login_url('/')),
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    53
    ]
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    54
    
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    55
  return [
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    56
    # user is logged in, so User top-level menu doubles as a sign-out link
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    57
    menu.MenuItem(
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    58
      'User (sign out)',
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    59
      value=users.create_logout_url('/'),
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    60
      sub_menu=menu.Menu(items=[
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    61
        # edit existing (or create new) site-wide User profile
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    62
        menu.MenuItem(
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    63
          'Site-wide Profile',
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    64
          value='/user/profile'),
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    65
        ]
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    66
      )
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    67
    ),
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    68
  ]
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    69
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    70
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    71
def buildSiteSidebar(is_admin=None, **ignored):
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    72
  """Returns a list of menu items for the Developer portion of the sidebar.
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    73
  
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    74
  Args:
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    75
    is_admin: Boolean indicating that current user is a "Developer"
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    76
      (site super-user); default is None, in which case
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    77
      id_user.isIdDeveloper() is called 
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    78
    **ignored: other keyword arguments supplied to other sidebar builder
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    79
      functions, but ignored by this one
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    80
  """
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    81
  if is_admin is None:
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    82
    is_admin = id_user.isIdDeveloper()
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    83
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    84
  if not is_admin:
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    85
    # user is either not logged in or not a "Developer", so return no menu
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    86
    return None
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    87
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    88
  return [
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    89
    menu.MenuItem(
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    90
      # Site top-level menu doubles as link for editing site-wide settings
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    91
      'Site',
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    92
      value='/site/home/edit',
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    93
      sub_menu=menu.Menu(items=[
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    94
        menu.MenuItem(
199
14ede160ef16 Minor tweaks to Site menu item names to make them more descriptive.
Todd Larsen <tlarsen@google.com>
parents: 197
diff changeset
    95
          'Search Site for a User',
197
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    96
          value='/site/user/lookup'),
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    97
        menu.MenuItem(
199
14ede160ef16 Minor tweaks to Site menu item names to make them more descriptive.
Todd Larsen <tlarsen@google.com>
parents: 197
diff changeset
    98
          'List Users of Site',
197
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    99
          value='/site/user/list'),
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   100
        menu.MenuItem(
199
14ede160ef16 Minor tweaks to Site menu item names to make them more descriptive.
Todd Larsen <tlarsen@google.com>
parents: 197
diff changeset
   101
          'Create a new Site User',
197
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   102
          value='/site/user/profile'),
221
9cca97feadaa Add sidebar menu items for /site/docs/list and /site/docs/edit. They do not
Todd Larsen <tlarsen@google.com>
parents: 199
diff changeset
   103
        menu.MenuItem(
9cca97feadaa Add sidebar menu items for /site/docs/list and /site/docs/edit. They do not
Todd Larsen <tlarsen@google.com>
parents: 199
diff changeset
   104
          'List Documents on Site',
9cca97feadaa Add sidebar menu items for /site/docs/list and /site/docs/edit. They do not
Todd Larsen <tlarsen@google.com>
parents: 199
diff changeset
   105
          value='/site/docs/list'),
9cca97feadaa Add sidebar menu items for /site/docs/list and /site/docs/edit. They do not
Todd Larsen <tlarsen@google.com>
parents: 199
diff changeset
   106
        menu.MenuItem(
9cca97feadaa Add sidebar menu items for /site/docs/list and /site/docs/edit. They do not
Todd Larsen <tlarsen@google.com>
parents: 199
diff changeset
   107
          'Create a new Site Document',
9cca97feadaa Add sidebar menu items for /site/docs/list and /site/docs/edit. They do not
Todd Larsen <tlarsen@google.com>
parents: 199
diff changeset
   108
          value='/site/docs/edit'),
253
da304c6f8fff Add links in sidebar for upcoming Sponsor views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 221
diff changeset
   109
        menu.MenuItem(
da304c6f8fff Add links in sidebar for upcoming Sponsor views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 221
diff changeset
   110
          'List Sponsors',
da304c6f8fff Add links in sidebar for upcoming Sponsor views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 221
diff changeset
   111
          value='/site/sponsor/list'),
da304c6f8fff Add links in sidebar for upcoming Sponsor views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 221
diff changeset
   112
        menu.MenuItem(
da304c6f8fff Add links in sidebar for upcoming Sponsor views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 221
diff changeset
   113
          'Create a new Sponsor',
da304c6f8fff Add links in sidebar for upcoming Sponsor views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 221
diff changeset
   114
          value='/site/sponsor/profile'),
197
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   115
        ]
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   116
      )
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   117
    ),
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   118
  ]
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   119
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   120
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   121
def buildProgramsSidebar(**unused):
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   122
  """Mock-up for Programs section of sidebar menu.
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   123
  
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   124
  Args:
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   125
    **unused: all keyword arguments are currently unused in this mock-up
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   126
  
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   127
  TODO: actually implement this once Program entities are present in the
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   128
    Datastore.
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   129
  """
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   130
  return [
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   131
    menu.MenuItem(
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   132
      'Google Summer of Code',
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   133
      value='/program/gsoc2009/home',
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   134
      sub_menu=menu.Menu(items=[
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   135
        menu.MenuItem(
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   136
          'Community',
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   137
          value='/program/gsoc2009/community'),
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   138
        menu.MenuItem(
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   139
          'FAQs',
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   140
          value='/program/gsoc2009/docs/faqs'),
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   141
        menu.MenuItem(
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   142
          'Terms of Service',
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   143
          value='/program/gsoc2009/docs/tos'),
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   144
        ]
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   145
      )
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   146
    ),
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   147
    menu.MenuItem(
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   148
      'Google Highly Open Participation',
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   149
      value='/program/ghop2008/home',
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   150
      sub_menu=menu.Menu(items=[
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   151
        menu.MenuItem(
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   152
          'Community',
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   153
          value='/program/ghop2008/community'),
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   154
        menu.MenuItem(
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   155
          'FAQs',
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   156
          value='/program/ghop2008/docs/faqs'),
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   157
        menu.MenuItem(
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   158
          'Contest Rules',
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   159
          value='/program/ghop2008/docs/rules'),
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   160
        ]
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   161
      )
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   162
    ),
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   163
  ]
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   164
  
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   165
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   166
DEF_SIDEBAR_BUILDERS = [
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   167
  buildUserSidebar,
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   168
  buildSiteSidebar,
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   169
  buildProgramsSidebar,
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   170
]
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   171
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   172
def buildSidebar(path=None, builders=DEF_SIDEBAR_BUILDERS, **builder_args):
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   173
  """Calls all sidebar builders to construct the sidebar menu.
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   174
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   175
  Args:
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   176
    builders: list of functions that take context as a single
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   177
      argument; default is the list of sidebar builder functions present
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   178
      in soc.logic.site.sidebar
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   179
    **builder_args: keyword arguments passed to each sidebar builder function
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   180
      
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   181
  Returns:
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   182
    an soc.logic.menu.Menu object containing the sidebar menu items 
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   183
  """
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   184
  menu_items = []
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   185
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   186
  # call each of the sidebar builders and append any menu items they create
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   187
  for builder in builders:
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   188
    built_items = builder(**builder_args)
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   189
    
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   190
    if built_items:
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   191
      menu_items.extend(built_items)
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   192
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   193
  # try to determine which of the menu items is the current path, to indicate
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   194
  # that it is "selected"
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   195
  if not path:
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   196
    # path argument not supplied, so see if an HTTP request object was
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   197
    # supplied in the builder_args
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   198
    request = builder_args.get('request')
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   199
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   200
    if request:
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   201
      # there is an HTTP request object, so use the path stored in it
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   202
      path = request.path
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   203
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   204
  if path:
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   205
    # TODO(tlarsen): scan through list and mark current request.path as "selected"
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   206
    pass
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   207
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   208
  return menu.Menu(items=menu_items)