app/soc/logic/site/sidebar.py
author Todd Larsen <tlarsen@google.com>
Wed, 01 Oct 2008 00:35:29 +0000
changeset 221 9cca97feadaa
parent 199 14ede160ef16
child 253 da304c6f8fff
permissions -rw-r--r--
Add sidebar menu items for /site/docs/list and /site/docs/edit. They do not currently have view functions attached, but there are other links in the mock-up portion of the sidebar that don't currently work, either. The goal is to commit the /site/docs/list and /site/docs/edit changes in small bits that don't break anyone else.
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'),
197
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   109
        ]
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   110
      )
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   111
    ),
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   112
  ]
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   113
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   114
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   115
def buildProgramsSidebar(**unused):
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   116
  """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
   117
  
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   118
  Args:
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   119
    **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
   120
  
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   121
  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
   122
    Datastore.
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
  return [
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   125
    menu.MenuItem(
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   126
      'Google Summer of Code',
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   127
      value='/program/gsoc2009/home',
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   128
      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
   129
        menu.MenuItem(
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   130
          'Community',
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   131
          value='/program/gsoc2009/community'),
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   132
        menu.MenuItem(
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   133
          'FAQs',
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   134
          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
   135
        menu.MenuItem(
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   136
          'Terms of Service',
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   137
          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
   138
        ]
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   139
      )
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   140
    ),
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
      'Google Highly Open Participation',
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   143
      value='/program/ghop2008/home',
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   144
      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
   145
        menu.MenuItem(
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   146
          'Community',
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   147
          value='/program/ghop2008/community'),
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   148
        menu.MenuItem(
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   149
          'FAQs',
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   150
          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
   151
        menu.MenuItem(
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   152
          'Contest Rules',
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   153
          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
   154
        ]
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   155
      )
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   156
    ),
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   157
  ]
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   158
  
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   159
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   160
DEF_SIDEBAR_BUILDERS = [
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   161
  buildUserSidebar,
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   162
  buildSiteSidebar,
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   163
  buildProgramsSidebar,
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 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
   167
  """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
   168
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   169
  Args:
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   170
    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
   171
      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
   172
      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
   173
    **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
   174
      
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   175
  Returns:
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   176
    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
   177
  """
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   178
  menu_items = []
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   179
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   180
  # 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
   181
  for builder in builders:
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   182
    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
   183
    
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   184
    if built_items:
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   185
      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
   186
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   187
  # 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
   188
  # that it is "selected"
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   189
  if not path:
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   190
    # 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
   191
    # 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
   192
    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
   193
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   194
    if request:
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   195
      # 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
   196
      path = request.path
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   197
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   198
  if path:
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   199
    # 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
   200
    pass
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   201
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   202
  return menu.Menu(items=menu_items)