app/soc/views/models/program.py
author Lennard de Rijk <ljvderijk@gmail.com>
Sun, 08 Mar 2009 13:14:28 +0000
changeset 1741 0da1285f5bc0
parent 1736 72fb61f67ff5
child 1743 669b6136b7b3
permissions -rw-r--r--
Public reviews are now shown on the public page for the student proposal. The assigned mentor name has been removed from the public page. The student proposal view now uses the new getReviewsForEntity method. Patch by: Lennard de Rijk Reviewed by:to-be-reviewed
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
#
1308
35b75ffcbb37 Partially reverted "Update the copyright notice for 2009."
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1307
diff changeset
     3
# Copyright 2008 the Melange authors.
643
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
1736
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
    26
from django import http
643
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    27
from django import forms
1736
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
    28
from django.utils import simplejson
1260
594c6b500378 Added Agreement properties to Program Model.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1257
diff changeset
    29
from django.utils.translation import ugettext
643
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    30
1736
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
    31
from soc.logic import allocations
1700
599a5ff8f422 Clean document references
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1698
diff changeset
    32
from soc.logic import cleaning
643
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    33
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
    34
from soc.logic.helper import timeline as timeline_helper
1273
324a1ecc4e88 Use the newly added __scoped__ and references for program's ToSes
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1260
diff changeset
    35
from soc.logic.models import host as host_logic
1437
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
    36
from soc.logic.models import mentor as mentor_logic
1705
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
    37
from soc.logic.models import organization as org_logic
1437
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
    38
from soc.logic.models import org_admin as org_admin_logic
778
bc13cd968946 Added support for mutliple edit forms based on entity type
Sverre Rabbelier <srabbelier@gmail.com>
parents: 777
diff changeset
    39
from soc.logic.models import program as program_logic
1437
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
    40
from soc.logic.models import student as student_logic
1352
4f118840617f Fix import sorting in soc.views.models.program module and rename any "Org" in link names to "Organization".
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1343
diff changeset
    41
from soc.logic.models.document import logic as document_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
    42
from soc.views import helper
1038
0a0bc446f869 Allow for a program on/off switch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1036
diff changeset
    43
from soc.views import out_of_band
700
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
    44
from soc.views.helper import access
1038
0a0bc446f869 Allow for a program on/off switch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1036
diff changeset
    45
from soc.views.helper import decorators
1705
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
    46
from soc.views.helper import lists
643
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    47
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
    48
from soc.views.helper import widgets
1698
a8da5a620236 Switch Program to regular presence
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1643
diff changeset
    49
from soc.views.models import presence
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
    50
from soc.views.models import document as document_view
643
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    51
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
    52
from soc.views.sitemap import sidebar
643
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    53
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    54
import soc.logic.models.program
1260
594c6b500378 Added Agreement properties to Program Model.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1257
diff changeset
    55
import soc.models.work
643
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    56
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    57
1698
a8da5a620236 Switch Program to regular presence
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1643
diff changeset
    58
class View(presence.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
    59
  """View methods for the Program model.
643
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    60
  """
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    61
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 653
diff changeset
    62
  def __init__(self, params=None):
643
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    63
    """Defines the fields and methods required for the base View class
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    64
    to provide the user with list, public, create, edit and delete views.
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    65
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    66
    Params:
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 653
diff changeset
    67
      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
    68
    """
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
    69
1007
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 973
diff changeset
    70
    rights = access.Checker(params)
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 973
diff changeset
    71
    rights['any_access'] = ['allow']
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 973
diff changeset
    72
    rights['show'] = ['allow']
1643
7b33b9442c81 Fix too long lines, remove unused variable, add missing docstring in soc.views.models.program module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1584
diff changeset
    73
    rights['create'] = [('checkSeeded', ['checkHasActiveRoleForScope', 
7b33b9442c81 Fix too long lines, remove unused variable, add missing docstring in soc.views.models.program module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1584
diff changeset
    74
        host_logic.logic])]
1074
94bc2a9ae103 Properly check if a program is active
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1053
diff changeset
    75
    rights['edit'] = ['checkIsHostForProgram']
1107
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
    76
    rights['delete'] = ['checkIsDeveloper']
643
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    77
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 653
diff changeset
    78
    new_params = {}
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 653
diff changeset
    79
    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
    80
    new_params['rights'] = rights
643
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    81
662
0e89b027b140 Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents: 660
diff changeset
    82
    new_params['scope_view'] = sponsor_view
681
48983ecf4665 Cleanups in group and program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 680
diff changeset
    83
    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
    84
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 653
diff changeset
    85
    new_params['name'] = "Program"
1025
1f83f05f522b Add grouping to the existing views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1024
diff changeset
    86
    new_params['sidebar_grouping'] = 'Programs'
1303
08433090cff8 Add prefix filtering and refactored program field generation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1281
diff changeset
    87
    new_params['document_prefix'] = "program"
08433090cff8 Add prefix filtering and refactored program field generation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1281
diff changeset
    88
1511
3342ce7a495c Fix some whitespace damadge and a style fix
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1492
diff changeset
    89
    new_params['extra_dynaexclude'] = ['timeline', 'org_admin_agreement',
1260
594c6b500378 Added Agreement properties to Program Model.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1257
diff changeset
    90
        'mentor_agreement', 'student_agreement']
810
208659644a7f Hide 'tos' pull-down selector from Program profile forms.
Todd Larsen <tlarsen@google.com>
parents: 799
diff changeset
    91
1705
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
    92
    patterns = []
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
    93
    patterns += [
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
    94
        (r'^%(url_name)s/(?P<access_type>assign_slots)/%(key_fields)s$',
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
    95
          'soc.views.models.%(module_name)s.assign_slots',
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
    96
          'Assign slots'),
1706
9609e2a0d7d7 Added a slots JSON call
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1705
diff changeset
    97
        (r'^%(url_name)s/(?P<access_type>slots)/%(key_fields)s$',
9609e2a0d7d7 Added a slots JSON call
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1705
diff changeset
    98
          'soc.views.models.%(module_name)s.slots',
9609e2a0d7d7 Added a slots JSON call
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1705
diff changeset
    99
          'Assign slots'),
1705
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   100
        ]
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   101
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   102
    new_params['extra_django_patterns'] = patterns
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   103
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   104
1107
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   105
    # TODO add clean field to check for uniqueness in link_id and scope_path
1430
ff8cc6b15e6a Rename dynafields to dynaproperties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1352
diff changeset
   106
    new_params['create_extra_dynaproperties'] = {
649
95a41542e693 Finish Program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 647
diff changeset
   107
        '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
   108
            attrs={'rows':10, 'cols':40})),
77f9a6ea6e67 Some style and typo fixes in different modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 666
diff changeset
   109
        'scope_path': forms.CharField(widget=forms.HiddenInput, required=True),
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
   110
        '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
   111
            ('ghop','Task-based')], required=True),
643
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   112
        }
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   113
1303
08433090cff8 Add prefix filtering and refactored program field generation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1281
diff changeset
   114
    reference_fields = [
08433090cff8 Add prefix filtering and refactored program field generation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1281
diff changeset
   115
        ('org_admin_agreement_link_id', soc.models.work.Work.link_id.help_text,
08433090cff8 Add prefix filtering and refactored program field generation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1281
diff changeset
   116
         ugettext('Organization Admin Agreement Document link ID')),
08433090cff8 Add prefix filtering and refactored program field generation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1281
diff changeset
   117
        ('mentor_agreement_link_id', soc.models.work.Work.link_id.help_text,
08433090cff8 Add prefix filtering and refactored program field generation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1281
diff changeset
   118
         ugettext('Mentor Agreement Document link ID')),
08433090cff8 Add prefix filtering and refactored program field generation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1281
diff changeset
   119
        ('student_agreement_link_id', soc.models.work.Work.link_id.help_text,
08433090cff8 Add prefix filtering and refactored program field generation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1281
diff changeset
   120
         ugettext('Student Agreement Document link ID')),
08433090cff8 Add prefix filtering and refactored program field generation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1281
diff changeset
   121
        ('home_link_id', soc.models.work.Work.link_id.help_text,
08433090cff8 Add prefix filtering and refactored program field generation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1281
diff changeset
   122
         ugettext('Home page Document link ID')),
08433090cff8 Add prefix filtering and refactored program field generation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1281
diff changeset
   123
        ]
08433090cff8 Add prefix filtering and refactored program field generation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1281
diff changeset
   124
08433090cff8 Add prefix filtering and refactored program field generation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1281
diff changeset
   125
    result = {}
08433090cff8 Add prefix filtering and refactored program field generation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1281
diff changeset
   126
08433090cff8 Add prefix filtering and refactored program field generation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1281
diff changeset
   127
    for key, help_text, label in reference_fields:
08433090cff8 Add prefix filtering and refactored program field generation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1281
diff changeset
   128
      result[key] = widgets.ReferenceField(
08433090cff8 Add prefix filtering and refactored program field generation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1281
diff changeset
   129
          reference_url='document', filter=['__scoped__'],
08433090cff8 Add prefix filtering and refactored program field generation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1281
diff changeset
   130
          filter_fields={'prefix': new_params['document_prefix']},
08433090cff8 Add prefix filtering and refactored program field generation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1281
diff changeset
   131
          required=False, label=label, help_text=help_text)
08433090cff8 Add prefix filtering and refactored program field generation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1281
diff changeset
   132
08433090cff8 Add prefix filtering and refactored program field generation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1281
diff changeset
   133
    result['workflow'] = forms.CharField(widget=widgets.ReadOnlyInput(),
08433090cff8 Add prefix filtering and refactored program field generation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1281
diff changeset
   134
                                         required=True)
1700
599a5ff8f422 Clean document references
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1698
diff changeset
   135
    result['clean'] = cleaning.clean_refs(new_params,
599a5ff8f422 Clean document references
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1698
diff changeset
   136
                                          [i for i,_,_ in reference_fields])
1303
08433090cff8 Add prefix filtering and refactored program field generation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1281
diff changeset
   137
1430
ff8cc6b15e6a Rename dynafields to dynaproperties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1352
diff changeset
   138
    new_params['edit_extra_dynaproperties'] = result
1303
08433090cff8 Add prefix filtering and refactored program field generation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1281
diff changeset
   139
1700
599a5ff8f422 Clean document references
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1698
diff changeset
   140
    document_references = [
599a5ff8f422 Clean document references
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1698
diff changeset
   141
        ('org_admin_agreement_link_id', 'org_admin_agreement',
1273
324a1ecc4e88 Use the newly added __scoped__ and references for program's ToSes
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1260
diff changeset
   142
         lambda x: x.org_admin_agreement),
1700
599a5ff8f422 Clean document references
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1698
diff changeset
   143
        ('mentor_agreement_link_id', 'mentor_agreement',
1273
324a1ecc4e88 Use the newly added __scoped__ and references for program's ToSes
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1260
diff changeset
   144
         lambda x: x.mentor_agreement),
1700
599a5ff8f422 Clean document references
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1698
diff changeset
   145
        ('student_agreement_link_id', 'student_agreement',
1273
324a1ecc4e88 Use the newly added __scoped__ and references for program's ToSes
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1260
diff changeset
   146
         lambda x: x.student_agreement),
324a1ecc4e88 Use the newly added __scoped__ and references for program's ToSes
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1260
diff changeset
   147
        ]
324a1ecc4e88 Use the newly added __scoped__ and references for program's ToSes
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1260
diff changeset
   148
1700
599a5ff8f422 Clean document references
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1698
diff changeset
   149
    new_params['references'] = document_references
1273
324a1ecc4e88 Use the newly added __scoped__ and references for program's ToSes
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1260
diff changeset
   150
1260
594c6b500378 Added Agreement properties to Program Model.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1257
diff changeset
   151
    params = dicts.merge(params, new_params, sub_merge=True)
643
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   152
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 653
diff changeset
   153
    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
   154
1705
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   155
  @decorators.merge_params
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   156
  @decorators.check_access
1706
9609e2a0d7d7 Added a slots JSON call
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1705
diff changeset
   157
  def slots(self, request, acces_type, page_name=None, params=None, **kwargs):
9609e2a0d7d7 Added a slots JSON call
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1705
diff changeset
   158
    """Returns a JSON object with all orgs allocation.
9609e2a0d7d7 Added a slots JSON call
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1705
diff changeset
   159
9609e2a0d7d7 Added a slots JSON call
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1705
diff changeset
   160
    Args:
9609e2a0d7d7 Added a slots JSON call
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1705
diff changeset
   161
      request: the standard Django HTTP request object
9609e2a0d7d7 Added a slots JSON call
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1705
diff changeset
   162
      access_type : the name of the access type which should be checked
9609e2a0d7d7 Added a slots JSON call
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1705
diff changeset
   163
      page_name: the page name displayed in templates as page and header title
9609e2a0d7d7 Added a slots JSON call
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1705
diff changeset
   164
      params: a dict with params for this View, not used
9609e2a0d7d7 Added a slots JSON call
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1705
diff changeset
   165
    """
9609e2a0d7d7 Added a slots JSON call
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1705
diff changeset
   166
9609e2a0d7d7 Added a slots JSON call
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1705
diff changeset
   167
    program = program_logic.logic.getFromKeyFields(kwargs)
1736
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   168
    slots = program.slots
1706
9609e2a0d7d7 Added a slots JSON call
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1705
diff changeset
   169
1736
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   170
    if request.method == 'POST' and 'result' in request.POST:
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   171
      result = request.POST['result']
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   172
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   173
      from_json = simplejson.loads(result).iteritems()
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   174
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   175
      # filter out all orgs where the link_id is 'undefined'
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   176
      orgs = dict( ((k,v) for k, v in from_json if k != 'undefined'))
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   177
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   178
      items = orgs.iteritems()
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   179
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   180
      # whether the org has it's allocations locked
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   181
      locked = ((k, v['slots']) for k, v in items if v['locked'])
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   182
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   183
      # the adjustement for the org
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   184
      adjusted = ((k, v['adjustment']) for k, v in items if v['adjustment'])
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   185
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   186
      locked_slots = dict(locked)
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   187
      adjusted_slots = dict(adjusted)
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   188
    else:
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   189
      filter = {
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   190
          'scope': program,
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   191
          }
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   192
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   193
      query = org_logic.logic.getQueryForFields(filter=filter)
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   194
      entities = [i.toDict() for i in org_logic.logic.getAll(query)]
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   195
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   196
      # group orgs by link_id
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   197
      orgs = dict( ((i['link_id'], i) for i in entities) )
1706
9609e2a0d7d7 Added a slots JSON call
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1705
diff changeset
   198
1736
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   199
      # default to no orgs locked nor adjusted
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   200
      locked_slots = adjusted_slots = {}
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   201
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   202
    # TODO(Lennard): use real data here
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   203
    applications = dict( ((i, [1, 2]) for i in orgs.keys()) )
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   204
    mentors = dict( ((i, 1000) for i in orgs.keys()) )
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   205
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   206
    # TODO: Use configuration variables here
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   207
    max_slots_per_org = 40
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   208
    min_slots_per_org = 2
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   209
    iterative = False
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   210
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   211
    allocator = allocations.Allocator(orgs, applications, mentors,
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   212
                                      slots, max_slots_per_org,
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   213
                                      min_slots_per_org, iterative)
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   214
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   215
    result = allocator.allocate(locked_slots, adjusted_slots)
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   216
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   217
    data = []
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   218
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   219
    for link_id, count in result.iteritems():
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   220
      org = orgs[link_id]
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   221
      data.append({
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   222
          'link_id': link_id,
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   223
          'slots': count,
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   224
          'locked': org['locked'] if 'locked' in org else 0,
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   225
          'adjustment': org['adjustment'] if 'adjustment' in org else 0,
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   226
          })
1706
9609e2a0d7d7 Added a slots JSON call
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1705
diff changeset
   227
9609e2a0d7d7 Added a slots JSON call
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1705
diff changeset
   228
    return self.json(request, data)
9609e2a0d7d7 Added a slots JSON call
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1705
diff changeset
   229
9609e2a0d7d7 Added a slots JSON call
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1705
diff changeset
   230
  @decorators.merge_params
9609e2a0d7d7 Added a slots JSON call
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1705
diff changeset
   231
  @decorators.check_access
1705
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   232
  def assignSlots(self, request, access_type, page_name=None,
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   233
           params=None, **kwargs):
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   234
    """View that allows to assign slots to orgs.
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   235
    """
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   236
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   237
    from soc.views.models import organization as organization_view
1736
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   238
1705
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   239
    params = organization_view.view.getParams()
1736
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   240
    params['list_template'] = 'soc/program/allocation/allocation.html'
1705
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   241
    params['list_heading'] = 'soc/program/allocation/heading.html'
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   242
    params['list_row'] = 'soc/program/allocation/row.html'
1736
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   243
    params['list_pagination'] = 'soc/list/no_pagination.html'
1705
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   244
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   245
    program = program_logic.logic.getFromKeyFields(kwargs)
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   246
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   247
    filter = {
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   248
        'scope': program,
1736
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   249
        'status': 'active',
1705
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   250
        }
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   251
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   252
    content = lists.getListContent(request, params, filter=filter)
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   253
    contents = [content]
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   254
1736
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   255
    context = {
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   256
        'total_slots': program.slots,
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   257
        'uses_json': True,
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   258
        'uses_slot_allocator': True
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   259
        }
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   260
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   261
    return self._list(request, params, contents, page_name, context)
1705
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   262
769
a0ee643fe832 Added an elementary workflow choosing method to program creation.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 755
diff changeset
   263
  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
   264
    """See base._editPost().
a0ee643fe832 Added an elementary workflow choosing method to program creation.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 755
diff changeset
   265
    """
777
16dcdb8f3357 Added an 'edit timeline' button to the program edit page
Sverre Rabbelier <srabbelier@gmail.com>
parents: 771
diff changeset
   266
1475
22b63ab59b27 Make timeline a Linkable
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1470
diff changeset
   267
    super(View, self)._editPost(request, entity, fields)
22b63ab59b27 Make timeline a Linkable
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1470
diff changeset
   268
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
   269
    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
   270
      # 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
   271
      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
   272
    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
   273
      # 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
   274
      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
   275
16dcdb8f3357 Added an 'edit timeline' button to the program edit page
Sverre Rabbelier <srabbelier@gmail.com>
parents: 771
diff changeset
   276
  def _createTimelineForType(self, fields):
771
0b1beae179f5 Typo and style fixes.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 770
diff changeset
   277
    """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
   278
    """
777
16dcdb8f3357 Added an 'edit timeline' button to the program edit page
Sverre Rabbelier <srabbelier@gmail.com>
parents: 771
diff changeset
   279
16dcdb8f3357 Added an 'edit timeline' button to the program edit page
Sverre Rabbelier <srabbelier@gmail.com>
parents: 771
diff changeset
   280
    workflow = fields['workflow']
16dcdb8f3357 Added an 'edit timeline' button to the program edit page
Sverre Rabbelier <srabbelier@gmail.com>
parents: 771
diff changeset
   281
778
bc13cd968946 Added support for mutliple edit forms based on entity type
Sverre Rabbelier <srabbelier@gmail.com>
parents: 777
diff changeset
   282
    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
   283
1512
97c4a718d6f4 Remove updateOrCreateFromFields and it's uses
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1511
diff changeset
   284
    properties = timeline_logic.getKeyFieldsFromFields(fields)
97c4a718d6f4 Remove updateOrCreateFromFields and it's uses
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1511
diff changeset
   285
    key_name = timeline_logic.getKeyNameFromFields(properties)
97c4a718d6f4 Remove updateOrCreateFromFields and it's uses
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1511
diff changeset
   286
1475
22b63ab59b27 Make timeline a Linkable
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1470
diff changeset
   287
    properties['scope'] = fields['scope']
777
16dcdb8f3357 Added an 'edit timeline' button to the program edit page
Sverre Rabbelier <srabbelier@gmail.com>
parents: 771
diff changeset
   288
1512
97c4a718d6f4 Remove updateOrCreateFromFields and it's uses
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1511
diff changeset
   289
    timeline = timeline_logic.updateOrCreateFromKeyName(properties, key_name)
777
16dcdb8f3357 Added an 'edit timeline' button to the program edit page
Sverre Rabbelier <srabbelier@gmail.com>
parents: 771
diff changeset
   290
    return timeline
643
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   291
1038
0a0bc446f869 Allow for a program on/off switch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1036
diff changeset
   292
  @decorators.merge_params
1017
6ad4fdb48840 Cache access checks and disable sidebar caching
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1007
diff changeset
   293
  def getExtraMenus(self, id, user, params=None):
700
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   294
    """Returns the extra menu's for this view.
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   295
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   296
    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
   297
    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
   298
    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
   299
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   300
    Args:
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   301
      params: a dict with params for this View.
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   302
    """
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   303
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   304
    logic = params['logic']
1038
0a0bc446f869 Allow for a program on/off switch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1036
diff changeset
   305
    rights = params['rights']
700
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   306
1107
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   307
    # only get all invisible and visible programs
1511
3342ce7a495c Fix some whitespace damadge and a style fix
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1492
diff changeset
   308
    fields = {'status': ['invisible', 'visible']}
1107
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   309
    entities = logic.getForFields(fields)
700
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   310
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   311
    menus = []
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   312
1038
0a0bc446f869 Allow for a program on/off switch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1036
diff changeset
   313
    rights.setCurrentUser(id, user)
0a0bc446f869 Allow for a program on/off switch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1036
diff changeset
   314
700
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   315
    for entity in entities:
1107
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   316
      items = []
1038
0a0bc446f869 Allow for a program on/off switch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1036
diff changeset
   317
1107
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   318
      if entity.status == 'visible':
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   319
        # 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
   320
        items += document_view.view.getMenusForScope(entity, params)
1317
fad74cf4e5da Add a 'list documents' link everywhere
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1308
diff changeset
   321
        items += self._getTimeDependentEntries(entity, params, id, user)
1097
1f7015b33a0c Add a 'Create new document' link for clubs, sponsors and programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1074
diff changeset
   322
1f7015b33a0c Add a 'Create new document' link for clubs, sponsors and programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1074
diff changeset
   323
      try:
1107
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   324
        # check if the current user is a host for this program
1511
3342ce7a495c Fix some whitespace damadge and a style fix
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1492
diff changeset
   325
        rights.doCachedCheck('checkIsHostForProgram',
1325
8368086dd3a7 Add a list_public view to organization
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1321
diff changeset
   326
                             {'scope_path': entity.scope_path,
8368086dd3a7 Add a list_public view to organization
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1321
diff changeset
   327
                              'link_id': entity.link_id}, [])
1107
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   328
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   329
        if entity.status == 'invisible':
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   330
          # 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
   331
          items += document_view.view.getMenusForScope(entity, params)
1321
0e587b1d0c1d Fixed missing parameters in program view due to change in _getTimeDependentEntries in r1943.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1317
diff changeset
   332
          items += self._getTimeDependentEntries(entity, params, id, user)
1257
12d2bf06698f Added a button to list all your org applications to a speficic program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1248
diff changeset
   333
1238
af56ae7397ab Added scoped group_app listing.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1225
diff changeset
   334
        items += [(redirects.getReviewOverviewRedirect(
af56ae7397ab Added scoped group_app listing.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1225
diff changeset
   335
            entity, {'url_name': 'org_app'}),
1352
4f118840617f Fix import sorting in soc.views.models.program module and rename any "Org" in link names to "Organization".
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1343
diff changeset
   336
            "Review Organization Applications", 'any_access')]
1107
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   337
        # add link to edit Program Profile
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   338
        items += [(redirects.getEditRedirect(entity, params),
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   339
            'Edit Program Profile','any_access')]
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   340
        # add link to edit Program Timeline
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   341
        items += [(redirects.getEditRedirect(entity, {'url_name': 'timeline'}),
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   342
            "Edit Program Timeline", 'any_access')]
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   343
        # 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
   344
        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
   345
            "Create a New Document", 'any_access')]
1317
fad74cf4e5da Add a 'list documents' link everywhere
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1308
diff changeset
   346
        # add link to list all Program Document
fad74cf4e5da Add a 'list documents' link everywhere
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1308
diff changeset
   347
        items += [(redirects.getListDocumentsRedirect(entity, 'program'),
fad74cf4e5da Add a 'list documents' link everywhere
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1308
diff changeset
   348
            "List Documents", 'any_access')]
1107
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   349
1097
1f7015b33a0c Add a 'Create new document' link for clubs, sponsors and programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1074
diff changeset
   350
      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
   351
        pass
1f7015b33a0c Add a 'Create new document' link for clubs, sponsors and programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1074
diff changeset
   352
1162
1d9396d75c13 Do not return empty menu's in program.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1144
diff changeset
   353
      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
   354
      if not items:
1d9396d75c13 Do not return empty menu's in program.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1144
diff changeset
   355
        continue
1d9396d75c13 Do not return empty menu's in program.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1144
diff changeset
   356
700
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   357
      menu = {}
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   358
      menu['heading'] = entity.short_name
1162
1d9396d75c13 Do not return empty menu's in program.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1144
diff changeset
   359
      menu['items'] = items
1024
2a0ae6483825 Group dynamically generated menu items
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1023
diff changeset
   360
      menu['group'] = 'Programs'
700
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   361
      menus.append(menu)
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   362
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   363
    return menus
647
355ac73823a1 Swap order of merged params to fix sponsor select view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 643
diff changeset
   364
1317
fad74cf4e5da Add a 'list documents' link everywhere
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1308
diff changeset
   365
  def _getTimeDependentEntries(self, program_entity, params, id, user):
1643
7b33b9442c81 Fix too long lines, remove unused variable, add missing docstring in soc.views.models.program module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1584
diff changeset
   366
    """Returns a list with time dependent menu items.
7b33b9442c81 Fix too long lines, remove unused variable, add missing docstring in soc.views.models.program module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1584
diff changeset
   367
    """
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
   368
    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
   369
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
   370
    #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
   371
    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
   372
1321
0e587b1d0c1d Fixed missing parameters in program view due to change in _getTimeDependentEntries in r1943.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1317
diff changeset
   373
    if timeline_helper.isActivePeriod(timeline_entity, 'org_signup'):
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
   374
      # 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
   375
      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
   376
          (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
   377
          "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
   378
1321
0e587b1d0c1d Fixed missing parameters in program view due to change in _getTimeDependentEntries in r1943.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1317
diff changeset
   379
      if user:
1352
4f118840617f Fix import sorting in soc.views.models.program module and rename any "Org" in link names to "Organization".
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1343
diff changeset
   380
        # add the 'List my Organization Applications' link
1321
0e587b1d0c1d Fixed missing parameters in program view due to change in _getTimeDependentEntries in r1943.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1317
diff changeset
   381
        items += [
1511
3342ce7a495c Fix some whitespace damadge and a style fix
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1492
diff changeset
   382
            (redirects.getListSelfRedirect(program_entity,
1321
0e587b1d0c1d Fixed missing parameters in program view due to change in _getTimeDependentEntries in r1943.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1317
diff changeset
   383
                                           {'url_name' : 'org_app'}),
1352
4f118840617f Fix import sorting in soc.views.models.program module and rename any "Org" in link names to "Organization".
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1343
diff changeset
   384
             "List My Organization Applications", 'any_access')]
1257
12d2bf06698f Added a button to list all your org applications to a speficic program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1248
diff changeset
   385
1437
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   386
    # get the student entity for this user and program
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   387
    filter = {'user': user,
1564
49a9858c8803 For links in a program to take effect there must be an active role.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1512
diff changeset
   388
              'scope': program_entity,
49a9858c8803 For links in a program to take effect there must be an active role.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1512
diff changeset
   389
              'status': 'active'}
1437
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   390
    student_entity = student_logic.logic.getForFields(filter, unique=True)
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   391
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   392
    if student_entity:
1470
5e887fb80921 Added list my Student Proposals link to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1437
diff changeset
   393
      items += self._getStudentEntries(program_entity, student_entity,
5e887fb80921 Added list my Student Proposals link to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1437
diff changeset
   394
                                       params, id, user)
1437
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   395
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   396
    # get mentor and org_admin entity for this user and program
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   397
    filter = {'user': user,
1564
49a9858c8803 For links in a program to take effect there must be an active role.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1512
diff changeset
   398
              'program': program_entity,
49a9858c8803 For links in a program to take effect there must be an active role.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1512
diff changeset
   399
              'status': 'active'}
1437
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   400
    mentor_entity = mentor_logic.logic.getForFields(filter, unique=True)
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   401
    org_admin_entity = org_admin_logic.logic.getForFields(filter, unique=True)
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   402
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   403
    if mentor_entity or org_admin_entity:
1470
5e887fb80921 Added list my Student Proposals link to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1437
diff changeset
   404
      items += self._getOrganizationEntries(program_entity, org_admin_entity,
5e887fb80921 Added list my Student Proposals link to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1437
diff changeset
   405
                                            mentor_entity, params, id, user)
1437
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   406
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   407
    if not (student_entity or mentor_entity or org_admin_entity):
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   408
      if timeline_helper.isActivePeriod(timeline_entity, 'student_signup'):
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   409
        # this user does not have a role yet for this program
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   410
        items += [('/student/apply/%s' % (program_entity.key().name()),
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   411
            "Register as a Student", 'any_access')]
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   412
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   413
    if timeline_helper.isAfterEvent(timeline_entity,
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   414
        'accepted_organization_announced_deadline'):
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   415
      # add a link to list all the organizations
1643
7b33b9442c81 Fix too long lines, remove unused variable, add missing docstring in soc.views.models.program module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1584
diff changeset
   416
      items += [(redirects.getPublicListRedirect(program_entity, 
7b33b9442c81 Fix too long lines, remove unused variable, add missing docstring in soc.views.models.program module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1584
diff changeset
   417
          {'url_name': 'org'}),
1437
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   418
          "List participating Organizations", 'any_access')]
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   419
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   420
      if not student_entity:
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   421
        # add apply to become a mentor link
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   422
        items += [('/org/apply_mentor/%s' % (program_entity.key().name()),
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   423
         "Apply to become a Mentor", 'any_access')]
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   424
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   425
    return items
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   426
1643
7b33b9442c81 Fix too long lines, remove unused variable, add missing docstring in soc.views.models.program module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1584
diff changeset
   427
  def _getStudentEntries(self, program_entity, student_entity, 
7b33b9442c81 Fix too long lines, remove unused variable, add missing docstring in soc.views.models.program module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1584
diff changeset
   428
                         params, id, user):
1437
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   429
    """Returns a list with menu items for students in a specific program.
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   430
    """
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   431
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   432
    items = []
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   433
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   434
    timeline_entity = program_entity.timeline
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   435
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   436
    if timeline_helper.isActivePeriod(timeline_entity, 'student_signup'):
1643
7b33b9442c81 Fix too long lines, remove unused variable, add missing docstring in soc.views.models.program module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1584
diff changeset
   437
      items += [('/student_proposal/list_orgs/%s' % (
7b33b9442c81 Fix too long lines, remove unused variable, add missing docstring in soc.views.models.program module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1584
diff changeset
   438
          student_entity.key().name()),
1492
deac044c10b6 Textual change in program menu due to comment on r2113.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1490
diff changeset
   439
          "Submit your Student Proposal", 'any_access')]
1470
5e887fb80921 Added list my Student Proposals link to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1437
diff changeset
   440
      items += [(redirects.getListSelfRedirect(student_entity,
1643
7b33b9442c81 Fix too long lines, remove unused variable, add missing docstring in soc.views.models.program module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1584
diff changeset
   441
          {'url_name':'student_proposal'}),
1470
5e887fb80921 Added list my Student Proposals link to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1437
diff changeset
   442
         "List my Student Proposals", 'any_access')]
1437
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   443
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   444
    return items
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   445
1470
5e887fb80921 Added list my Student Proposals link to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1437
diff changeset
   446
  def _getOrganizationEntries(self, program_entity, org_admin_entity,
5e887fb80921 Added list my Student Proposals link to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1437
diff changeset
   447
                              mentor_entity, params, id, user):
1511
3342ce7a495c Fix some whitespace damadge and a style fix
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1492
diff changeset
   448
    """Returns a list with menu items for org admins and mentors in a
1437
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   449
       specific program.
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   450
    """
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   451
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   452
    # TODO(ljvderijk) think about adding specific org items like submit review
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   453
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   454
    items = []
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   455
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
   456
    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
   457
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
   458
643
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   459
view = View()
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   460
1584
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1564
diff changeset
   461
admin = decorators.view(view.admin)
1705
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   462
assign_slots = decorators.view(view.assignSlots)
1584
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1564
diff changeset
   463
create = decorators.view(view.create)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1564
diff changeset
   464
delete = decorators.view(view.delete)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1564
diff changeset
   465
edit = decorators.view(view.edit)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1564
diff changeset
   466
list = decorators.view(view.list)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1564
diff changeset
   467
public = decorators.view(view.public)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1564
diff changeset
   468
export = decorators.view(view.export)
1706
9609e2a0d7d7 Added a slots JSON call
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1705
diff changeset
   469
slots = decorators.view(view.slots)
1584
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1564
diff changeset
   470
home = decorators.view(view.home)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1564
diff changeset
   471
pick = decorators.view(view.pick)