app/soc/logic/site/sidebar.py
author Pawel Solyga <Pawel.Solyga@gmail.com>
Mon, 13 Oct 2008 22:22:16 +0000
changeset 319 4e336befdf86
parent 283 52e5039ac0fc
child 348 fe527c17760c
permissions -rw-r--r--
Rename soc/logic/models/settings.py to model site_settings.py and apply import name change to soc/views/site/home.py Patch by: Pawel Solyga 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
283
52e5039ac0fc Update soc/logic/site/sidebar.py to use parts of the "site map" in
Todd Larsen <tlarsen@google.com>
parents: 253
diff changeset
    32
from soc.logic.site import map
197
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
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    35
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
    36
  """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
    37
  
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    38
  Args:
283
52e5039ac0fc Update soc/logic/site/sidebar.py to use parts of the "site map" in
Todd Larsen <tlarsen@google.com>
parents: 253
diff changeset
    39
    id: a Google Account (users.User) object; default is None, in which
52e5039ac0fc Update soc/logic/site/sidebar.py to use parts of the "site map" in
Todd Larsen <tlarsen@google.com>
parents: 253
diff changeset
    40
      case users.get_current_user() is called 
197
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:
283
52e5039ac0fc Update soc/logic/site/sidebar.py to use parts of the "site map" in
Todd Larsen <tlarsen@google.com>
parents: 253
diff changeset
    48
    return [map.user_signin.makeMenuItem()]
52e5039ac0fc Update soc/logic/site/sidebar.py to use parts of the "site map" in
Todd Larsen <tlarsen@google.com>
parents: 253
diff changeset
    49
52e5039ac0fc Update soc/logic/site/sidebar.py to use parts of the "site map" in
Todd Larsen <tlarsen@google.com>
parents: 253
diff changeset
    50
  return [map.user_signout.makeMenuItem()]
197
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    51
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    52
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    53
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
    54
  """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
    55
  
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    56
  Args:
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    57
    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
    58
      (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
    59
      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
    60
    **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
    61
      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
    62
  """
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    63
  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
    64
    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
    65
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    66
  if not is_admin:
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    67
    # 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
    68
    return None
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    69
283
52e5039ac0fc Update soc/logic/site/sidebar.py to use parts of the "site map" in
Todd Larsen <tlarsen@google.com>
parents: 253
diff changeset
    70
  return [map.site_home_edit.makeMenuItem()]
197
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    71
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    72
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    73
def buildProgramsSidebar(**unused):
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    74
  """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
    75
  
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    76
  Args:
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    77
    **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
    78
  
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    79
  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
    80
    Datastore.
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    81
  """
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    82
  return [
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    83
    menu.MenuItem(
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    84
      'Google Summer of Code',
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    85
      value='/program/gsoc2009/home',
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    86
      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
    87
        menu.MenuItem(
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    88
          'Community',
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    89
          value='/program/gsoc2009/community'),
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    90
        menu.MenuItem(
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    91
          'FAQs',
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    92
          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
    93
        menu.MenuItem(
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    94
          'Terms of Service',
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    95
          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
    96
        ]
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    97
      )
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    98
    ),
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    99
    menu.MenuItem(
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   100
      'Google Highly Open Participation',
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   101
      value='/program/ghop2008/home',
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   102
      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
   103
        menu.MenuItem(
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   104
          'Community',
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   105
          value='/program/ghop2008/community'),
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   106
        menu.MenuItem(
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   107
          'FAQs',
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   108
          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
   109
        menu.MenuItem(
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   110
          'Contest Rules',
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   111
          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
   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
  ]
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
DEF_SIDEBAR_BUILDERS = [
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   119
  buildUserSidebar,
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   120
  buildSiteSidebar,
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   121
  buildProgramsSidebar,
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   122
]
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
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
   125
  """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
   126
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   127
  Args:
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   128
    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
   129
      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
   130
      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
   131
    **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
   132
      
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   133
  Returns:
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   134
    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
   135
  """
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   136
  menu_items = []
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   137
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   138
  # 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
   139
  for builder in builders:
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   140
    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
   141
    
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   142
    if built_items:
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   143
      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
   144
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   145
  # 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
   146
  # that it is "selected"
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   147
  if not path:
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   148
    # 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
   149
    # 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
   150
    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
   151
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   152
    if request:
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   153
      # 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
   154
      path = request.path
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
  if path:
4cf7c0040f2e Sidebar-building controller, with a TODO remaining to implement marking the
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   157
    # 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
   158
    pass
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
  return menu.Menu(items=menu_items)