app/soc/views/models/program.py
author Madhusudan.C.S <madhusudancs@gmail.com>
Sat, 22 Aug 2009 03:44:13 +0530
changeset 2781 8f6c0a5a7491
parent 2778 44bb0e89cc1b
child 2782 3944749338d3
permissions -rw-r--r--
program_logic is passed as a parameter to three checkers than hard coding it. program_logic is added as a parameter to checkIsActivePeriod checkCanCreateOrgApp checkIsNotParticipatingInProgramInScope access check methods and the corresponding arguments are added in all the places they are used.
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__ = [
2292
80361f34c457 Add full list of accepted students
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 2257
diff changeset
    21
    '"Daniel Hans" <daniel.m.hans@gmail.com>',
643
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    22
    '"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
    23
    '"Lennard de Rijk" <ljvderijk@gmail.com>',
643
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
1747
02f15a955c42 Provide the 'return_url' in the allocate slots view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1745
diff changeset
    27
import os
02f15a955c42 Provide the 'return_url' in the allocate slots view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1745
diff changeset
    28
1762
c47b9deb22ac Use getFromKeyFieldsOr404 in slots() and allocateSlots()
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1751
diff changeset
    29
from django import forms
1736
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
    30
from django import http
1260
594c6b500378 Added Agreement properties to Program Model.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1257
diff changeset
    31
from django.utils.translation import ugettext
643
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    32
1736
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
    33
from soc.logic import allocations
1700
599a5ff8f422 Clean document references
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1698
diff changeset
    34
from soc.logic import cleaning
643
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    35
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
    36
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
    37
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
    38
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
    39
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
    40
from soc.logic.models import org_admin as org_admin_logic
1852
ea2e23e5b7a1 Show 'list my org apps' only if you have org apps
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1850
diff changeset
    41
from soc.logic.models import org_app as org_app_logic
1751
17c7a7a48dc7 Switch from actual applications to popularity
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1750
diff changeset
    42
from soc.logic.models import student_proposal as student_proposal_logic
778
bc13cd968946 Added support for mutliple edit forms based on entity type
Sverre Rabbelier <srabbelier@gmail.com>
parents: 777
diff changeset
    43
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
    44
from soc.logic.models import student as student_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
    45
from soc.views import helper
1038
0a0bc446f869 Allow for a program on/off switch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1036
diff changeset
    46
from soc.views import out_of_band
700
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
    47
from soc.views.helper import access
1038
0a0bc446f869 Allow for a program on/off switch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1036
diff changeset
    48
from soc.views.helper import decorators
1705
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
    49
from soc.views.helper import lists
643
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    50
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
    51
from soc.views.helper import widgets
1698
a8da5a620236 Switch Program to regular presence
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1643
diff changeset
    52
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
    53
from soc.views.models import document as document_view
643
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    54
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
    55
from soc.views.sitemap import sidebar
643
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    56
1959
e6644c70e408 Show all orgs in accepted org list view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1940
diff changeset
    57
import soc.cache.logic
643
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    58
import soc.logic.models.program
1260
594c6b500378 Added Agreement properties to Program Model.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1257
diff changeset
    59
import soc.models.work
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
1698
a8da5a620236 Switch Program to regular presence
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1643
diff changeset
    62
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
    63
  """View methods for the Program model.
643
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    64
  """
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    65
1940
609128cc37f7 Verbiage fix
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1930
diff changeset
    66
  DEF_ACCEPTED_ORGS_MSG_FMT = ugettext("These organizations have"
609128cc37f7 Verbiage fix
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1930
diff changeset
    67
      " been accepted into %(name)s, but they have not yet completed"
609128cc37f7 Verbiage fix
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1930
diff changeset
    68
      " their organization profile. You can still learn more about"
609128cc37f7 Verbiage fix
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1930
diff changeset
    69
      " each organization by visiting the links below.")
609128cc37f7 Verbiage fix
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1930
diff changeset
    70
609128cc37f7 Verbiage fix
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1930
diff changeset
    71
  DEF_CREATED_ORGS_MSG_FMT = ugettext("These organizations have been"
609128cc37f7 Verbiage fix
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1930
diff changeset
    72
      " accepted into %(name)s and have completed their organization"
609128cc37f7 Verbiage fix
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1930
diff changeset
    73
      " profiles. You can learn more about each organization by"
609128cc37f7 Verbiage fix
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1930
diff changeset
    74
      " visiting the links below.")
609128cc37f7 Verbiage fix
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1930
diff changeset
    75
2128
7da77549bdeb Use the new self._getAcceptedOrgsList in slots view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2127
diff changeset
    76
  DEF_SLOTS_ALLOCATION_MSG = ugettext("Use this view to assign slots.")
7da77549bdeb Use the new self._getAcceptedOrgsList in slots view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2127
diff changeset
    77
2292
80361f34c457 Add full list of accepted students
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 2257
diff changeset
    78
  DEF_ACCEPTED_PROJECTS_MSG_FMT = ugettext("These projects have been"
80361f34c457 Add full list of accepted students
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 2257
diff changeset
    79
      " accepted into %(name)s. You can learn more about each project"
80361f34c457 Add full list of accepted students
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 2257
diff changeset
    80
      " by visiting the links below.")
80361f34c457 Add full list of accepted students
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 2257
diff changeset
    81
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 653
diff changeset
    82
  def __init__(self, params=None):
643
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    83
    """Defines the fields and methods required for the base View class
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    84
    to provide the user with list, public, create, edit and delete views.
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    85
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    86
    Params:
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 653
diff changeset
    87
      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
    88
    """
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
    89
1007
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 973
diff changeset
    90
    rights = access.Checker(params)
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 973
diff changeset
    91
    rights['any_access'] = ['allow']
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 973
diff changeset
    92
    rights['show'] = ['allow']
2778
44bb0e89cc1b Whitespace fix in Program view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 2771
diff changeset
    93
    rights['create'] = [('checkSeeded', ['checkHasActiveRoleForScope',
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
    94
        host_logic.logic])]
1074
94bc2a9ae103 Properly check if a program is active
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1053
diff changeset
    95
    rights['edit'] = ['checkIsHostForProgram']
1107
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
    96
    rights['delete'] = ['checkIsDeveloper']
2107
855daf131060 Make slots view available to hosts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2106
diff changeset
    97
    rights['assign_slots'] = ['checkIsHostForProgram']
855daf131060 Make slots view available to hosts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2106
diff changeset
    98
    rights['slots'] = ['checkIsHostForProgram']
1830
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
    99
    rights['show_duplicates'] = ['checkIsHostForProgram']
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   100
    rights['assigned_proposals'] = ['checkIsHostForProgram']
2257
7c0af7e05257 Fixed typo in access module naming.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2199
diff changeset
   101
    rights['accepted_orgs'] = [('checkIsAfterEvent',
2771
eb654b51053b checkIsAfterEvent takes logic as argument instead of hard coded program logic.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2719
diff changeset
   102
        ['accepted_organization_announced_deadline',
eb654b51053b checkIsAfterEvent takes logic as argument instead of hard coded program logic.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2719
diff changeset
   103
         '__all__', program_logic.logic])]
2292
80361f34c457 Add full list of accepted students
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 2257
diff changeset
   104
    rights['list_projects'] = [('checkIsAfterEvent',
2778
44bb0e89cc1b Whitespace fix in Program view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 2771
diff changeset
   105
        ['accepted_students_announced_deadline',
2771
eb654b51053b checkIsAfterEvent takes logic as argument instead of hard coded program logic.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2719
diff changeset
   106
         '__all__', program_logic.logic])]
643
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   107
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 653
diff changeset
   108
    new_params = {}
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 653
diff changeset
   109
    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
   110
    new_params['rights'] = rights
643
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   111
662
0e89b027b140 Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents: 660
diff changeset
   112
    new_params['scope_view'] = sponsor_view
681
48983ecf4665 Cleanups in group and program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 680
diff changeset
   113
    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
   114
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 653
diff changeset
   115
    new_params['name'] = "Program"
1025
1f83f05f522b Add grouping to the existing views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1024
diff changeset
   116
    new_params['sidebar_grouping'] = 'Programs'
1303
08433090cff8 Add prefix filtering and refactored program field generation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1281
diff changeset
   117
    new_params['document_prefix'] = "program"
08433090cff8 Add prefix filtering and refactored program field generation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1281
diff changeset
   118
1511
3342ce7a495c Fix some whitespace damadge and a style fix
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1492
diff changeset
   119
    new_params['extra_dynaexclude'] = ['timeline', 'org_admin_agreement',
2149
8e6f98adb243 Remove slots_allocation from program view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2147
diff changeset
   120
        'mentor_agreement', 'student_agreement', 'slots_allocation']
810
208659644a7f Hide 'tos' pull-down selector from Program profile forms.
Todd Larsen <tlarsen@google.com>
parents: 799
diff changeset
   121
1705
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   122
    patterns = []
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   123
    patterns += [
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   124
        (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
   125
          'soc.views.models.%(module_name)s.assign_slots',
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   126
          'Assign slots'),
1706
9609e2a0d7d7 Added a slots JSON call
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1705
diff changeset
   127
        (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
   128
          'soc.views.models.%(module_name)s.slots',
1764
1c56cbbf3a33 Views should have a unique name
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1762
diff changeset
   129
          'Assign slots (JSON)'),
1830
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   130
        (r'^%(url_name)s/(?P<access_type>show_duplicates)/%(key_fields)s$',
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   131
          'soc.views.models.%(module_name)s.show_duplicates',
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   132
          'Show duplicate slot assignments'),
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   133
        (r'^%(url_name)s/(?P<access_type>assigned_proposals)/%(key_fields)s$',
1863
d5272c2ded9f Added a 'accepted orgs' view to program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1857
diff changeset
   134
          'soc.views.models.%(module_name)s.assigned_proposals',
1930
2222bed78e7f Rename 'orgs' to 'organizations' in page title
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1924
diff changeset
   135
          "Assigned proposals for multiple organizations"),
1863
d5272c2ded9f Added a 'accepted orgs' view to program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1857
diff changeset
   136
        (r'^%(url_name)s/(?P<access_type>accepted_orgs)/%(key_fields)s$',
d5272c2ded9f Added a 'accepted orgs' view to program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1857
diff changeset
   137
          'soc.views.models.%(module_name)s.accepted_orgs',
1930
2222bed78e7f Rename 'orgs' to 'organizations' in page title
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1924
diff changeset
   138
          "List all accepted organizations"),
2292
80361f34c457 Add full list of accepted students
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 2257
diff changeset
   139
        (r'^%(url_name)s/(?P<access_type>list_projects)/%(key_fields)s$',
80361f34c457 Add full list of accepted students
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 2257
diff changeset
   140
          'soc.views.models.%(module_name)s.list_projects',
80361f34c457 Add full list of accepted students
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 2257
diff changeset
   141
          "List all student projects"),
1705
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   142
        ]
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   143
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   144
    new_params['extra_django_patterns'] = patterns
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   145
1875
69d60793092a Specify the type of Link ID used
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1866
diff changeset
   146
    new_params['create_dynafields'] = [
69d60793092a Specify the type of Link ID used
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1866
diff changeset
   147
        {'name': 'link_id',
69d60793092a Specify the type of Link ID used
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1866
diff changeset
   148
         'base': forms.fields.CharField,
69d60793092a Specify the type of Link ID used
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1866
diff changeset
   149
         'label': 'Program Link ID',
69d60793092a Specify the type of Link ID used
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1866
diff changeset
   150
         },
69d60793092a Specify the type of Link ID used
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1866
diff changeset
   151
        ]
69d60793092a Specify the type of Link ID used
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1866
diff changeset
   152
1107
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   153
    # 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
   154
    new_params['create_extra_dynaproperties'] = {
649
95a41542e693 Finish Program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 647
diff changeset
   155
        '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
   156
            attrs={'rows':10, 'cols':40})),
1966
fcf246b379a7 Add an non-required accepted_orgs_msg property to program profile
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1959
diff changeset
   157
        'accepted_orgs_msg': forms.fields.CharField(
fcf246b379a7 Add an non-required accepted_orgs_msg property to program profile
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1959
diff changeset
   158
            widget=helper.widgets.TinyMCE(attrs={'rows':10, 'cols':40})),
668
77f9a6ea6e67 Some style and typo fixes in different modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 666
diff changeset
   159
        '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
   160
        '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
   161
            ('ghop','Task-based')], required=True),
643
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   162
        }
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   163
1303
08433090cff8 Add prefix filtering and refactored program field generation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1281
diff changeset
   164
    reference_fields = [
08433090cff8 Add prefix filtering and refactored program field generation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1281
diff changeset
   165
        ('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
   166
         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
   167
        ('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
   168
         ugettext('Mentor Agreement Document link ID')),
08433090cff8 Add prefix filtering and refactored program field generation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1281
diff changeset
   169
        ('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
   170
         ugettext('Student Agreement Document link ID')),
08433090cff8 Add prefix filtering and refactored program field generation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1281
diff changeset
   171
        ('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
   172
         ugettext('Home page Document link ID')),
08433090cff8 Add prefix filtering and refactored program field generation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1281
diff changeset
   173
        ]
08433090cff8 Add prefix filtering and refactored program field generation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1281
diff changeset
   174
08433090cff8 Add prefix filtering and refactored program field generation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1281
diff changeset
   175
    result = {}
08433090cff8 Add prefix filtering and refactored program field generation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1281
diff changeset
   176
08433090cff8 Add prefix filtering and refactored program field generation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1281
diff changeset
   177
    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
   178
      result[key] = widgets.ReferenceField(
08433090cff8 Add prefix filtering and refactored program field generation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1281
diff changeset
   179
          reference_url='document', filter=['__scoped__'],
08433090cff8 Add prefix filtering and refactored program field generation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1281
diff changeset
   180
          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
   181
          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
   182
08433090cff8 Add prefix filtering and refactored program field generation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1281
diff changeset
   183
    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
   184
                                         required=True)
1700
599a5ff8f422 Clean document references
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1698
diff changeset
   185
    result['clean'] = cleaning.clean_refs(new_params,
599a5ff8f422 Clean document references
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1698
diff changeset
   186
                                          [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
   187
1430
ff8cc6b15e6a Rename dynafields to dynaproperties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1352
diff changeset
   188
    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
   189
1700
599a5ff8f422 Clean document references
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1698
diff changeset
   190
    document_references = [
599a5ff8f422 Clean document references
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1698
diff changeset
   191
        ('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
   192
         lambda x: x.org_admin_agreement),
1700
599a5ff8f422 Clean document references
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1698
diff changeset
   193
        ('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
   194
         lambda x: x.mentor_agreement),
1700
599a5ff8f422 Clean document references
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1698
diff changeset
   195
        ('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
   196
         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
   197
        ]
324a1ecc4e88 Use the newly added __scoped__ and references for program's ToSes
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1260
diff changeset
   198
1700
599a5ff8f422 Clean document references
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1698
diff changeset
   199
    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
   200
1260
594c6b500378 Added Agreement properties to Program Model.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1257
diff changeset
   201
    params = dicts.merge(params, new_params, sub_merge=True)
643
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   202
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 653
diff changeset
   203
    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
   204
2127
1a0167169af3 Factor out _getAcceptedOrgsList from acceptedOrgs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2121
diff changeset
   205
  def _getAcceptedOrgsList(self, description, params, filter, use_cache):
1a0167169af3 Factor out _getAcceptedOrgsList from acceptedOrgs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2121
diff changeset
   206
    """Returns a list with all accepted orgs.
1a0167169af3 Factor out _getAcceptedOrgsList from acceptedOrgs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2121
diff changeset
   207
1a0167169af3 Factor out _getAcceptedOrgsList from acceptedOrgs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2121
diff changeset
   208
    Args:
1a0167169af3 Factor out _getAcceptedOrgsList from acceptedOrgs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2121
diff changeset
   209
      description: the description of the list
1a0167169af3 Factor out _getAcceptedOrgsList from acceptedOrgs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2121
diff changeset
   210
      params: the params to use
1a0167169af3 Factor out _getAcceptedOrgsList from acceptedOrgs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2121
diff changeset
   211
      filter: the filter to use
1a0167169af3 Factor out _getAcceptedOrgsList from acceptedOrgs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2121
diff changeset
   212
      use_cache: whether or not to use the cache
1a0167169af3 Factor out _getAcceptedOrgsList from acceptedOrgs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2121
diff changeset
   213
    """
1a0167169af3 Factor out _getAcceptedOrgsList from acceptedOrgs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2121
diff changeset
   214
1a0167169af3 Factor out _getAcceptedOrgsList from acceptedOrgs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2121
diff changeset
   215
    logic = params['logic']
1a0167169af3 Factor out _getAcceptedOrgsList from acceptedOrgs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2121
diff changeset
   216
1a0167169af3 Factor out _getAcceptedOrgsList from acceptedOrgs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2121
diff changeset
   217
    order = ['name']
1a0167169af3 Factor out _getAcceptedOrgsList from acceptedOrgs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2121
diff changeset
   218
1a0167169af3 Factor out _getAcceptedOrgsList from acceptedOrgs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2121
diff changeset
   219
    if not use_cache:
1a0167169af3 Factor out _getAcceptedOrgsList from acceptedOrgs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2121
diff changeset
   220
      fun = self._getData
1a0167169af3 Factor out _getAcceptedOrgsList from acceptedOrgs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2121
diff changeset
   221
    else:
1a0167169af3 Factor out _getAcceptedOrgsList from acceptedOrgs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2121
diff changeset
   222
      # only cache if all profiles are created
1a0167169af3 Factor out _getAcceptedOrgsList from acceptedOrgs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2121
diff changeset
   223
      fun =  soc.cache.logic.cache(self._getData)
1a0167169af3 Factor out _getAcceptedOrgsList from acceptedOrgs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2121
diff changeset
   224
    entities = fun(logic.getModel(), filter, order, logic)
1a0167169af3 Factor out _getAcceptedOrgsList from acceptedOrgs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2121
diff changeset
   225
1a0167169af3 Factor out _getAcceptedOrgsList from acceptedOrgs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2121
diff changeset
   226
    result = dicts.rename(params, params['list_params'])
1a0167169af3 Factor out _getAcceptedOrgsList from acceptedOrgs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2121
diff changeset
   227
    result['action'] = (redirects.getHomeRedirect, params)
1a0167169af3 Factor out _getAcceptedOrgsList from acceptedOrgs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2121
diff changeset
   228
    result['description'] = description
1a0167169af3 Factor out _getAcceptedOrgsList from acceptedOrgs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2121
diff changeset
   229
    result['pagination'] = 'soc/list/no_pagination.html'
1a0167169af3 Factor out _getAcceptedOrgsList from acceptedOrgs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2121
diff changeset
   230
    result['data'] = entities
1a0167169af3 Factor out _getAcceptedOrgsList from acceptedOrgs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2121
diff changeset
   231
1a0167169af3 Factor out _getAcceptedOrgsList from acceptedOrgs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2121
diff changeset
   232
    return result
1a0167169af3 Factor out _getAcceptedOrgsList from acceptedOrgs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2121
diff changeset
   233
1705
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   234
  @decorators.merge_params
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   235
  @decorators.check_access
1863
d5272c2ded9f Added a 'accepted orgs' view to program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1857
diff changeset
   236
  def acceptedOrgs(self, request, access_type,
d5272c2ded9f Added a 'accepted orgs' view to program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1857
diff changeset
   237
                   page_name=None, params=None, filter=None, **kwargs):
d5272c2ded9f Added a 'accepted orgs' view to program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1857
diff changeset
   238
    """See base.View.list.
d5272c2ded9f Added a 'accepted orgs' view to program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1857
diff changeset
   239
    """
d5272c2ded9f Added a 'accepted orgs' view to program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1857
diff changeset
   240
d5272c2ded9f Added a 'accepted orgs' view to program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1857
diff changeset
   241
    contents = []
d5272c2ded9f Added a 'accepted orgs' view to program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1857
diff changeset
   242
    logic = params['logic']
d5272c2ded9f Added a 'accepted orgs' view to program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1857
diff changeset
   243
d5272c2ded9f Added a 'accepted orgs' view to program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1857
diff changeset
   244
    program_entity = logic.getFromKeyFieldsOr404(kwargs)
d5272c2ded9f Added a 'accepted orgs' view to program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1857
diff changeset
   245
1940
609128cc37f7 Verbiage fix
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1930
diff changeset
   246
    fmt = {'name': program_entity.name}
609128cc37f7 Verbiage fix
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1930
diff changeset
   247
    description = self.DEF_ACCEPTED_ORGS_MSG_FMT % fmt
609128cc37f7 Verbiage fix
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1930
diff changeset
   248
1863
d5272c2ded9f Added a 'accepted orgs' view to program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1857
diff changeset
   249
    filter = {
d5272c2ded9f Added a 'accepted orgs' view to program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1857
diff changeset
   250
        'status': 'accepted',
d5272c2ded9f Added a 'accepted orgs' view to program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1857
diff changeset
   251
        'scope': program_entity,
d5272c2ded9f Added a 'accepted orgs' view to program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1857
diff changeset
   252
        }
d5272c2ded9f Added a 'accepted orgs' view to program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1857
diff changeset
   253
d5272c2ded9f Added a 'accepted orgs' view to program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1857
diff changeset
   254
    from soc.views.models import org_app as org_app_view
d5272c2ded9f Added a 'accepted orgs' view to program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1857
diff changeset
   255
    aa_params = org_app_view.view.getParams().copy() # accepted applications
d5272c2ded9f Added a 'accepted orgs' view to program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1857
diff changeset
   256
d5272c2ded9f Added a 'accepted orgs' view to program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1857
diff changeset
   257
    # define the list redirect action to show the notification
1865
f00720cddea0 Remove key_order from 'list accepted orgs' view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1863
diff changeset
   258
    del aa_params['list_key_order']
2121
4f6344dfab28 Added list of projects to the organization home page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2107
diff changeset
   259
    aa_params['list_action'] = (redirects.getHomeRedirect, aa_params)
1940
609128cc37f7 Verbiage fix
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1930
diff changeset
   260
    aa_params['list_description'] = description
1863
d5272c2ded9f Added a 'accepted orgs' view to program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1857
diff changeset
   261
d5272c2ded9f Added a 'accepted orgs' view to program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1857
diff changeset
   262
    aa_list = lists.getListContent(request, aa_params, filter, idx=0,
d5272c2ded9f Added a 'accepted orgs' view to program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1857
diff changeset
   263
                                   need_content=True)
d5272c2ded9f Added a 'accepted orgs' view to program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1857
diff changeset
   264
d5272c2ded9f Added a 'accepted orgs' view to program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1857
diff changeset
   265
    if aa_list:
d5272c2ded9f Added a 'accepted orgs' view to program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1857
diff changeset
   266
      contents.append(aa_list)
d5272c2ded9f Added a 'accepted orgs' view to program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1857
diff changeset
   267
2127
1a0167169af3 Factor out _getAcceptedOrgsList from acceptedOrgs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2121
diff changeset
   268
    use_cache = not aa_list # only cache if there are no aa's left
1940
609128cc37f7 Verbiage fix
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1930
diff changeset
   269
    description = self.DEF_CREATED_ORGS_MSG_FMT % fmt
609128cc37f7 Verbiage fix
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1930
diff changeset
   270
1863
d5272c2ded9f Added a 'accepted orgs' view to program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1857
diff changeset
   271
    filter['status'] = ['new', 'active']
d5272c2ded9f Added a 'accepted orgs' view to program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1857
diff changeset
   272
1959
e6644c70e408 Show all orgs in accepted org list view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1940
diff changeset
   273
    from soc.views.models.organization import view as org_view
e6644c70e408 Show all orgs in accepted org list view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1940
diff changeset
   274
    ao_params = org_view.getParams().copy() # active orgs
2778
44bb0e89cc1b Whitespace fix in Program view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 2771
diff changeset
   275
    ao_list = self._getAcceptedOrgsList(description, ao_params,
2194
d5d061b0dfd0 Fix too long line in soc.views.models.program module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2180
diff changeset
   276
        filter, use_cache)
1959
e6644c70e408 Show all orgs in accepted org list view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1940
diff changeset
   277
1924
00445d599421 Always show the accepted organizations list even when there are None.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1923
diff changeset
   278
    contents.append(ao_list)
1863
d5272c2ded9f Added a 'accepted orgs' view to program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1857
diff changeset
   279
1968
23fa129b7cad Show the accepted_orgs_msg for the accepted orgs page
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1966
diff changeset
   280
    params = params.copy()
23fa129b7cad Show the accepted_orgs_msg for the accepted orgs page
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1966
diff changeset
   281
    params['list_msg'] = program_entity.accepted_orgs_msg
23fa129b7cad Show the accepted_orgs_msg for the accepted orgs page
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1966
diff changeset
   282
1863
d5272c2ded9f Added a 'accepted orgs' view to program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1857
diff changeset
   283
    return self._list(request, params, contents, page_name)
d5272c2ded9f Added a 'accepted orgs' view to program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1857
diff changeset
   284
d5272c2ded9f Added a 'accepted orgs' view to program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1857
diff changeset
   285
  @decorators.merge_params
d5272c2ded9f Added a 'accepted orgs' view to program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1857
diff changeset
   286
  @decorators.check_access
2292
80361f34c457 Add full list of accepted students
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 2257
diff changeset
   287
  def acceptedProjects(self, request, access_type,
2410
cb136ce6c8d1 Temporary fix for Issue 636 by turning off the caching of the page's entities.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2361
diff changeset
   288
                       page_name=None, params=None, filter=None, **kwargs):
2292
80361f34c457 Add full list of accepted students
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 2257
diff changeset
   289
    """See base.View.list.
80361f34c457 Add full list of accepted students
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 2257
diff changeset
   290
    """
80361f34c457 Add full list of accepted students
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 2257
diff changeset
   291
    contents = []
80361f34c457 Add full list of accepted students
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 2257
diff changeset
   292
    logic = params['logic']
80361f34c457 Add full list of accepted students
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 2257
diff changeset
   293
80361f34c457 Add full list of accepted students
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 2257
diff changeset
   294
    program_entity = logic.getFromKeyFieldsOr404(kwargs)
80361f34c457 Add full list of accepted students
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 2257
diff changeset
   295
80361f34c457 Add full list of accepted students
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 2257
diff changeset
   296
    filter = {
2410
cb136ce6c8d1 Temporary fix for Issue 636 by turning off the caching of the page's entities.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2361
diff changeset
   297
        'status': 'accepted',
cb136ce6c8d1 Temporary fix for Issue 636 by turning off the caching of the page's entities.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2361
diff changeset
   298
        'program': program_entity}
2292
80361f34c457 Add full list of accepted students
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 2257
diff changeset
   299
80361f34c457 Add full list of accepted students
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 2257
diff changeset
   300
    fmt = {'name': program_entity.name}
80361f34c457 Add full list of accepted students
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 2257
diff changeset
   301
    description = self.DEF_ACCEPTED_PROJECTS_MSG_FMT % fmt
80361f34c457 Add full list of accepted students
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 2257
diff changeset
   302
80361f34c457 Add full list of accepted students
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 2257
diff changeset
   303
    from soc.views.models import student_project as sp_view
80361f34c457 Add full list of accepted students
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 2257
diff changeset
   304
80361f34c457 Add full list of accepted students
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 2257
diff changeset
   305
    ap_params = sp_view.view.getParams().copy() # accepted projects
2410
cb136ce6c8d1 Temporary fix for Issue 636 by turning off the caching of the page's entities.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2361
diff changeset
   306
    ap_params['list_action'] = (redirects.getPublicRedirect, ap_params)
cb136ce6c8d1 Temporary fix for Issue 636 by turning off the caching of the page's entities.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2361
diff changeset
   307
    ap_params['list_description'] = description
cb136ce6c8d1 Temporary fix for Issue 636 by turning off the caching of the page's entities.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2361
diff changeset
   308
    ap_params['list_heading'] = 'soc/student_project/list/heading_all.html'
cb136ce6c8d1 Temporary fix for Issue 636 by turning off the caching of the page's entities.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2361
diff changeset
   309
    ap_params['list_row'] = 'soc/student_project/list/row_all.html'
2292
80361f34c457 Add full list of accepted students
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 2257
diff changeset
   310
2410
cb136ce6c8d1 Temporary fix for Issue 636 by turning off the caching of the page's entities.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2361
diff changeset
   311
    return self.list(request, access_type, page_name=page_name,
cb136ce6c8d1 Temporary fix for Issue 636 by turning off the caching of the page's entities.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2361
diff changeset
   312
                     params=ap_params, filter=filter)
2292
80361f34c457 Add full list of accepted students
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 2257
diff changeset
   313
80361f34c457 Add full list of accepted students
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 2257
diff changeset
   314
  @decorators.merge_params
80361f34c457 Add full list of accepted students
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 2257
diff changeset
   315
  @decorators.check_access
1706
9609e2a0d7d7 Added a slots JSON call
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1705
diff changeset
   316
  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
   317
    """Returns a JSON object with all orgs allocation.
9609e2a0d7d7 Added a slots JSON call
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1705
diff changeset
   318
9609e2a0d7d7 Added a slots JSON call
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1705
diff changeset
   319
    Args:
9609e2a0d7d7 Added a slots JSON call
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1705
diff changeset
   320
      request: the standard Django HTTP request object
9609e2a0d7d7 Added a slots JSON call
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1705
diff changeset
   321
      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
   322
      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
   323
      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
   324
    """
2778
44bb0e89cc1b Whitespace fix in Program view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 2771
diff changeset
   325
2076
1cd180cc56c9 Style fixes and removal of unused imports in soc.views.models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2064
diff changeset
   326
    from django.utils import simplejson
1706
9609e2a0d7d7 Added a slots JSON call
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1705
diff changeset
   327
1762
c47b9deb22ac Use getFromKeyFieldsOr404 in slots() and allocateSlots()
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1751
diff changeset
   328
    program = program_logic.logic.getFromKeyFieldsOr404(kwargs)
2076
1cd180cc56c9 Style fixes and removal of unused imports in soc.views.models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2064
diff changeset
   329
    program_slots = program.slots
1706
9609e2a0d7d7 Added a slots JSON call
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1705
diff changeset
   330
1751
17c7a7a48dc7 Switch from actual applications to popularity
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1750
diff changeset
   331
    filter = {
17c7a7a48dc7 Switch from actual applications to popularity
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1750
diff changeset
   332
          'scope': program,
17c7a7a48dc7 Switch from actual applications to popularity
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1750
diff changeset
   333
          'status': 'active',
17c7a7a48dc7 Switch from actual applications to popularity
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1750
diff changeset
   334
          }
17c7a7a48dc7 Switch from actual applications to popularity
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1750
diff changeset
   335
17c7a7a48dc7 Switch from actual applications to popularity
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1750
diff changeset
   336
    query = org_logic.logic.getQueryForFields(filter=filter)
17c7a7a48dc7 Switch from actual applications to popularity
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1750
diff changeset
   337
    organizations = org_logic.logic.getAll(query)
17c7a7a48dc7 Switch from actual applications to popularity
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1750
diff changeset
   338
17c7a7a48dc7 Switch from actual applications to popularity
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1750
diff changeset
   339
    locked_slots = adjusted_slots = {}
17c7a7a48dc7 Switch from actual applications to popularity
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1750
diff changeset
   340
1736
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   341
    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
   342
      result = request.POST['result']
2136
5d55e61dd338 Add a submit method and button to slots view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2130
diff changeset
   343
      submit = request.GET.get('submit')
2147
5dd2091c8f0c Allow loading a previously saved slot allocation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2140
diff changeset
   344
      load = request.GET.get('load')
5dd2091c8f0c Allow loading a previously saved slot allocation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2140
diff changeset
   345
      stored = program.slots_allocation
5dd2091c8f0c Allow loading a previously saved slot allocation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2140
diff changeset
   346
5dd2091c8f0c Allow loading a previously saved slot allocation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2140
diff changeset
   347
      if load and stored:
5dd2091c8f0c Allow loading a previously saved slot allocation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2140
diff changeset
   348
        result = stored
1736
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   349
1751
17c7a7a48dc7 Switch from actual applications to popularity
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1750
diff changeset
   350
      from_json = simplejson.loads(result)
2147
5dd2091c8f0c Allow loading a previously saved slot allocation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2140
diff changeset
   351
1751
17c7a7a48dc7 Switch from actual applications to popularity
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1750
diff changeset
   352
      locked_slots = dicts.groupDictBy(from_json, 'locked', 'slots')
17c7a7a48dc7 Switch from actual applications to popularity
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1750
diff changeset
   353
2139
43a02512ebf7 Change iterative to algorithm in slot allocator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2136
diff changeset
   354
      if submit:
43a02512ebf7 Change iterative to algorithm in slot allocator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2136
diff changeset
   355
        program.slots_allocation = result
43a02512ebf7 Change iterative to algorithm in slot allocator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2136
diff changeset
   356
        program.put()
43a02512ebf7 Change iterative to algorithm in slot allocator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2136
diff changeset
   357
1855
8c76c32a2392 Fixed a very obvious bug in slots()
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1852
diff changeset
   358
    orgs = {}
1751
17c7a7a48dc7 Switch from actual applications to popularity
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1750
diff changeset
   359
    applications = {}
2130
83f4fab7c556 Drop the 'adjustement' part of slots allocation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2128
diff changeset
   360
    max = {}
1736
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   361
1751
17c7a7a48dc7 Switch from actual applications to popularity
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1750
diff changeset
   362
    for org in organizations:
1855
8c76c32a2392 Fixed a very obvious bug in slots()
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1852
diff changeset
   363
      orgs[org.link_id] = org
2106
2131c4b05ca3 Use the new nr_applications and nr_mentors
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2080
diff changeset
   364
      applications[org.link_id] = org.nr_applications
2130
83f4fab7c556 Drop the 'adjustement' part of slots allocation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2128
diff changeset
   365
      max[org.link_id] = min(org.nr_mentors, org.slots_desired)
1736
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   366
2139
43a02512ebf7 Change iterative to algorithm in slot allocator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2136
diff changeset
   367
    max_slots_per_org = program.max_slots
43a02512ebf7 Change iterative to algorithm in slot allocator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2136
diff changeset
   368
    min_slots_per_org = program.min_slots
2140
32b0731f0bf5 Add a new allocation algorithm and use it
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2139
diff changeset
   369
    algorithm = 2
1736
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   370
2130
83f4fab7c556 Drop the 'adjustement' part of slots allocation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2128
diff changeset
   371
    allocator = allocations.Allocator(orgs.keys(), applications, max,
2076
1cd180cc56c9 Style fixes and removal of unused imports in soc.views.models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2064
diff changeset
   372
                                      program_slots, max_slots_per_org,
2139
43a02512ebf7 Change iterative to algorithm in slot allocator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2136
diff changeset
   373
                                      min_slots_per_org, algorithm)
1736
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   374
2130
83f4fab7c556 Drop the 'adjustement' part of slots allocation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2128
diff changeset
   375
    result = allocator.allocate(locked_slots)
1736
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   376
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   377
    data = []
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   378
2139
43a02512ebf7 Change iterative to algorithm in slot allocator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2136
diff changeset
   379
    # TODO: remove adjustment here and in the JS
1736
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   380
    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
   381
      org = orgs[link_id]
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   382
      data.append({
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   383
          'link_id': link_id,
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   384
          'slots': count,
1855
8c76c32a2392 Fixed a very obvious bug in slots()
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1852
diff changeset
   385
          'locked': locked_slots.get(link_id, 0),
8c76c32a2392 Fixed a very obvious bug in slots()
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1852
diff changeset
   386
          'adjustment': adjusted_slots.get(link_id, 0),
1736
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   387
          })
1706
9609e2a0d7d7 Added a slots JSON call
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1705
diff changeset
   388
9609e2a0d7d7 Added a slots JSON call
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1705
diff changeset
   389
    return self.json(request, data)
9609e2a0d7d7 Added a slots JSON call
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1705
diff changeset
   390
9609e2a0d7d7 Added a slots JSON call
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1705
diff changeset
   391
  @decorators.merge_params
9609e2a0d7d7 Added a slots JSON call
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1705
diff changeset
   392
  @decorators.check_access
1705
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   393
  def assignSlots(self, request, access_type, page_name=None,
1857
febcaeb4234b Style fixes.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1855
diff changeset
   394
                  params=None, **kwargs):
1705
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   395
    """View that allows to assign slots to orgs.
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   396
    """
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   397
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   398
    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
   399
1841
d7ac10b583fb Don't override org view params
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1830
diff changeset
   400
    org_params = organization_view.view.getParams().copy()
1745
d8a45f622241 Don't override the params argument
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1743
diff changeset
   401
    org_params['list_template'] = 'soc/program/allocation/allocation.html'
d8a45f622241 Don't override the params argument
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1743
diff changeset
   402
    org_params['list_heading'] = 'soc/program/allocation/heading.html'
d8a45f622241 Don't override the params argument
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1743
diff changeset
   403
    org_params['list_row'] = 'soc/program/allocation/row.html'
d8a45f622241 Don't override the params argument
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1743
diff changeset
   404
    org_params['list_pagination'] = 'soc/list/no_pagination.html'
1705
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   405
1762
c47b9deb22ac Use getFromKeyFieldsOr404 in slots() and allocateSlots()
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1751
diff changeset
   406
    program = program_logic.logic.getFromKeyFieldsOr404(kwargs)
1705
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   407
2128
7da77549bdeb Use the new self._getAcceptedOrgsList in slots view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2127
diff changeset
   408
    description = self.DEF_SLOTS_ALLOCATION_MSG
7da77549bdeb Use the new self._getAcceptedOrgsList in slots view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2127
diff changeset
   409
1705
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   410
    filter = {
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   411
        'scope': program,
1736
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   412
        'status': 'active',
1705
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   413
        }
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   414
2128
7da77549bdeb Use the new self._getAcceptedOrgsList in slots view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2127
diff changeset
   415
    content = self._getAcceptedOrgsList(description, org_params, filter, False)
7da77549bdeb Use the new self._getAcceptedOrgsList in slots view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2127
diff changeset
   416
1705
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   417
    contents = [content]
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   418
1747
02f15a955c42 Provide the 'return_url' in the allocate slots view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1745
diff changeset
   419
    return_url =  "http://%(host)s%(index)s" % {
02f15a955c42 Provide the 'return_url' in the allocate slots view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1745
diff changeset
   420
      'host' : os.environ['HTTP_HOST'],
02f15a955c42 Provide the 'return_url' in the allocate slots view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1745
diff changeset
   421
      'index': redirects.getSlotsRedirect(program, params)
02f15a955c42 Provide the 'return_url' in the allocate slots view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1745
diff changeset
   422
      }
02f15a955c42 Provide the 'return_url' in the allocate slots view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1745
diff changeset
   423
1736
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   424
    context = {
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   425
        'total_slots': program.slots,
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   426
        'uses_json': True,
1747
02f15a955c42 Provide the 'return_url' in the allocate slots view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1745
diff changeset
   427
        'uses_slot_allocator': True,
02f15a955c42 Provide the 'return_url' in the allocate slots view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1745
diff changeset
   428
        'return_url': return_url,
1736
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   429
        }
72fb61f67ff5 Add and use the new and improved allocation scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1706
diff changeset
   430
1745
d8a45f622241 Don't override the params argument
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1743
diff changeset
   431
    return self._list(request, org_params, contents, page_name, context)
1705
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   432
1830
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   433
  @decorators.merge_params
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   434
  @decorators.check_access
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   435
  def showDuplicates(self, request, access_type, page_name=None,
1857
febcaeb4234b Style fixes.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1855
diff changeset
   436
                     params=None, **kwargs):
2778
44bb0e89cc1b Whitespace fix in Program view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 2771
diff changeset
   437
    """View in which a host can see which students have been assigned
2076
1cd180cc56c9 Style fixes and removal of unused imports in soc.views.models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2064
diff changeset
   438
       multiple slots.
1830
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   439
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   440
    For params see base.view.Public().
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   441
    """
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   442
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   443
    from django.utils import simplejson
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   444
2055
b4375ec63de5 Enable storing of the duplicate calculation results.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2004
diff changeset
   445
    from soc.logic.models.proposal_duplicates import logic as duplicates_logic
b4375ec63de5 Enable storing of the duplicate calculation results.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2004
diff changeset
   446
1830
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   447
    program_entity = program_logic.logic.getFromKeyFieldsOr404(kwargs)
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   448
2055
b4375ec63de5 Enable storing of the duplicate calculation results.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2004
diff changeset
   449
    if request.POST and request.POST.get('result'):
b4375ec63de5 Enable storing of the duplicate calculation results.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2004
diff changeset
   450
      # store result in the datastore
b4375ec63de5 Enable storing of the duplicate calculation results.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2004
diff changeset
   451
      fields = {'link_id': program_entity.link_id,
b4375ec63de5 Enable storing of the duplicate calculation results.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2004
diff changeset
   452
                'scope': program_entity,
2160
3f9dd37d98a8 Use key().id_or_name() instead of key().name()
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2156
diff changeset
   453
                'scope_path': program_entity.key().id_or_name(),
2055
b4375ec63de5 Enable storing of the duplicate calculation results.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2004
diff changeset
   454
                'json_representation' : request.POST['result']
b4375ec63de5 Enable storing of the duplicate calculation results.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2004
diff changeset
   455
                }
b4375ec63de5 Enable storing of the duplicate calculation results.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2004
diff changeset
   456
      key_name = duplicates_logic.getKeyNameFromFields(fields)
b4375ec63de5 Enable storing of the duplicate calculation results.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2004
diff changeset
   457
      duplicates_logic.updateOrCreateFromKeyName(fields, key_name)
2064
031406b4789d Returning a JSON response on successfully storing the found duplicates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2055
diff changeset
   458
031406b4789d Returning a JSON response on successfully storing the found duplicates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2055
diff changeset
   459
      response = simplejson.dumps({'status': 'done'})
031406b4789d Returning a JSON response on successfully storing the found duplicates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2055
diff changeset
   460
      return http.HttpResponse(response)
2055
b4375ec63de5 Enable storing of the duplicate calculation results.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2004
diff changeset
   461
1830
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   462
    context = helper.responses.getUniversalContext(request)
1850
1e39b32ff4d7 Enable javascript in duplicate students view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1848
diff changeset
   463
    helper.responses.useJavaScript(context, params['js_uses_all'])
2004
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1996
diff changeset
   464
    context['uses_duplicates'] = True
4d9e41c947fd Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1996
diff changeset
   465
    context['uses_json'] = True
1830
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   466
    context['page_name'] = page_name
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   467
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   468
    # get all orgs for this program who are active and have slots assigned
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   469
    fields = {'scope': program_entity,
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   470
              'slots >': 0,
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   471
              'status': 'active'}
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   472
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   473
    query = org_logic.logic.getQueryForFields(fields)
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   474
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   475
    to_json = {
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   476
        'nr_of_orgs': query.count(),
2160
3f9dd37d98a8 Use key().id_or_name() instead of key().name()
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2156
diff changeset
   477
        'program_key': program_entity.key().id_or_name()}
1830
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   478
    json = simplejson.dumps(to_json)
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   479
    context['info'] = json
2055
b4375ec63de5 Enable storing of the duplicate calculation results.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2004
diff changeset
   480
    context['offset_length'] = 10
1830
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   481
2055
b4375ec63de5 Enable storing of the duplicate calculation results.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2004
diff changeset
   482
    fields = {'link_id': program_entity.link_id,
b4375ec63de5 Enable storing of the duplicate calculation results.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2004
diff changeset
   483
              'scope': program_entity}
b4375ec63de5 Enable storing of the duplicate calculation results.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2004
diff changeset
   484
    duplicates = duplicates_logic.getForFields(fields, unique=True)
b4375ec63de5 Enable storing of the duplicate calculation results.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2004
diff changeset
   485
b4375ec63de5 Enable storing of the duplicate calculation results.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2004
diff changeset
   486
    if duplicates:
b4375ec63de5 Enable storing of the duplicate calculation results.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2004
diff changeset
   487
      # we have stored information
2361
40b0c25a5793 Some more pylint fixes in different Melange modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2292
diff changeset
   488
      # pylint: disable-msg=E1103
2055
b4375ec63de5 Enable storing of the duplicate calculation results.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2004
diff changeset
   489
      context['duplicate_cache_content'] = duplicates.json_representation
b4375ec63de5 Enable storing of the duplicate calculation results.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2004
diff changeset
   490
      context['date_of_calculation'] = duplicates.calculated_on
b4375ec63de5 Enable storing of the duplicate calculation results.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2004
diff changeset
   491
    else:
b4375ec63de5 Enable storing of the duplicate calculation results.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2004
diff changeset
   492
      # no information stored
b4375ec63de5 Enable storing of the duplicate calculation results.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2004
diff changeset
   493
      context['duplicate_cache_content'] = simplejson.dumps({})
1830
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   494
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   495
    template = 'soc/program/show_duplicates.html'
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   496
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   497
    return helper.responses.respond(request, template=template, context=context)
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   498
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   499
  @decorators.merge_params
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   500
  @decorators.check_access
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   501
  def assignedProposals(self, request, access_type, page_name=None,
1857
febcaeb4234b Style fixes.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1855
diff changeset
   502
                        params=None, filter=None, **kwargs):
1830
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   503
    """Returns a JSON dict containing all the proposals that would have
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   504
    a slot assigned for a specific set of orgs.
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   505
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   506
    The request.GET limit and offset determines how many and which
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   507
    organizations should be returned.
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   508
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   509
    For params see base.View.public().
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   510
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   511
    Returns: JSON object with a collection of orgs and proposals. Containing
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   512
             identification information and contact information.
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   513
    """
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   514
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   515
    get_dict = request.GET
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   516
1917
334094450b77 Fixed a bug where giving a limit but no offset would cause a 505.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1911
diff changeset
   517
    if not (get_dict.get('limit') and get_dict.get('offset')):
1830
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   518
      return self.json(request, {})
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   519
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   520
    try:
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   521
      limit = max(0, int(get_dict['limit']))
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   522
      offset = max(0, int(get_dict['offset']))
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   523
    except ValueError:
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   524
      return self.json(request, {})
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   525
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   526
    program_entity = program_logic.logic.getFromKeyFieldsOr404(kwargs)
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   527
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   528
    fields = {'scope': program_entity,
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   529
              'slots >': 0,
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   530
              'status': 'active'}
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   531
2778
44bb0e89cc1b Whitespace fix in Program view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 2771
diff changeset
   532
    org_entities = org_logic.logic.getForFields(fields,
2076
1cd180cc56c9 Style fixes and removal of unused imports in soc.views.models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2064
diff changeset
   533
        limit=limit, offset=offset)
1830
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   534
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   535
    orgs_data = {}
1919
1ec857439499 Proposal data is now stored in a list rather then a dictionary for the AssignedProposals JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1918
diff changeset
   536
    proposals_data = []
1830
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   537
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   538
    # for each org get the proposals who will be assigned a slot
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   539
    for org in org_entities:
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   540
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   541
      org_data = {'name': org.name}
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   542
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   543
      fields = {'scope': org,
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   544
                'status': 'active',
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   545
                'user': org.founder}
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   546
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   547
      org_admin = org_admin_logic.logic.getForFields(fields, unique=True)
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   548
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   549
      if org_admin:
2361
40b0c25a5793 Some more pylint fixes in different Melange modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2292
diff changeset
   550
        # pylint: disable-msg=E1103
1830
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   551
        org_data['admin_name'] = org_admin.name()
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   552
        org_data['admin_email'] = org_admin.email
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   553
2197
efa28a1ccf76 Moved the code to retrieve all Proposal which should be accepted for one Organization to the Proposal Logic module.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2194
diff changeset
   554
      proposals = student_proposal_logic.logic.getProposalsToBeAcceptedForOrg(
2199
9e22f90ec781 Rename that should have been part of r2953.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2197
diff changeset
   555
          org, step_size=program_entity.max_slots)
1830
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   556
2197
efa28a1ccf76 Moved the code to retrieve all Proposal which should be accepted for one Organization to the Proposal Logic module.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2194
diff changeset
   557
      if not proposals:
efa28a1ccf76 Moved the code to retrieve all Proposal which should be accepted for one Organization to the Proposal Logic module.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2194
diff changeset
   558
        # nothing to accept, next organization
1830
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   559
        continue
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   560
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   561
      # store information about the org
2160
3f9dd37d98a8 Use key().id_or_name() instead of key().name()
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2156
diff changeset
   562
      orgs_data[org.key().id_or_name()] = org_data
1830
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   563
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   564
      # store each proposal in the dictionary
2180
7b8dcd7aab75 Fix a bug in duplicate detection
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2160
diff changeset
   565
      for proposal in proposals:
1830
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   566
        student_entity = proposal.scope
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   567
1919
1ec857439499 Proposal data is now stored in a list rather then a dictionary for the AssignedProposals JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1918
diff changeset
   568
        proposals_data.append(
2160
3f9dd37d98a8 Use key().id_or_name() instead of key().name()
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2156
diff changeset
   569
            {'key_name': proposal.key().id_or_name(),
1830
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   570
            'proposal_title': proposal.title,
2160
3f9dd37d98a8 Use key().id_or_name() instead of key().name()
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2156
diff changeset
   571
            'student_key': student_entity.key().id_or_name(),
1830
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   572
            'student_name': student_entity.name(),
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   573
            'student_contact': student_entity.email,
2160
3f9dd37d98a8 Use key().id_or_name() instead of key().name()
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2156
diff changeset
   574
            'org_key': org.key().id_or_name()
1919
1ec857439499 Proposal data is now stored in a list rather then a dictionary for the AssignedProposals JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1918
diff changeset
   575
            })
1830
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   576
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   577
    # return all the data in JSON format
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   578
    data = {'orgs': orgs_data,
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   579
            'proposals': proposals_data}
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   580
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   581
    return self.json(request, data)
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   582
769
a0ee643fe832 Added an elementary workflow choosing method to program creation.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 755
diff changeset
   583
  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
   584
    """See base._editPost().
a0ee643fe832 Added an elementary workflow choosing method to program creation.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 755
diff changeset
   585
    """
777
16dcdb8f3357 Added an 'edit timeline' button to the program edit page
Sverre Rabbelier <srabbelier@gmail.com>
parents: 771
diff changeset
   586
1475
22b63ab59b27 Make timeline a Linkable
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1470
diff changeset
   587
    super(View, self)._editPost(request, entity, fields)
22b63ab59b27 Make timeline a Linkable
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1470
diff changeset
   588
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
   589
    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
   590
      # 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
   591
      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
   592
    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
   593
      # 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
   594
      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
   595
16dcdb8f3357 Added an 'edit timeline' button to the program edit page
Sverre Rabbelier <srabbelier@gmail.com>
parents: 771
diff changeset
   596
  def _createTimelineForType(self, fields):
771
0b1beae179f5 Typo and style fixes.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 770
diff changeset
   597
    """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
   598
    """
777
16dcdb8f3357 Added an 'edit timeline' button to the program edit page
Sverre Rabbelier <srabbelier@gmail.com>
parents: 771
diff changeset
   599
16dcdb8f3357 Added an 'edit timeline' button to the program edit page
Sverre Rabbelier <srabbelier@gmail.com>
parents: 771
diff changeset
   600
    workflow = fields['workflow']
16dcdb8f3357 Added an 'edit timeline' button to the program edit page
Sverre Rabbelier <srabbelier@gmail.com>
parents: 771
diff changeset
   601
778
bc13cd968946 Added support for mutliple edit forms based on entity type
Sverre Rabbelier <srabbelier@gmail.com>
parents: 777
diff changeset
   602
    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
   603
1512
97c4a718d6f4 Remove updateOrCreateFromFields and it's uses
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1511
diff changeset
   604
    properties = timeline_logic.getKeyFieldsFromFields(fields)
97c4a718d6f4 Remove updateOrCreateFromFields and it's uses
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1511
diff changeset
   605
    key_name = timeline_logic.getKeyNameFromFields(properties)
97c4a718d6f4 Remove updateOrCreateFromFields and it's uses
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1511
diff changeset
   606
1475
22b63ab59b27 Make timeline a Linkable
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1470
diff changeset
   607
    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
   608
1512
97c4a718d6f4 Remove updateOrCreateFromFields and it's uses
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1511
diff changeset
   609
    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
   610
    return timeline
643
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   611
1038
0a0bc446f869 Allow for a program on/off switch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1036
diff changeset
   612
  @decorators.merge_params
1017
6ad4fdb48840 Cache access checks and disable sidebar caching
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1007
diff changeset
   613
  def getExtraMenus(self, id, user, params=None):
700
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   614
    """Returns the extra menu's for this view.
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   615
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   616
    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
   617
    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
   618
    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
   619
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   620
    Args:
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   621
      params: a dict with params for this View.
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   622
    """
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   623
2543
4c95d717a976 Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2540
diff changeset
   624
    from soc.views.models import survey as survey_view
4c95d717a976 Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2540
diff changeset
   625
    from soc.views.models import project_survey as project_survey_view
4c95d717a976 Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2540
diff changeset
   626
    from soc.views.models import grading_project_survey as grading_survey_view
4c95d717a976 Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2540
diff changeset
   627
700
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   628
    logic = params['logic']
1038
0a0bc446f869 Allow for a program on/off switch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1036
diff changeset
   629
    rights = params['rights']
700
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   630
1107
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   631
    # 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
   632
    fields = {'status': ['invisible', 'visible']}
1107
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   633
    entities = logic.getForFields(fields)
700
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   634
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   635
    menus = []
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   636
1038
0a0bc446f869 Allow for a program on/off switch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1036
diff changeset
   637
    rights.setCurrentUser(id, user)
0a0bc446f869 Allow for a program on/off switch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1036
diff changeset
   638
700
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   639
    for entity in entities:
1107
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   640
      items = []
1038
0a0bc446f869 Allow for a program on/off switch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1036
diff changeset
   641
1107
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   642
      if entity.status == 'visible':
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   643
        # 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
   644
        items += document_view.view.getMenusForScope(entity, params)
2543
4c95d717a976 Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2540
diff changeset
   645
        items += survey_view.view.getMenusForScope(entity, params, id, user)
4c95d717a976 Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2540
diff changeset
   646
        items += project_survey_view.view.getMenusForScope(
4c95d717a976 Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2540
diff changeset
   647
            entity, params, id, user)
4c95d717a976 Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2540
diff changeset
   648
        items += grading_survey_view.view.getMenusForScope(
4c95d717a976 Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2540
diff changeset
   649
            entity, params, id, user)
1317
fad74cf4e5da Add a 'list documents' link everywhere
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1308
diff changeset
   650
        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
   651
      try:
1107
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   652
        # 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
   653
        rights.doCachedCheck('checkIsHostForProgram',
1325
8368086dd3a7 Add a list_public view to organization
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1321
diff changeset
   654
                             {'scope_path': entity.scope_path,
8368086dd3a7 Add a list_public view to organization
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1321
diff changeset
   655
                              'link_id': entity.link_id}, [])
1107
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   656
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   657
        if entity.status == 'invisible':
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   658
          # 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
   659
          items += document_view.view.getMenusForScope(entity, params)
2543
4c95d717a976 Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2540
diff changeset
   660
          items += survey_view.view.getMenusForScope(entity, params, id, user)
4c95d717a976 Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2540
diff changeset
   661
          items += project_survey_view.view.getMenusForScope(
4c95d717a976 Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2540
diff changeset
   662
              entity, params, id, user)
4c95d717a976 Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2540
diff changeset
   663
          items += grading_survey_view.view.getMenusForScope(
4c95d717a976 Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2540
diff changeset
   664
              entity, params, id, user)
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
   665
          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
   666
1238
af56ae7397ab Added scoped group_app listing.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1225
diff changeset
   667
        items += [(redirects.getReviewOverviewRedirect(
af56ae7397ab Added scoped group_app listing.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1225
diff changeset
   668
            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
   669
            "Review Organization Applications", 'any_access')]
1107
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   670
        # add link to edit Program Profile
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   671
        items += [(redirects.getEditRedirect(entity, params),
2156
0f5f68891822 Added two menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2149
diff changeset
   672
            'Edit Program Profile', 'any_access')]
1911
87c3e62b28dc Added a Assign Slots link to sidebar for Hosts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1909
diff changeset
   673
        # add link to Assign Slots
87c3e62b28dc Added a Assign Slots link to sidebar for Hosts
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1909
diff changeset
   674
        items += [(redirects.getAssignSlotsRedirect(entity, params),
2156
0f5f68891822 Added two menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2149
diff changeset
   675
            'Assign Slots', 'any_access')]
0f5f68891822 Added two menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2149
diff changeset
   676
        # add link to Show Duplicate project assignments
0f5f68891822 Added two menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2149
diff changeset
   677
        items += [(redirects.getShowDuplicatesRedirect(entity, params),
0f5f68891822 Added two menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2149
diff changeset
   678
            'Show Duplicate Project Assignments', 'any_access')]
1107
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   679
        # add link to edit Program Timeline
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   680
        items += [(redirects.getEditRedirect(entity, {'url_name': 'timeline'}),
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   681
            "Edit Program Timeline", 'any_access')]
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   682
        # 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
   683
        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
   684
            "Create a New Document", 'any_access')]
1317
fad74cf4e5da Add a 'list documents' link everywhere
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1308
diff changeset
   685
        # add link to list all Program Document
fad74cf4e5da Add a 'list documents' link everywhere
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1308
diff changeset
   686
        items += [(redirects.getListDocumentsRedirect(entity, 'program'),
fad74cf4e5da Add a 'list documents' link everywhere
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1308
diff changeset
   687
            "List Documents", 'any_access')]
2437
32620683a7a6 Added Survey menu items to the Program menu.
Daniel Diniz <ajaksu@gmail.com>
parents: 2410
diff changeset
   688
        # add link to create a new Program Survey
2495
0113c2de89d3 Enable the ProjectSurvey and GradingProjectSurvey views in the core.
Daniel Diniz <ajaksu@gmail.com>
parents: 2479
diff changeset
   689
        items += [(redirects.getCreateSurveyRedirect(entity, 'program',
2540
1e44d71c0e3e Several style fixes due to code reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2509
diff changeset
   690
            'survey'),
2437
32620683a7a6 Added Survey menu items to the Program menu.
Daniel Diniz <ajaksu@gmail.com>
parents: 2410
diff changeset
   691
            "Create a New Survey", 'any_access')]
32620683a7a6 Added Survey menu items to the Program menu.
Daniel Diniz <ajaksu@gmail.com>
parents: 2410
diff changeset
   692
        # add link to list all Program Surveys
2495
0113c2de89d3 Enable the ProjectSurvey and GradingProjectSurvey views in the core.
Daniel Diniz <ajaksu@gmail.com>
parents: 2479
diff changeset
   693
        items += [(redirects.getListSurveysRedirect(entity, 'program',
2540
1e44d71c0e3e Several style fixes due to code reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2509
diff changeset
   694
            'survey'),
2437
32620683a7a6 Added Survey menu items to the Program menu.
Daniel Diniz <ajaksu@gmail.com>
parents: 2410
diff changeset
   695
            "List Surveys", 'any_access')]
2495
0113c2de89d3 Enable the ProjectSurvey and GradingProjectSurvey views in the core.
Daniel Diniz <ajaksu@gmail.com>
parents: 2479
diff changeset
   696
        # add link to create a new Project Survey
0113c2de89d3 Enable the ProjectSurvey and GradingProjectSurvey views in the core.
Daniel Diniz <ajaksu@gmail.com>
parents: 2479
diff changeset
   697
        items += [(redirects.getCreateSurveyRedirect(entity, 'program',
2540
1e44d71c0e3e Several style fixes due to code reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2509
diff changeset
   698
            'project_survey'),
2495
0113c2de89d3 Enable the ProjectSurvey and GradingProjectSurvey views in the core.
Daniel Diniz <ajaksu@gmail.com>
parents: 2479
diff changeset
   699
            "Create a New Project Survey", 'any_access')]
0113c2de89d3 Enable the ProjectSurvey and GradingProjectSurvey views in the core.
Daniel Diniz <ajaksu@gmail.com>
parents: 2479
diff changeset
   700
        # add link to list all Project Surveys
0113c2de89d3 Enable the ProjectSurvey and GradingProjectSurvey views in the core.
Daniel Diniz <ajaksu@gmail.com>
parents: 2479
diff changeset
   701
        items += [(redirects.getListSurveysRedirect(entity, 'program',
2540
1e44d71c0e3e Several style fixes due to code reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2509
diff changeset
   702
            'project_survey'),
2495
0113c2de89d3 Enable the ProjectSurvey and GradingProjectSurvey views in the core.
Daniel Diniz <ajaksu@gmail.com>
parents: 2479
diff changeset
   703
            "List Project Surveys", 'any_access')]
0113c2de89d3 Enable the ProjectSurvey and GradingProjectSurvey views in the core.
Daniel Diniz <ajaksu@gmail.com>
parents: 2479
diff changeset
   704
        # add link to create a new Grading Survey
0113c2de89d3 Enable the ProjectSurvey and GradingProjectSurvey views in the core.
Daniel Diniz <ajaksu@gmail.com>
parents: 2479
diff changeset
   705
        items += [(redirects.getCreateSurveyRedirect(entity, 'program',
2540
1e44d71c0e3e Several style fixes due to code reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2509
diff changeset
   706
            'grading_project_survey'),
2495
0113c2de89d3 Enable the ProjectSurvey and GradingProjectSurvey views in the core.
Daniel Diniz <ajaksu@gmail.com>
parents: 2479
diff changeset
   707
            "Create a New Grading Survey", 'any_access')]
0113c2de89d3 Enable the ProjectSurvey and GradingProjectSurvey views in the core.
Daniel Diniz <ajaksu@gmail.com>
parents: 2479
diff changeset
   708
        # add link to list all Grading Surveys
0113c2de89d3 Enable the ProjectSurvey and GradingProjectSurvey views in the core.
Daniel Diniz <ajaksu@gmail.com>
parents: 2479
diff changeset
   709
        items += [(redirects.getListSurveysRedirect(entity, 'program',
2540
1e44d71c0e3e Several style fixes due to code reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2509
diff changeset
   710
            'grading_project_survey'),
2495
0113c2de89d3 Enable the ProjectSurvey and GradingProjectSurvey views in the core.
Daniel Diniz <ajaksu@gmail.com>
parents: 2479
diff changeset
   711
            "List Grading Surveys", 'any_access')]
2706
198926c38229 Add link to withdraw student project page
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 2543
diff changeset
   712
        # add link to withdraw Student Projects
198926c38229 Add link to withdraw student project page
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 2543
diff changeset
   713
        items += [(redirects.getWithdrawRedirect(
198926c38229 Add link to withdraw student project page
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 2543
diff changeset
   714
            entity, {'url_name': 'student_project'}),
198926c38229 Add link to withdraw student project page
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 2543
diff changeset
   715
            "Withdraw Student Projects", 'any_access')]
1107
a878188e225c Added status to program.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1097
diff changeset
   716
1097
1f7015b33a0c Add a 'Create new document' link for clubs, sponsors and programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1074
diff changeset
   717
      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
   718
        pass
1f7015b33a0c Add a 'Create new document' link for clubs, sponsors and programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1074
diff changeset
   719
1162
1d9396d75c13 Do not return empty menu's in program.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1144
diff changeset
   720
      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
   721
      if not items:
1d9396d75c13 Do not return empty menu's in program.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1144
diff changeset
   722
        continue
1d9396d75c13 Do not return empty menu's in program.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1144
diff changeset
   723
700
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   724
      menu = {}
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   725
      menu['heading'] = entity.short_name
1162
1d9396d75c13 Do not return empty menu's in program.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1144
diff changeset
   726
      menu['items'] = items
1024
2a0ae6483825 Group dynamically generated menu items
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1023
diff changeset
   727
      menu['group'] = 'Programs'
700
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   728
      menus.append(menu)
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   729
8baf8367340d Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 681
diff changeset
   730
    return menus
647
355ac73823a1 Swap order of merged params to fix sponsor select view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 643
diff changeset
   731
1317
fad74cf4e5da Add a 'list documents' link everywhere
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1308
diff changeset
   732
  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
   733
    """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
   734
    """
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
   735
    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
   736
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
   737
    #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
   738
    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
   739
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
   740
    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
   741
      # 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
   742
      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
   743
          (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
   744
          "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
   745
2778
44bb0e89cc1b Whitespace fix in Program view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 2771
diff changeset
   746
    if user and timeline_helper.isAfterEvent(timeline_entity,
2076
1cd180cc56c9 Style fixes and removal of unused imports in soc.views.models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2064
diff changeset
   747
        'org_signup_start'):
1852
ea2e23e5b7a1 Show 'list my org apps' only if you have org apps
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1850
diff changeset
   748
      filter = {
ea2e23e5b7a1 Show 'list my org apps' only if you have org apps
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1850
diff changeset
   749
          'applicant': user,
ea2e23e5b7a1 Show 'list my org apps' only if you have org apps
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1850
diff changeset
   750
          'scope': program_entity,
ea2e23e5b7a1 Show 'list my org apps' only if you have org apps
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1850
diff changeset
   751
          }
ea2e23e5b7a1 Show 'list my org apps' only if you have org apps
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1850
diff changeset
   752
ea2e23e5b7a1 Show 'list my org apps' only if you have org apps
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1850
diff changeset
   753
      if org_app_logic.logic.getForFields(filter, unique=True):
ea2e23e5b7a1 Show 'list my org apps' only if you have org apps
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1850
diff changeset
   754
        # add the 'List my Organization Applications' link
ea2e23e5b7a1 Show 'list my org apps' only if you have org apps
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1850
diff changeset
   755
        items += [
ea2e23e5b7a1 Show 'list my org apps' only if you have org apps
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1850
diff changeset
   756
            (redirects.getListSelfRedirect(program_entity,
ea2e23e5b7a1 Show 'list my org apps' only if you have org apps
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1850
diff changeset
   757
                                           {'url_name' : 'org_app'}),
ea2e23e5b7a1 Show 'list my org apps' only if you have org apps
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1850
diff changeset
   758
             "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
   759
1437
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   760
    # 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
   761
    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
   762
              '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
   763
              'status': 'active'}
1437
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   764
    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
   765
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   766
    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
   767
      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
   768
                                       params, id, user)
1437
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   769
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   770
    # 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
   771
    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
   772
              '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
   773
              'status': 'active'}
1437
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   774
    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
   775
    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
   776
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   777
    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
   778
      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
   779
                                            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
   780
1971
0b7f57c16fee Only show 'Register as student' link student has a user profile
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1968
diff changeset
   781
    if user and not (student_entity or mentor_entity or org_admin_entity):
1437
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   782
      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
   783
        # this user does not have a role yet for this program
2160
3f9dd37d98a8 Use key().id_or_name() instead of key().name()
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2156
diff changeset
   784
        items += [('/student/apply/%s' % (program_entity.key().id_or_name()),
1437
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   785
            "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
   786
1863
d5272c2ded9f Added a 'accepted orgs' view to program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1857
diff changeset
   787
    deadline = 'accepted_organization_announced_deadline'
d5272c2ded9f Added a 'accepted orgs' view to program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1857
diff changeset
   788
d5272c2ded9f Added a 'accepted orgs' view to program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1857
diff changeset
   789
    if timeline_helper.isAfterEvent(timeline_entity, deadline):
d5272c2ded9f Added a 'accepted orgs' view to program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1857
diff changeset
   790
      url = redirects.getAcceptedOrgsRedirect(program_entity, params)
1437
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   791
      # add a link to list all the organizations
1863
d5272c2ded9f Added a 'accepted orgs' view to program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1857
diff changeset
   792
      items += [(url, "List participating Organizations", 'any_access')]
1437
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   793
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   794
      if not student_entity:
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   795
        # add apply to become a mentor link
2160
3f9dd37d98a8 Use key().id_or_name() instead of key().name()
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2156
diff changeset
   796
        items += [('/org/apply_mentor/%s' % (program_entity.key().id_or_name()),
1437
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   797
         "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
   798
2292
80361f34c457 Add full list of accepted students
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 2257
diff changeset
   799
    deadline = 'accepted_students_announced_deadline'
80361f34c457 Add full list of accepted students
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 2257
diff changeset
   800
80361f34c457 Add full list of accepted students
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 2257
diff changeset
   801
    if timeline_helper.isAfterEvent(timeline_entity, deadline):
80361f34c457 Add full list of accepted students
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 2257
diff changeset
   802
      items += [(redirects.getListProjectsRedirect(program_entity,
80361f34c457 Add full list of accepted students
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 2257
diff changeset
   803
          {'url_name':'program'}),
80361f34c457 Add full list of accepted students
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 2257
diff changeset
   804
          "List all student projects", 'any_access')]
80361f34c457 Add full list of accepted students
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 2257
diff changeset
   805
1437
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   806
    return items
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   807
2778
44bb0e89cc1b Whitespace fix in Program view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 2771
diff changeset
   808
  def _getStudentEntries(self, program_entity, 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
   809
                         params, id, user):
1437
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   810
    """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
   811
    """
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   812
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   813
    items = []
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   814
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   815
    timeline_entity = program_entity.timeline
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   816
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   817
    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
   818
      items += [('/student_proposal/list_orgs/%s' % (
2160
3f9dd37d98a8 Use key().id_or_name() instead of key().name()
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2156
diff changeset
   819
          student_entity.key().id_or_name()),
1492
deac044c10b6 Textual change in program menu due to comment on r2113.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1490
diff changeset
   820
          "Submit your Student Proposal", 'any_access')]
2080
6c4cf7ae18d8 Also show 'List my student proposals' after signup closes
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2076
diff changeset
   821
6c4cf7ae18d8 Also show 'List my student proposals' after signup closes
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2076
diff changeset
   822
    if timeline_helper.isAfterEvent(timeline_entity, 'student_signup_start'):
1470
5e887fb80921 Added list my Student Proposals link to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1437
diff changeset
   823
      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
   824
          {'url_name':'student_proposal'}),
2156
0f5f68891822 Added two menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2149
diff changeset
   825
          "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
   826
2778
44bb0e89cc1b Whitespace fix in Program view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 2771
diff changeset
   827
    items += [(redirects.getEditRedirect(student_entity,
2156
0f5f68891822 Added two menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2149
diff changeset
   828
        {'url_name': 'student'}),
0f5f68891822 Added two menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2149
diff changeset
   829
        "Edit my Student Profile", 'any_access')]
0f5f68891822 Added two menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2149
diff changeset
   830
0f5f68891822 Added two menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2149
diff changeset
   831
    if timeline_helper.isAfterEvent(timeline_entity,
0f5f68891822 Added two menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2149
diff changeset
   832
                                   'accepted_students_announced_deadline'):
0f5f68891822 Added two menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2149
diff changeset
   833
      # add a link to show all projects
0f5f68891822 Added two menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2149
diff changeset
   834
      items += [(redirects.getListProjectsRedirect(program_entity,
0f5f68891822 Added two menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2149
diff changeset
   835
          {'url_name':'student'}),
0f5f68891822 Added two menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2149
diff changeset
   836
          "List my Student Projects", 'any_access')]
1996
ae53f21abb9b Add "Edit my Student Profile" link to program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1971
diff changeset
   837
2719
c8841000b863 Added link for students to resign their profile to the Program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2706
diff changeset
   838
    items += [(redirects.getManageRedirect(student_entity,
c8841000b863 Added link for students to resign their profile to the Program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2706
diff changeset
   839
        {'url_name':'student'}),
c8841000b863 Added link for students to resign their profile to the Program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2706
diff changeset
   840
        "Resign as a Student", 'any_access')]
c8841000b863 Added link for students to resign their profile to the Program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2706
diff changeset
   841
1437
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   842
    return items
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   843
1470
5e887fb80921 Added list my Student Proposals link to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1437
diff changeset
   844
  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
   845
                              mentor_entity, params, id, user):
1511
3342ce7a495c Fix some whitespace damadge and a style fix
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1492
diff changeset
   846
    """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
   847
       specific program.
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   848
    """
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   849
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   850
    # 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
   851
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   852
    items = []
eec60d5bbe95 Added several menu items to the program menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
   853
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
   854
    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
   855
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
   856
643
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   857
view = View()
b57d538a9dd3 Added programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   858
1863
d5272c2ded9f Added a 'accepted orgs' view to program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1857
diff changeset
   859
accepted_orgs = decorators.view(view.acceptedOrgs)
2292
80361f34c457 Add full list of accepted students
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 2257
diff changeset
   860
list_projects = decorators.view(view.acceptedProjects)
1584
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1564
diff changeset
   861
admin = decorators.view(view.admin)
1705
1dbce30b5757 Added a slot allocation view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   862
assign_slots = decorators.view(view.assignSlots)
1830
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   863
assigned_proposals = decorators.view(view.assignedProposals)
1584
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1564
diff changeset
   864
create = decorators.view(view.create)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1564
diff changeset
   865
delete = decorators.view(view.delete)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1564
diff changeset
   866
edit = decorators.view(view.edit)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1564
diff changeset
   867
list = decorators.view(view.list)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1564
diff changeset
   868
public = decorators.view(view.public)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1564
diff changeset
   869
export = decorators.view(view.export)
1830
b2b638076e90 Started with the view for showing students who have been assigned to multiple slots.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1764
diff changeset
   870
show_duplicates = decorators.view(view.showDuplicates)
1706
9609e2a0d7d7 Added a slots JSON call
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1705
diff changeset
   871
slots = decorators.view(view.slots)
1584
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1564
diff changeset
   872
home = decorators.view(view.home)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1564
diff changeset
   873
pick = decorators.view(view.pick)