app/soc/modules/ghop/views/models/program.py
author Daniel Hans <Daniel.M.Hans@gmail.com>
Sat, 14 Nov 2009 17:22:44 +0100
changeset 3088 08b9f4de6675
parent 3078 bd001e9ab9d4
permissions -rw-r--r--
Users who claim or work on tasks may list them without having student role.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2891
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     2
#
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     3
# Copyright 2009 the Melange authors.
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     4
#
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     8
#
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    10
#
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    16
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    17
"""GHOP specific views for Programs.
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    18
"""
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    19
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    20
__authors__ = [
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    21
    '"Madhusudan.C.S" <madhusudancs@gmail.com>',
3076
11d5fa052ad1 List view of all tasks for a GHOP student.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3067
diff changeset
    22
    '"Daniel Hans" <daniel.m.hans@gmail.com>',
2891
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    23
    '"Lennard de Rijk" <ljvderijk@gmail.com>',
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    24
  ]
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    25
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    26
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    27
import datetime
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    28
import os
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    29
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    30
from django import forms
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    31
from django import http
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    32
from django.utils.translation import ugettext
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    33
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    34
from soc.logic import cleaning
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    35
from soc.logic import dicts
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    36
from soc.logic.helper import timeline as timeline_helper
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    37
from soc.logic.models import host as host_logic
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    38
from soc.views import out_of_band
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    39
from soc.views import helper
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    40
from soc.views.helper import decorators
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    41
from soc.views.helper import dynaform
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    42
from soc.views.helper import lists
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    43
from soc.views.helper import params as params_helper
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    44
from soc.views.helper import redirects
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    45
from soc.views.helper import widgets
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    46
from soc.views.models import document as document_view
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    47
from soc.views.models import program 
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    48
from soc.views.sitemap import sidebar
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    49
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    50
import soc.cache.logic
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    51
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    52
from soc.modules.ghop.logic.models import mentor as ghop_mentor_logic
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    53
from soc.modules.ghop.logic.models import org_admin as ghop_org_admin_logic
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    54
from soc.modules.ghop.logic.models import program as ghop_program_logic
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    55
from soc.modules.ghop.logic.models import student as ghop_student_logic
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    56
from soc.modules.ghop.logic.models import task as ghop_task_logic
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    57
from soc.modules.ghop.models import task as ghop_task_model
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    58
from soc.modules.ghop.views.helper import access as ghop_access
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    59
from soc.modules.ghop.views.helper import redirects as ghop_redirects
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    60
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    61
import soc.modules.ghop.logic.models.program
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    62
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    63
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    64
class View(program.View):
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    65
  """View methods for the GHOP Program model.
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    66
  """
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    67
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    68
  DEF_PARTICIPATING_ORGS_MSG_FMT = ugettext(
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    69
      'The following is a list of all the participating organizations under '
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    70
      'the programme %(name)s. To know more about each organization and see '
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    71
      'the tasks published by them please visit the corresponding links.')
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    72
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    73
  DEF_TASK_QUOTA_ALLOCATION_MSG = ugettext(
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    74
      "Use this view to assign task quotas.")
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    75
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    76
  DEF_TASK_QUOTA_ERROR_MSG_FMT = ugettext(
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    77
      "Task Quota limit for the organizations %s do not contain"
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    78
      " a valid number(>0) and has not been updated.")
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    79
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    80
  def __init__(self, params=None):
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    81
    """Defines the fields and methods required for the program View class
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    82
    to provide the user with list, public, create, edit and delete views.
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    83
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    84
    Params:
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    85
      params: a dict with params for this View
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    86
    """
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    87
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    88
    rights = ghop_access.GHOPChecker(params)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    89
    rights['show'] = ['allow']
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    90
    rights['create'] = [('checkSeeded', ['checkHasActiveRoleForScope',
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    91
                                         host_logic.logic])]
3067
371e1979ee6a checkIsHostForProgram function takes a new 'logic' argument.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 2951
diff changeset
    92
    rights['edit'] = [('checkIsHostForProgram', [ghop_program_logic.logic])]
2891
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    93
    rights['delete'] = ['checkIsDeveloper']
2951
c904033c58e1 Added listing of all Accepted GHOPOrganizations to the Program View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2941
diff changeset
    94
    rights['accepted_orgs'] = [('checkIsAfterEvent',
c904033c58e1 Added listing of all Accepted GHOPOrganizations to the Program View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2941
diff changeset
    95
        ['student_signup_start',
c904033c58e1 Added listing of all Accepted GHOPOrganizations to the Program View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2941
diff changeset
    96
         '__all__', ghop_program_logic.logic])]
2891
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    97
    rights['task_difficulty'] = [('checkIsHostForProgram',
3067
371e1979ee6a checkIsHostForProgram function takes a new 'logic' argument.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 2951
diff changeset
    98
        [ghop_program_logic.logic])]
2891
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    99
    rights['task_type'] = [('checkIsHostForProgram',
3067
371e1979ee6a checkIsHostForProgram function takes a new 'logic' argument.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 2951
diff changeset
   100
        [ghop_program_logic.logic])]
2891
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   101
    rights['difficulty_tag_edit'] = [('checkIsHostForProgram',
3067
371e1979ee6a checkIsHostForProgram function takes a new 'logic' argument.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 2951
diff changeset
   102
        [ghop_program_logic.logic])]
2891
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   103
    rights['type_tag_edit'] = [('checkIsHostForProgram',
3067
371e1979ee6a checkIsHostForProgram function takes a new 'logic' argument.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 2951
diff changeset
   104
        [ghop_program_logic.logic])]
2891
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   105
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   106
    new_params = {}
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   107
    new_params['logic'] = soc.modules.ghop.logic.models.program.logic
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   108
    new_params['rights'] = rights
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   109
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   110
    new_params['name'] = "GHOP Program"
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   111
    new_params['module_name'] = "program"
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   112
    new_params['sidebar_grouping'] = 'Programs'
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   113
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   114
    new_params['module_package'] = 'soc.modules.ghop.views.models'
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   115
    new_params['url_name'] = 'ghop/program'
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   116
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   117
    # TODO: this list can be reduced after GSoC has been moved
2935
0b8b82b6764e Removed slots and apps_tasks_limit from extra_dynaexclude in params and added a getExtraMenus entry to callback for program.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2891
diff changeset
   118
    new_params['extra_dynaexclude'] = ['min_slots', 'max_slots',
0b8b82b6764e Removed slots and apps_tasks_limit from extra_dynaexclude in params and added a getExtraMenus entry to callback for program.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2891
diff changeset
   119
                                       'slot_allocation', 'allocations_visible',
2891
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   120
                                       'task_difficulties', 'task_types',
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   121
                                       ]
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   122
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   123
    patterns = []
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   124
    patterns += [
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   125
        (r'^%(url_name)s/(?P<access_type>assign_task_quotas)/%(key_fields)s$',
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   126
          '%(module_package)s.%(module_name)s.assign_task_quotas',
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   127
          'Assign task quota limits'),
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   128
        (r'^%(url_name)s/(?P<access_type>task_difficulty)/%(key_fields)s$',
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   129
         '%(module_package)s.%(module_name)s.task_difficulty_edit',
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   130
         'Edit Task Difficulty Tags'),
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   131
        (r'^%(url_name)s/(?P<access_type>task_type)/%(key_fields)s$',
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   132
         '%(module_package)s.%(module_name)s.task_type_edit',
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   133
         'Edit Task Type Tags'),
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   134
        (r'^%(url_name)s/(?P<access_type>difficulty_tag_edit)$',
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   135
         '%(module_package)s.%(module_name)s.difficulty_tag_edit',
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   136
         'Edit a Difficulty Tag'),
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   137
        (r'^%(url_name)s/(?P<access_type>type_tag_edit)$',
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   138
         '%(module_package)s.%(module_name)s.task_type_tag_edit',
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   139
         'Edit a Task Type Tag'),
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   140
        ]
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   141
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   142
    new_params['extra_django_patterns'] = patterns
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   143
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   144
    params = dicts.merge(params, new_params, sub_merge=True)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   145
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   146
    super(View, self).__init__(params=params)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   147
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   148
    dynafields = [
2940
ef809d10aaf1 Fixed error occuring when tags list was empty in GHOPProgram edit View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2935
diff changeset
   149
        {'name': 'overview_task_difficulties',
2891
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   150
         'base': forms.CharField,
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   151
         'label': 'Task Difficulty Levels',
2940
ef809d10aaf1 Fixed error occuring when tags list was empty in GHOPProgram edit View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2935
diff changeset
   152
         'group': 'Task Settings',
2891
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   153
         'widget': widgets.ReadOnlyInput(),
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   154
         'required': False,
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   155
         'help_text': ugettext('Lists all the difficulty levels that '
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   156
                               'can be assigned to a task. Edit them '
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   157
                               'from the Program menu on sidebar.'),
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   158
         },
2940
ef809d10aaf1 Fixed error occuring when tags list was empty in GHOPProgram edit View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2935
diff changeset
   159
         {'name': 'overview_task_types',
2891
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   160
         'base': forms.CharField,
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   161
         'label': 'Task Type Tags',
2940
ef809d10aaf1 Fixed error occuring when tags list was empty in GHOPProgram edit View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2935
diff changeset
   162
         'group': 'Task Settings',
2891
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   163
         'widget': widgets.ReadOnlyInput(),
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   164
         'required': False,
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   165
         'help_text': ugettext('Lists all the types a task can be in. '
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   166
                               'Edit them from the Program menu on sidebar.'),
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   167
         },
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   168
        ]
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   169
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   170
    dynaproperties = params_helper.getDynaFields(dynafields)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   171
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   172
    edit_form = dynaform.extendDynaForm(
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   173
        dynaform=self._params['edit_form'],
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   174
        dynaproperties=dynaproperties)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   175
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   176
    self._params['edit_form'] = edit_form
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   177
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   178
  def _editGet(self, request, entity, form):
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   179
    """See base.View._editGet().
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   180
    """
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   181
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   182
    # TODO: can't a simple join operation do this?
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   183
    tds = ghop_task_model.TaskDifficultyTag.get_by_scope(entity)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   184
    if tds:
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   185
      td_str = ''
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   186
      for td in tds[:-1]:
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   187
        td_str += str(td) + ', '
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   188
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   189
      td_str += str(tds[-1])
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   190
2941
5d2afe70420d Bron paper bag fix, should have been part of ref809d10aa.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2940
diff changeset
   191
      form.fields['overview_task_difficulties'].initial = td_str
2891
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   192
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   193
    tts = ghop_task_model.TaskTypeTag.get_by_scope(entity)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   194
    if tts:
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   195
      tt_str = ''
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   196
      for tt in tts[:-1]:
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   197
        tt_str += str(tt) + ', '
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   198
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   199
      tt_str += str(tts[-1])
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   200
2941
5d2afe70420d Bron paper bag fix, should have been part of ref809d10aa.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2940
diff changeset
   201
      form.fields['overview_task_types'].initial = tt_str
2891
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   202
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   203
    return super(View, self)._editGet(request, entity, form)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   204
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   205
  @decorators.merge_params
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   206
  @decorators.check_access
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   207
  def assignTaskQuotas(self, request, access_type, page_name=None,
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   208
                       params=None, filter=None, **kwargs):
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   209
    """View that allows to assign task quotas for accepted GHOP organization.
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   210
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   211
    This view allows the program admin to set the task quota limits
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   212
    and change them at any time when the program is active. 
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   213
    """
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   214
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   215
    # TODO: Once GAE Task APIs arrive, this view will be managed by them
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   216
    program = ghop_program_logic.logic.getFromKeyFieldsOr404(kwargs)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   217
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   218
    from soc.modules.ghop.views.models import \
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   219
        organization as ghop_organization_view
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   220
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   221
    org_params = ghop_organization_view.view.getParams().copy()
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   222
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   223
    context = {}
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   224
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   225
    if request.method == 'POST':
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   226
      return self.assignTaskQuotasPost(request, context, org_params, 
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   227
                                       page_name, params, program,
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   228
                                       **kwargs)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   229
    else: # request.method == 'GET'
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   230
      return self.assignTaskQuotasGet(request, context, org_params,
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   231
                                      page_name, params, program, 
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   232
                                      **kwargs)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   233
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   234
  def assignTaskQuotasPost(self, request, context, org_params, 
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   235
                           page_name, params, entity, **kwargs):
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   236
    """Handles the POST request for the task quota allocation page.
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   237
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   238
    Args:
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   239
        entity: the program entity
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   240
        rest: see base.View.public()
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   241
    """
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   242
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   243
    ghop_org_logic = org_params['logic']
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   244
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   245
    error_orgs = ''
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   246
    for link_id, task_count in request.POST.items():
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   247
      fields = {
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   248
          'link_id': link_id,
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   249
          'scope': entity,
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   250
          'scope_path': entity.key().id_or_name(),
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   251
          }
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   252
      key_name = ghop_org_logic.getKeyNameFromFields(fields)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   253
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   254
      try:
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   255
        task_count = int(task_count)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   256
        if task_count >= 0:
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   257
          fields['task_quota_limit'] = task_count
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   258
          ghop_org_logic.updateOrCreateFromKeyName(fields, key_name)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   259
        else:
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   260
          raise ValueError
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   261
      except ValueError:
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   262
        org_entity = ghop_org_logic.getFromKeyName(key_name)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   263
        error_orgs += org_entity.name + ', ' 
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   264
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   265
    if error_orgs:
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   266
      context['error_message'] = self.DEF_TASK_QUOTA_ERROR_MSG_FMT % (
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   267
          error_orgs[:-2])    
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   268
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   269
      return self.assignTaskQuotasGet(request, context, org_params,
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   270
                                      page_name, params, entity,
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   271
                                      **kwargs) 
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   272
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   273
    # redirect to the same page
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   274
    return http.HttpResponseRedirect('')
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   275
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   276
  def assignTaskQuotasGet(self, request, context, org_params, 
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   277
                          page_name, params, entity, **kwargs):
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   278
    """Handles the GET request for the task quota allocation page.
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   279
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   280
    Args:
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   281
        entity: the program entity
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   282
        rest see base.View.public()
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   283
    """
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   284
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   285
    org_params['list_template'] = ('modules/ghop/program/'
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   286
        'allocation/allocation.html')
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   287
    org_params['list_heading'] = ('modules/ghop/program/'
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   288
        'allocation/heading.html')
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   289
    org_params['list_row'] = 'modules/ghop/program/allocation/row.html'
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   290
    org_params['list_pagination'] = 'soc/list/no_pagination.html'
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   291
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   292
    description = self.DEF_TASK_QUOTA_ALLOCATION_MSG
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   293
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   294
    filter = {
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   295
        'scope': entity,
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   296
        'status': 'active',
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   297
        }
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   298
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   299
    content = self._getAcceptedOrgsList(description, org_params,
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   300
                                        filter, False)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   301
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   302
    contents = [content]
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   303
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   304
    return self._list(request, org_params, contents, page_name, context)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   305
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   306
  @decorators.merge_params
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   307
  def getExtraMenus(self, id, user, params=None):
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   308
    """See soc.views.models.program.View.getExtraMenus().
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   309
    """
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   310
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   311
    logic = params['logic']
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   312
    rights = params['rights']
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   313
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   314
    # only get all invisible and visible programs
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   315
    fields = {'status': ['invisible', 'visible']}
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   316
    entities = logic.getForFields(fields)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   317
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   318
    menus = []
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   319
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   320
    rights.setCurrentUser(id, user)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   321
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   322
    for entity in entities:
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   323
      items = []
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   324
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   325
      if entity.status == 'visible':
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   326
        # show the documents for this program, even for not logged in users
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   327
        items += document_view.view.getMenusForScope(entity, params)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   328
        items += self._getTimeDependentEntries(entity, params, id, user)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   329
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   330
      try:
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   331
        # check if the current user is a host for this program
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   332
        rights.doCachedCheck('checkIsHostForProgram',
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   333
                             {'scope_path': entity.scope_path,
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   334
                              'link_id': entity.link_id}, [])
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   335
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   336
        if entity.status == 'invisible':
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   337
          # still add the document links so hosts can see how it looks like
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   338
          items += document_view.view.getMenusForScope(entity, params)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   339
          items += self._getTimeDependentEntries(entity, params, id, user)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   340
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   341
        items += [(redirects.getReviewOverviewRedirect(
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   342
            entity, {'url_name': 'ghop/org_app', 'scope_view': self}),
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   343
            "Review Organization Applications", 'any_access')]
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   344
        # add link to edit Program Profile
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   345
        items += [(redirects.getEditRedirect(entity, params),
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   346
            'Edit Program Profile', 'any_access')]
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   347
        # add link to Assign Task Quota limits
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   348
        items += [(ghop_redirects.getAssignTaskQuotasRedirect(entity, params),
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   349
            'Assign Task Quota limits', 'any_access')]
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   350
        # add link to edit Program Timeline
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   351
        items += [(redirects.getEditRedirect(
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   352
            entity, {'url_name': 'ghop/timeline'}),
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   353
            "Edit Program Timeline", 'any_access')]
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   354
        # add link to create a new Program Document
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   355
        items += [(redirects.getCreateDocumentRedirect(entity, 'ghop/program'),
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   356
            "Create a New Document", 'any_access')]
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   357
        # add link to list all Program Document
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   358
        items += [(redirects.getListDocumentsRedirect(entity, 'ghop/program'),
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   359
            "List Documents", 'any_access')]
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   360
        # add link to edit Task Difficulty Levels
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   361
        items += [(ghop_redirects.getDifficultyEditRedirect(
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   362
            entity, {'url_name': 'ghop/program'}),
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   363
            "Edit Task Difficulty Levels", 'any_access')]
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   364
        # add link to edit Task Type Tags
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   365
        items += [(ghop_redirects.getTaskTypeEditRedirect(
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   366
            entity, {'url_name': 'ghop/program'}),
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   367
            "Edit Task Type Tags", 'any_access')]
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   368
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   369
      except out_of_band.Error:
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   370
        pass
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   371
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   372
      items = sidebar.getSidebarMenu(id, user, items, params=params)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   373
      if not items:
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   374
        continue
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   375
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   376
      menu = {}
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   377
      menu['heading'] = entity.short_name
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   378
      menu['items'] = items
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   379
      menu['group'] = 'Programs'
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   380
      menus.append(menu)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   381
    
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   382
    return menus
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   383
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   384
  def _getTimeDependentEntries(self, ghop_program_entity, params, id, user):
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   385
    """Returns a list with time dependent menu items.
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   386
    """
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   387
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   388
    items = []
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   389
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   390
    timeline_entity = ghop_program_entity.timeline
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   391
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   392
    # get the student entity for this user and program
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   393
    filter = {'user': user,
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   394
              'scope': ghop_program_entity,
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   395
              'status': 'active'}
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   396
    student_entity = ghop_student_logic.logic.getForFields(filter, unique=True)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   397
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   398
    if student_entity:
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   399
      items += self._getStudentEntries(ghop_program_entity, student_entity,
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   400
                                       params, id, user)
3088
08b9f4de6675 Users who claim or work on tasks may list them without having student role.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3078
diff changeset
   401
    else:  
08b9f4de6675 Users who claim or work on tasks may list them without having student role.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3078
diff changeset
   402
      # if a user has a task assigned, he or she still may list it
08b9f4de6675 Users who claim or work on tasks may list them without having student role.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3078
diff changeset
   403
      filter = {
08b9f4de6675 Users who claim or work on tasks may list them without having student role.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3078
diff changeset
   404
          'user': user,
08b9f4de6675 Users who claim or work on tasks may list them without having student role.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3078
diff changeset
   405
          'program': ghop_program_entity,
08b9f4de6675 Users who claim or work on tasks may list them without having student role.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3078
diff changeset
   406
          'status': ['ClaimRequested', 'Claimed', 'ActionNeeded', 'NeedsWork',
08b9f4de6675 Users who claim or work on tasks may list them without having student role.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3078
diff changeset
   407
              'AwaitingRegistration', 'NeedsReview'] 
08b9f4de6675 Users who claim or work on tasks may list them without having student role.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3078
diff changeset
   408
          }
08b9f4de6675 Users who claim or work on tasks may list them without having student role.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3078
diff changeset
   409
      tasks = ghop_task_logic.logic.getForFields(filter)
08b9f4de6675 Users who claim or work on tasks may list them without having student role.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3078
diff changeset
   410
08b9f4de6675 Users who claim or work on tasks may list them without having student role.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3078
diff changeset
   411
      if tasks:
08b9f4de6675 Users who claim or work on tasks may list them without having student role.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3078
diff changeset
   412
        items += [(ghop_redirects.getListStudentTasksRedirect(
08b9f4de6675 Users who claim or work on tasks may list them without having student role.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3078
diff changeset
   413
            ghop_program_entity, {'url_name':'ghop/student'}),
08b9f4de6675 Users who claim or work on tasks may list them without having student role.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3078
diff changeset
   414
            "List my Tasks", 'any_access')]
2891
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   415
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   416
    # get mentor and org_admin entity for this user and program
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   417
    filter = {'user': user,
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   418
              'program': ghop_program_entity,
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   419
              'status': 'active'}
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   420
    mentor_entity = ghop_mentor_logic.logic.getForFields(filter, unique=True)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   421
    org_admin_entity = ghop_org_admin_logic.logic.getForFields(
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   422
        filter, unique=True)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   423
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   424
    if mentor_entity or org_admin_entity:
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   425
      items += self._getOrganizationEntries(
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   426
          ghop_program_entity, org_admin_entity,
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   427
          mentor_entity, params, id, user)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   428
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   429
    if user and not (student_entity or mentor_entity or org_admin_entity):
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   430
      if timeline_helper.isActivePeriod(timeline_entity, 'student_signup'):
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   431
        # this user does not have a role yet for this program
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   432
        items += [('/ghop/student/apply/%s' % (
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   433
            ghop_program_entity.key().id_or_name()),
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   434
            "Register as a Student", 'any_access')]
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   435
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   436
    if timeline_helper.isAfterEvent(timeline_entity, 'org_signup_start'):
2951
c904033c58e1 Added listing of all Accepted GHOPOrganizations to the Program View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2941
diff changeset
   437
      url = redirects.getAcceptedOrgsRedirect(
2891
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   438
          ghop_program_entity, params)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   439
      # add a link to list all the organizations
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   440
      items += [(url, "List participating Organizations", 'any_access')]
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   441
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   442
    return items
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   443
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   444
  def _getStudentEntries(self, ghop_program_entity, student_entity, 
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   445
                         params, id, user):
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   446
    """Returns a list with menu items for students in a specific program.
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   447
    """
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   448
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   449
    items = []
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   450
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   451
    timeline_entity = ghop_program_entity.timeline
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   452
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   453
    if timeline_helper.isAfterEvent(timeline_entity,
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   454
                                   'student_signup_start'):
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   455
      # add a link to show all projects
3076
11d5fa052ad1 List view of all tasks for a GHOP student.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3067
diff changeset
   456
      items += [(ghop_redirects.getListStudentTasksRedirect(
3078
bd001e9ab9d4 Lists of student tasks view does not use pagination.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3076
diff changeset
   457
          ghop_program_entity, {'url_name':'ghop/student'}),
2891
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   458
          "List my Tasks", 'any_access')]
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   459
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   460
    items += [(redirects.getEditRedirect(student_entity, 
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   461
        {'url_name': 'ghop/student'}),
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   462
        "Edit my Student Profile", 'any_access')]
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   463
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   464
    items += [(redirects.getManageRedirect(student_entity,
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   465
        {'url_name':'ghop/student'}),
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   466
        "Resign as a Student", 'any_access')]
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   467
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   468
    return items
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   469
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   470
  @decorators.merge_params
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   471
  @decorators.check_access
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   472
  def taskDifficultyEdit(self, request, access_type, page_name=None,
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   473
                         params=None, filter=None, **kwargs):
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   474
    """View method used to edit Difficulty Level tags.
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   475
    """
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   476
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   477
    params = dicts.merge(params, self._params)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   478
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   479
    try:
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   480
      entity = self._logic.getFromKeyFieldsOr404(kwargs)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   481
    except out_of_band.Error, error:
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   482
      return helper.responses.errorResponse(
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   483
          error, request, template=params['error_public'])
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   484
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   485
    context = helper.responses.getUniversalContext(request)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   486
    helper.responses.useJavaScript(context, params['js_uses_all'])
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   487
    context['page_name'] = page_name
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   488
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   489
    context['program_key_name'] = entity.key().name()
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   490
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   491
    context['difficulties'] = ghop_task_model.TaskDifficultyTag.get_by_scope(
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   492
        entity)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   493
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   494
    params['edit_template'] = 'modules/ghop/program/tag/difficulty.html'
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   495
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   496
    return self._constructResponse(request, entity, context, None, params)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   497
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   498
  @decorators.merge_params
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   499
  @decorators.check_access
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   500
  def difficultyTagEdit(self, request, access_type, page_name=None,
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   501
                        params=None, filter=None, **kwargs):
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   502
    """View method used to edit a supplied Difficulty level tag.
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   503
    """
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   504
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   505
    get_params = request.GET
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   506
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   507
    order = get_params.getlist('order')
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   508
    program_key_name = get_params.get('program_key_name')
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   509
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   510
    program_entity = ghop_program_logic.logic.getFromKeyName(
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   511
        program_key_name)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   512
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   513
    if order:
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   514
      for index, elem in enumerate(order):
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   515
        ghop_task_model.TaskDifficultyTag.update_order(
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   516
              program_entity, elem, index)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   517
      return http.HttpResponse()
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   518
    else:
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   519
      tag_data = get_params.getlist('tag_data')
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   520
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   521
      tag_name = tag_data[0].strip()
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   522
      tag_value = tag_data[1].strip()
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   523
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   524
      if tag_name:
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   525
        if not tag_value:
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   526
          ghop_task_model.TaskDifficultyTag.delete_tag(
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   527
              program_entity, tag_name)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   528
        elif tag_name != tag_value:
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   529
          ghop_task_model.TaskDifficultyTag.copy_tag(
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   530
              program_entity, tag_name, tag_value)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   531
      else:
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   532
        ghop_task_model.TaskDifficultyTag.get_or_create(
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   533
            program_entity, tag_value)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   534
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   535
      return http.HttpResponse(tag_value)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   536
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   537
  @decorators.merge_params
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   538
  @decorators.check_access
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   539
  def taskTypeEdit(self, request, access_type, page_name=None,
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   540
                   params=None, filter=None, **kwargs):
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   541
    """View method used to edit Task Type tags.
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   542
    """
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   543
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   544
    params = dicts.merge(params, self._params)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   545
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   546
    try:
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   547
      entity = self._logic.getFromKeyFieldsOr404(kwargs)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   548
    except out_of_band.Error, error:
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   549
      return helper.responses.errorResponse(
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   550
          error, request, template=params['error_public'])
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   551
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   552
    context = helper.responses.getUniversalContext(request)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   553
    helper.responses.useJavaScript(context, params['js_uses_all'])
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   554
    context['page_name'] = page_name
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   555
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   556
    context['program_key_name'] = entity.key().name()
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   557
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   558
    context['task_types'] = ghop_task_model.TaskTypeTag.get_by_scope(
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   559
        entity)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   560
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   561
    params['edit_template'] = 'modules/ghop/program/tag/task_type.html'
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   562
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   563
    return self._constructResponse(request, entity, context, None, params)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   564
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   565
  @decorators.merge_params
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   566
  @decorators.check_access
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   567
  def taskTypeTagEdit(self, request, access_type, page_name=None,
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   568
                      params=None, filter=None, **kwargs):
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   569
    """View method used to edit a supplied Task Type tag.
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   570
    """
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   571
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   572
    get_params = request.GET
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   573
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   574
    order = get_params.getlist('order')
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   575
    program_key_name = get_params.get('program_key_name')
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   576
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   577
    program_entity = ghop_program_logic.logic.getFromKeyName(
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   578
        program_key_name)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   579
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   580
    if order:
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   581
      for index, elem in enumerate(order):
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   582
        ghop_task_model.TaskTypeTag.update_order(
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   583
              program_entity, elem, index)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   584
      return http.HttpResponse()
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   585
    else:
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   586
      tag_data = get_params.getlist('tag_data')
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   587
      program_key_name = get_params.get('program_key_name')
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   588
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   589
      tag_name = tag_data[0].strip()
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   590
      tag_value = tag_data[1].strip()
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   591
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   592
      program_entity = ghop_program_logic.logic.getFromKeyName(
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   593
          program_key_name)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   594
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   595
      if tag_name:
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   596
        if not tag_value:
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   597
          ghop_task_model.TaskTypeTag.delete_tag(
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   598
              program_entity, tag_name)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   599
        elif tag_name != tag_value:
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   600
          ghop_task_model.TaskTypeTag.copy_tag(
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   601
              program_entity, tag_name, tag_value)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   602
      else:
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   603
        ghop_task_model.TaskTypeTag.get_or_create(program_entity, tag_value)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   604
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   605
      return http.HttpResponse(tag_value)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   606
2951
c904033c58e1 Added listing of all Accepted GHOPOrganizations to the Program View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2941
diff changeset
   607
  @decorators.merge_params
c904033c58e1 Added listing of all Accepted GHOPOrganizations to the Program View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2941
diff changeset
   608
  @decorators.check_access
c904033c58e1 Added listing of all Accepted GHOPOrganizations to the Program View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2941
diff changeset
   609
  def acceptedOrgs(self, request, access_type,
c904033c58e1 Added listing of all Accepted GHOPOrganizations to the Program View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2941
diff changeset
   610
                   page_name=None, params=None, filter=None, **kwargs):
c904033c58e1 Added listing of all Accepted GHOPOrganizations to the Program View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2941
diff changeset
   611
    """List all the accepted orgs for the given program.
c904033c58e1 Added listing of all Accepted GHOPOrganizations to the Program View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2941
diff changeset
   612
    """
c904033c58e1 Added listing of all Accepted GHOPOrganizations to the Program View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2941
diff changeset
   613
c904033c58e1 Added listing of all Accepted GHOPOrganizations to the Program View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2941
diff changeset
   614
    from soc.modules.ghop.views.models.organization import view as \
c904033c58e1 Added listing of all Accepted GHOPOrganizations to the Program View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2941
diff changeset
   615
        ghop_org_view
c904033c58e1 Added listing of all Accepted GHOPOrganizations to the Program View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2941
diff changeset
   616
c904033c58e1 Added listing of all Accepted GHOPOrganizations to the Program View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2941
diff changeset
   617
    contents = []
c904033c58e1 Added listing of all Accepted GHOPOrganizations to the Program View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2941
diff changeset
   618
    logic = params['logic']
c904033c58e1 Added listing of all Accepted GHOPOrganizations to the Program View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2941
diff changeset
   619
c904033c58e1 Added listing of all Accepted GHOPOrganizations to the Program View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2941
diff changeset
   620
    ghop_program_entity = logic.getFromKeyFieldsOr404(kwargs)
c904033c58e1 Added listing of all Accepted GHOPOrganizations to the Program View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2941
diff changeset
   621
c904033c58e1 Added listing of all Accepted GHOPOrganizations to the Program View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2941
diff changeset
   622
    ao_params = ghop_org_view.getParams().copy()
c904033c58e1 Added listing of all Accepted GHOPOrganizations to the Program View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2941
diff changeset
   623
    ao_params['list_action'] = (redirects.getHomeRedirect,
c904033c58e1 Added listing of all Accepted GHOPOrganizations to the Program View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2941
diff changeset
   624
                                ao_params)
c904033c58e1 Added listing of all Accepted GHOPOrganizations to the Program View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2941
diff changeset
   625
    ao_params['list_description'] = self.DEF_PARTICIPATING_ORGS_MSG_FMT % {
c904033c58e1 Added listing of all Accepted GHOPOrganizations to the Program View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2941
diff changeset
   626
        'name': ghop_program_entity.name
c904033c58e1 Added listing of all Accepted GHOPOrganizations to the Program View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2941
diff changeset
   627
        }
c904033c58e1 Added listing of all Accepted GHOPOrganizations to the Program View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2941
diff changeset
   628
c904033c58e1 Added listing of all Accepted GHOPOrganizations to the Program View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2941
diff changeset
   629
    filter = {
c904033c58e1 Added listing of all Accepted GHOPOrganizations to the Program View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2941
diff changeset
   630
        'scope': ghop_program_entity,
c904033c58e1 Added listing of all Accepted GHOPOrganizations to the Program View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2941
diff changeset
   631
        'status': ['new', 'active'],
c904033c58e1 Added listing of all Accepted GHOPOrganizations to the Program View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2941
diff changeset
   632
        }
c904033c58e1 Added listing of all Accepted GHOPOrganizations to the Program View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2941
diff changeset
   633
c904033c58e1 Added listing of all Accepted GHOPOrganizations to the Program View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2941
diff changeset
   634
    order = ['name']
c904033c58e1 Added listing of all Accepted GHOPOrganizations to the Program View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2941
diff changeset
   635
c904033c58e1 Added listing of all Accepted GHOPOrganizations to the Program View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2941
diff changeset
   636
    ao_list = lists.getListContent(request, ao_params, filter=filter,
c904033c58e1 Added listing of all Accepted GHOPOrganizations to the Program View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2941
diff changeset
   637
                                   order=order, idx=0)
c904033c58e1 Added listing of all Accepted GHOPOrganizations to the Program View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2941
diff changeset
   638
c904033c58e1 Added listing of all Accepted GHOPOrganizations to the Program View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2941
diff changeset
   639
    contents.append(ao_list)
c904033c58e1 Added listing of all Accepted GHOPOrganizations to the Program View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2941
diff changeset
   640
c904033c58e1 Added listing of all Accepted GHOPOrganizations to the Program View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2941
diff changeset
   641
    params = params.copy()
c904033c58e1 Added listing of all Accepted GHOPOrganizations to the Program View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2941
diff changeset
   642
    params['list_msg'] = ghop_program_entity.accepted_orgs_msg
c904033c58e1 Added listing of all Accepted GHOPOrganizations to the Program View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2941
diff changeset
   643
c904033c58e1 Added listing of all Accepted GHOPOrganizations to the Program View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2941
diff changeset
   644
    return self._list(request, params, contents, page_name)
c904033c58e1 Added listing of all Accepted GHOPOrganizations to the Program View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2941
diff changeset
   645
2891
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   646
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   647
view = View()
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   648
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   649
admin = decorators.view(view.admin)
2951
c904033c58e1 Added listing of all Accepted GHOPOrganizations to the Program View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2941
diff changeset
   650
accepted_orgs = decorators.view(view.acceptedOrgs)
2891
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   651
assign_task_quotas = decorators.view(view.assignTaskQuotas)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   652
create = decorators.view(view.create)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   653
delete = decorators.view(view.delete)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   654
edit = decorators.view(view.edit)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   655
list = decorators.view(view.list)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   656
public = decorators.view(view.public)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   657
export = decorators.view(view.export)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   658
home = decorators.view(view.home)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   659
difficulty_tag_edit = decorators.view(view.difficultyTagEdit)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   660
task_type_tag_edit = decorators.view(view.taskTypeTagEdit)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   661
task_difficulty_edit = decorators.view(view.taskDifficultyEdit)
aba681d72b0a Added GHOP Program View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   662
task_type_edit = decorators.view(view.taskTypeEdit)