app/soc/views/models/program.py
author Sverre Rabbelier <srabbelier@gmail.com>
Thu, 05 Feb 2009 23:52:27 +0000
changeset 1230 b1b1897e4df1
parent 1225 1d5c58e24fd3
child 1238 af56ae7397ab
permissions -rw-r--r--
Cleanup in org_app and replace ReferenceProperty with LinkProperty Using LinkProperty allows the org to host their idea's list on Melange through the Document system, and then specify the URL of that document. This also makes it possible for the orgs to specify a document that is not hosted on Melange. Patch by: Sverre Rabbelier
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
643
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     2
#
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     3
# Copyright 2008 the Melange authors.
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     4
#
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     8
#
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    10
#
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    16
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    17
"""Views for Programs.
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    18
"""
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    19
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    20
__authors__ = [
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    21
    '"Sverre Rabbelier" <sverre@rabbelier.nl>',
769
a0ee643fe832 Added an elementary workflow choosing method to program creation.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 755
diff changeset
    22
    '"Lennard de Rijk" <ljvderijk@gmail.com>',
643
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    23
  ]
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    24
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    25
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    26
from django import forms
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    27
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    28
from soc.logic import dicts
1209
c875b0836f77 Specific program menu's now show a "Apply to become an Organization" entry when the program's timeline states that it's open.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1203
diff changeset
    29
from soc.logic.helper import timeline as timeline_helper
778
bc13cd968946 Added support for mutliple edit forms based on entity type
Sverre Rabbelier <srabbelier@gmail.com>
parents: 777
diff changeset
    30
from soc.logic.models import program as program_logic
1163
d8c50be19232 Cleaned up access.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1162
diff changeset
    31
from soc.logic.models import host as host_logic
666
b9b0506efe8d Fix import sorting and docstring typos in soc.views.models.program module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 663
diff changeset
    32
from soc.views import helper
1038
0a0bc446f869 Allow for a program on/off switch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1036
diff changeset
    33
from soc.views import out_of_band
700
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
    34
from soc.views.helper import access
1038
0a0bc446f869 Allow for a program on/off switch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1036
diff changeset
    35
from soc.views.helper import decorators
643
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    36
from soc.views.helper import redirects
778
bc13cd968946 Added support for mutliple edit forms based on entity type
Sverre Rabbelier <srabbelier@gmail.com>
parents: 777
diff changeset
    37
from soc.views.helper import widgets
1053
3b9552cf748a Rename the confusing Tossed Model class to PresenceWithToS.
Todd Larsen <tlarsen@google.com>
parents: 1051
diff changeset
    38
from soc.views.models import presence_with_tos
714
3e2ce3d8057a Add missing dots in docstrings, proper sorting of imports and small docstring typo fixes.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 712
diff changeset
    39
from soc.views.models import document as document_view
643
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    40
from soc.views.models import sponsor as sponsor_view
705
0ab17e14df95 Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents: 700
diff changeset
    41
from soc.views.sitemap import sidebar
643
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    42
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    43
import soc.logic.models.program
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    44
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    45
1053
3b9552cf748a Rename the confusing Tossed Model class to PresenceWithToS.
Todd Larsen <tlarsen@google.com>
parents: 1051
diff changeset
    46
class View(presence_with_tos.View):
666
b9b0506efe8d Fix import sorting and docstring typos in soc.views.models.program module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 663
diff changeset
    47
  """View methods for the Program model.
643
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    48
  """
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    49
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 653
diff changeset
    50
  def __init__(self, params=None):
643
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    51
    """Defines the fields and methods required for the base View class
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    52
    to provide the user with list, public, create, edit and delete views.
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    53
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    54
    Params:
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 653
diff changeset
    55
      params: a dict with params for this View
700
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
    56
    """
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
    57
1007
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 973
diff changeset
    58
    rights = access.Checker(params)
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 973
diff changeset
    59
    rights['any_access'] = ['allow']
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 973
diff changeset
    60
    rights['show'] = ['allow']
1203
38225f2ad3a6 Renamed checkHasRole to checkHasActiveRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1189
diff changeset
    61
    rights['create'] = [('checkSeeded', ['checkHasActiveRole', host_logic.logic])]
1074
94bc2a9ae103 Properly check if a program is active
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1053
diff changeset
    62
    rights['edit'] = ['checkIsHostForProgram']
1107
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
    63
    rights['delete'] = ['checkIsDeveloper']
643
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    64
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 653
diff changeset
    65
    new_params = {}
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 653
diff changeset
    66
    new_params['logic'] = soc.logic.models.program.logic
700
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
    67
    new_params['rights'] = rights
643
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    68
662
0e89b027b140 Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents: 660
diff changeset
    69
    new_params['scope_view'] = sponsor_view
681
48983ecf4665 Cleanups in group and program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 680
diff changeset
    70
    new_params['scope_redirect'] = redirects.getCreateRedirect
662
0e89b027b140 Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents: 660
diff changeset
    71
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 653
diff changeset
    72
    new_params['name'] = "Program"
1025
1f83f05f522b Add grouping to the existing views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1024
diff changeset
    73
    new_params['sidebar_grouping'] = 'Programs'
643
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    74
901
d580a057103d Presence is now a 'abstract' View, pull in members from program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 858
diff changeset
    75
    new_params['extra_dynaexclude'] = ['timeline']
810
208659644a7f Hide 'tos' pull-down selector from Program profile forms.
Todd Larsen <tlarsen@google.com>
parents: 799
diff changeset
    76
1107
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
    77
    # TODO add clean field to check for uniqueness in link_id and scope_path
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 653
diff changeset
    78
    new_params['create_extra_dynafields'] = {
649
95a41542e693 Finish Program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 647
diff changeset
    79
        'description': forms.fields.CharField(widget=helper.widgets.TinyMCE(
668
77f9a6ea6e67 Some style and typo fixes in different modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 666
diff changeset
    80
            attrs={'rows':10, 'cols':40})),
901
d580a057103d Presence is now a 'abstract' View, pull in members from program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 858
diff changeset
    81
668
77f9a6ea6e67 Some style and typo fixes in different modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 666
diff changeset
    82
        'scope_path': forms.CharField(widget=forms.HiddenInput, required=True),
901
d580a057103d Presence is now a 'abstract' View, pull in members from program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 858
diff changeset
    83
1144
f89bbc9b20a6 Rename 'Create a new document' links to 'Create a New Document', also rename 'Create a new Program' to 'Create a New Program' in soc.views.models modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1115
diff changeset
    84
        'workflow': forms.ChoiceField(choices=[('gsoc','Project-based'),
769
a0ee643fe832 Added an elementary workflow choosing method to program creation.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 755
diff changeset
    85
            ('ghop','Task-based')], required=True),
643
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    86
        }
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    87
778
bc13cd968946 Added support for mutliple edit forms based on entity type
Sverre Rabbelier <srabbelier@gmail.com>
parents: 777
diff changeset
    88
    new_params['edit_extra_dynafields'] = {
bc13cd968946 Added support for mutliple edit forms based on entity type
Sverre Rabbelier <srabbelier@gmail.com>
parents: 777
diff changeset
    89
        'workflow': forms.CharField(widget=widgets.ReadOnlyInput(),
bc13cd968946 Added support for mutliple edit forms based on entity type
Sverre Rabbelier <srabbelier@gmail.com>
parents: 777
diff changeset
    90
                                   required=True),
bc13cd968946 Added support for mutliple edit forms based on entity type
Sverre Rabbelier <srabbelier@gmail.com>
parents: 777
diff changeset
    91
        }
bc13cd968946 Added support for mutliple edit forms based on entity type
Sverre Rabbelier <srabbelier@gmail.com>
parents: 777
diff changeset
    92
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 653
diff changeset
    93
    params = dicts.merge(params, new_params)
643
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    94
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 653
diff changeset
    95
    super(View, self).__init__(params=params)
777
16dcdb8f3357 Added an 'edit timeline' button to the program edit page
Sverre Rabbelier <srabbelier@gmail.com>
parents: 771
diff changeset
    96
769
a0ee643fe832 Added an elementary workflow choosing method to program creation.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 755
diff changeset
    97
  def _editPost(self, request, entity, fields):
a0ee643fe832 Added an elementary workflow choosing method to program creation.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 755
diff changeset
    98
    """See base._editPost().
a0ee643fe832 Added an elementary workflow choosing method to program creation.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 755
diff changeset
    99
    """
777
16dcdb8f3357 Added an 'edit timeline' button to the program edit page
Sverre Rabbelier <srabbelier@gmail.com>
parents: 771
diff changeset
   100
770
eb2e69312953 Fixed a bug where a new timeline would get created on every edit of an existing program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 769
diff changeset
   101
    if not entity:
eb2e69312953 Fixed a bug where a new timeline would get created on every edit of an existing program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 769
diff changeset
   102
      # there is no existing entity so create a new timeline
777
16dcdb8f3357 Added an 'edit timeline' button to the program edit page
Sverre Rabbelier <srabbelier@gmail.com>
parents: 771
diff changeset
   103
      fields['timeline'] = self._createTimelineForType(fields)
770
eb2e69312953 Fixed a bug where a new timeline would get created on every edit of an existing program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 769
diff changeset
   104
    else:
eb2e69312953 Fixed a bug where a new timeline would get created on every edit of an existing program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 769
diff changeset
   105
      # use the timeline from the entity
eb2e69312953 Fixed a bug where a new timeline would get created on every edit of an existing program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 769
diff changeset
   106
      fields['timeline'] = entity.timeline
777
16dcdb8f3357 Added an 'edit timeline' button to the program edit page
Sverre Rabbelier <srabbelier@gmail.com>
parents: 771
diff changeset
   107
901
d580a057103d Presence is now a 'abstract' View, pull in members from program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 858
diff changeset
   108
    super(View, self)._editPost(request, entity, fields)
d580a057103d Presence is now a 'abstract' View, pull in members from program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 858
diff changeset
   109
777
16dcdb8f3357 Added an 'edit timeline' button to the program edit page
Sverre Rabbelier <srabbelier@gmail.com>
parents: 771
diff changeset
   110
  def _createTimelineForType(self, fields):
771
0b1beae179f5 Typo and style fixes.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 770
diff changeset
   111
    """Creates and stores a timeline model for the given type of program.
769
a0ee643fe832 Added an elementary workflow choosing method to program creation.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 755
diff changeset
   112
    """
777
16dcdb8f3357 Added an 'edit timeline' button to the program edit page
Sverre Rabbelier <srabbelier@gmail.com>
parents: 771
diff changeset
   113
16dcdb8f3357 Added an 'edit timeline' button to the program edit page
Sverre Rabbelier <srabbelier@gmail.com>
parents: 771
diff changeset
   114
    workflow = fields['workflow']
16dcdb8f3357 Added an 'edit timeline' button to the program edit page
Sverre Rabbelier <srabbelier@gmail.com>
parents: 771
diff changeset
   115
778
bc13cd968946 Added support for mutliple edit forms based on entity type
Sverre Rabbelier <srabbelier@gmail.com>
parents: 777
diff changeset
   116
    timeline_logic = program_logic.logic.TIMELINE_LOGIC[workflow]
777
16dcdb8f3357 Added an 'edit timeline' button to the program edit page
Sverre Rabbelier <srabbelier@gmail.com>
parents: 771
diff changeset
   117
1218
569a3fe9cb88 Cleaned up getKeyNameFromFields in Logic base.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1209
diff changeset
   118
    key_name = self._logic.getKeyNameFromFields(fields)
777
16dcdb8f3357 Added an 'edit timeline' button to the program edit page
Sverre Rabbelier <srabbelier@gmail.com>
parents: 771
diff changeset
   119
16dcdb8f3357 Added an 'edit timeline' button to the program edit page
Sverre Rabbelier <srabbelier@gmail.com>
parents: 771
diff changeset
   120
    properties = {'scope_path': key_name}
16dcdb8f3357 Added an 'edit timeline' button to the program edit page
Sverre Rabbelier <srabbelier@gmail.com>
parents: 771
diff changeset
   121
16dcdb8f3357 Added an 'edit timeline' button to the program edit page
Sverre Rabbelier <srabbelier@gmail.com>
parents: 771
diff changeset
   122
    timeline = timeline_logic.updateOrCreateFromFields(properties, properties)
16dcdb8f3357 Added an 'edit timeline' button to the program edit page
Sverre Rabbelier <srabbelier@gmail.com>
parents: 771
diff changeset
   123
    return timeline
643
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   124
1038
0a0bc446f869 Allow for a program on/off switch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1036
diff changeset
   125
  @decorators.merge_params
1017
6ad4fdb48840 Cache access checks and disable sidebar caching
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1007
diff changeset
   126
  def getExtraMenus(self, id, user, params=None):
700
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   127
    """Returns the extra menu's for this view.
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   128
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   129
    A menu item is generated for each program that is currently
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   130
    running. The public page for each program is added as menu item,
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   131
    as well as all public documents for that program.
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   132
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   133
    Args:
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   134
      params: a dict with params for this View.
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   135
    """
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   136
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   137
    logic = params['logic']
1038
0a0bc446f869 Allow for a program on/off switch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1036
diff changeset
   138
    rights = params['rights']
700
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   139
1107
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   140
    # only get all invisible and visible programs
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   141
    fields = {'status':['invisible', 'visible']}
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   142
    entities = logic.getForFields(fields)
700
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   143
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   144
    menus = []
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   145
1038
0a0bc446f869 Allow for a program on/off switch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1036
diff changeset
   146
    rights.setCurrentUser(id, user)
0a0bc446f869 Allow for a program on/off switch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1036
diff changeset
   147
    filter_args = {}
0a0bc446f869 Allow for a program on/off switch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1036
diff changeset
   148
700
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   149
    for entity in entities:
1107
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   150
      items = []
1038
0a0bc446f869 Allow for a program on/off switch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1036
diff changeset
   151
1107
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   152
      if entity.status == 'visible':
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   153
        # show the documents for this program, even for not logged in users
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   154
        items += document_view.view.getMenusForScope(entity, params)
1209
c875b0836f77 Specific program menu's now show a "Apply to become an Organization" entry when the program's timeline states that it's open.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1203
diff changeset
   155
        items += self._getTimeDependentEntries(entity, params)
1097
1f7015b33a0c Add a 'Create new document' link for clubs, sponsors and programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1074
diff changeset
   156
1f7015b33a0c Add a 'Create new document' link for clubs, sponsors and programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1074
diff changeset
   157
      try:
1107
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   158
        # check if the current user is a host for this program
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   159
        rights.doCachedCheck('checkIsHostForProgram', 
1144
f89bbc9b20a6 Rename 'Create a new document' links to 'Create a New Document', also rename 'Create a new Program' to 'Create a New Program' in soc.views.models modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1115
diff changeset
   160
            {'scope_path': entity.scope_path,
1178
f0de31a14797 Removed work flow field from the check in getExtraMenus for program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1163
diff changeset
   161
            'link_id': entity.link_id}, [])
1107
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   162
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   163
        if entity.status == 'invisible':
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   164
          # still add the document links so hosts can see how it looks like
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   165
          items += document_view.view.getMenusForScope(entity, params)
1209
c875b0836f77 Specific program menu's now show a "Apply to become an Organization" entry when the program's timeline states that it's open.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1203
diff changeset
   166
          items += self._getTimeDependentEntries(entity, params)
1107
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   167
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   168
        # add link to edit Program Profile
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   169
        items += [(redirects.getEditRedirect(entity, params),
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   170
            'Edit Program Profile','any_access')]
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   171
        # add link to edit Program Timeline
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   172
        items += [(redirects.getEditRedirect(entity, {'url_name': 'timeline'}),
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   173
            "Edit Program Timeline", 'any_access')]
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   174
        # add link to create a new Program Document
1097
1f7015b33a0c Add a 'Create new document' link for clubs, sponsors and programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1074
diff changeset
   175
        items += [(redirects.getCreateDocumentRedirect(entity, 'program'),
1144
f89bbc9b20a6 Rename 'Create a new document' links to 'Create a New Document', also rename 'Create a new Program' to 'Create a New Program' in soc.views.models modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1115
diff changeset
   176
            "Create a New Document", 'any_access')]
1107
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   177
1097
1f7015b33a0c Add a 'Create new document' link for clubs, sponsors and programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1074
diff changeset
   178
      except out_of_band.Error:
1f7015b33a0c Add a 'Create new document' link for clubs, sponsors and programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1074
diff changeset
   179
        pass
1f7015b33a0c Add a 'Create new document' link for clubs, sponsors and programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1074
diff changeset
   180
1162
1d9396d75c13 Do not return empty menu's in program.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1144
diff changeset
   181
      items = sidebar.getSidebarMenu(id, user, items, params=params)
1d9396d75c13 Do not return empty menu's in program.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1144
diff changeset
   182
      if not items:
1d9396d75c13 Do not return empty menu's in program.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1144
diff changeset
   183
        continue
1d9396d75c13 Do not return empty menu's in program.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1144
diff changeset
   184
700
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   185
      menu = {}
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   186
      menu['heading'] = entity.short_name
1162
1d9396d75c13 Do not return empty menu's in program.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1144
diff changeset
   187
      menu['items'] = items
1024
2a0ae6483825 Group dynamically generated menu items
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1023
diff changeset
   188
      menu['group'] = 'Programs'
700
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   189
      menus.append(menu)
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   190
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   191
    return menus
647
355ac73823a1 Swap order of merged params to fix sponsor select view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 643
diff changeset
   192
1209
c875b0836f77 Specific program menu's now show a "Apply to become an Organization" entry when the program's timeline states that it's open.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1203
diff changeset
   193
  def _getTimeDependentEntries(self, program_entity, params):
c875b0836f77 Specific program menu's now show a "Apply to become an Organization" entry when the program's timeline states that it's open.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1203
diff changeset
   194
    items = []
c875b0836f77 Specific program menu's now show a "Apply to become an Organization" entry when the program's timeline states that it's open.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1203
diff changeset
   195
c875b0836f77 Specific program menu's now show a "Apply to become an Organization" entry when the program's timeline states that it's open.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1203
diff changeset
   196
    #TODO(ljvderijk) Add more timeline dependent entries
c875b0836f77 Specific program menu's now show a "Apply to become an Organization" entry when the program's timeline states that it's open.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1203
diff changeset
   197
    timeline_entity = program_entity.timeline
c875b0836f77 Specific program menu's now show a "Apply to become an Organization" entry when the program's timeline states that it's open.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1203
diff changeset
   198
c875b0836f77 Specific program menu's now show a "Apply to become an Organization" entry when the program's timeline states that it's open.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1203
diff changeset
   199
    if timeline_helper.isActivePeriod(timeline_entity, 'org_signup'):
c875b0836f77 Specific program menu's now show a "Apply to become an Organization" entry when the program's timeline states that it's open.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1203
diff changeset
   200
      # add the organization signup link
c875b0836f77 Specific program menu's now show a "Apply to become an Organization" entry when the program's timeline states that it's open.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1203
diff changeset
   201
      items += [
1225
1d5c58e24fd3 Org applications can now only be made by a user when a program allows it.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1218
diff changeset
   202
          (redirects.getApplyRedirect(program_entity, {'url_name': 'org_app'}),
1209
c875b0836f77 Specific program menu's now show a "Apply to become an Organization" entry when the program's timeline states that it's open.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1203
diff changeset
   203
          "Apply to become an Organization", 'any_access')]
c875b0836f77 Specific program menu's now show a "Apply to become an Organization" entry when the program's timeline states that it's open.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1203
diff changeset
   204
c875b0836f77 Specific program menu's now show a "Apply to become an Organization" entry when the program's timeline states that it's open.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1203
diff changeset
   205
    return items
c875b0836f77 Specific program menu's now show a "Apply to become an Organization" entry when the program's timeline states that it's open.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1203
diff changeset
   206
c875b0836f77 Specific program menu's now show a "Apply to become an Organization" entry when the program's timeline states that it's open.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1203
diff changeset
   207
643
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   208
view = View()
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   209
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   210
create = view.create
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   211
delete = view.delete
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   212
edit = view.edit
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   213
list = view.list
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   214
public = view.public
858
e79e7a22326f Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents: 810
diff changeset
   215
export = view.export
923
5a10f6db154b Hook up the 'home' view for site and program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 901
diff changeset
   216
home = view.home
934
9fcc08971efe Add a 'pick' view to the appropriate views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 923
diff changeset
   217
pick = view.pick