app/soc/modules/ghop/views/models/program.py
author Madhusudan C.S <madhusudancs@gmail.com>
Sat, 22 Aug 2009 03:56:14 +0530
changeset 2783 339696f3f5cf
child 2784 801eee4eda9a
permissions -rw-r--r--
Extended program configuration create/edit views specifically to support GHOP. Added the first views for GHOP, which are inherited from soc program views. Added new param keys, module_package. url_name key now specifies this is view is from a Melange GHOP module. Also added the view to GHOP module's callback.py. The program Logic class's timeline_logic variable is tied to corresponding timeline logic within the constructor.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2783
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
     2
#
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
     3
# Copyright 2009 the Melange authors.
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
     4
#
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
     8
#
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    10
#
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    16
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    17
"""GHOP specific views for Programs.
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    18
"""
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    19
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    20
__authors__ = [
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    21
    '"Madhusudan.C.S" <madhusudancs@gmail.com>'
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    22
  ]
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    23
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    24
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    25
import datetime
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    26
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    27
from django import forms
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    28
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    29
from soc.logic import cleaning
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    30
from soc.logic import dicts
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    31
from soc.views.helper import decorators
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    32
from soc.views.models import program 
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    33
from soc.views.sitemap import sidebar
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    34
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    35
import soc.cache.logic
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    36
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    37
import soc.modules.ghop.logic.models.program
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    38
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    39
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    40
class View(program.View):
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    41
  """View methods for the GHOP Program model.
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    42
  """
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    43
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    44
  def __init__(self, params=None):
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    45
    """Defines the fields and methods required for the program View class
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    46
    to provide the user with list, public, create, edit and delete views.
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    47
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    48
    Params:
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    49
      params: a dict with params for this View
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    50
    """
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    51
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    52
    new_params = {}
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    53
    new_params['logic'] = soc.modules.ghop.logic.models.program.logic
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    54
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    55
    new_params['name'] = "GHOP Program"
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    56
    new_params['module_name'] = "program"
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    57
    new_params['sidebar_grouping'] = 'Programs'
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    58
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    59
    new_params['module_package'] = 'soc.modules.ghop.views.models'
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    60
    new_params['url_name'] = 'ghop/program'
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    61
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    62
    new_params['extra_dynaexclude'] = ['apps_tasks_limit',
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    63
                                       'min_slots', 'max_slots',
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    64
                                       'slots', 'slot_allocation',
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    65
                                       'allocations_visible',
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    66
                                       'task_difficulties', 'task_types',
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    67
                                       ]
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    68
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    69
    new_params['create_dynafields'] = [
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    70
        {'name': 'task_difficulties_str',
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    71
         'base': forms.fields.CharField,
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    72
         'label': 'Task Difficulty levels',
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    73
         },
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    74
        {'name': 'task_types_str',
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    75
         'base': forms.fields.CharField,
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    76
         'label': 'Task Types',
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    77
         },
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    78
        ]
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    79
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    80
    new_params['create_extra_dynaproperties'] = {
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    81
        'clean_task_difficulties_str': cleaning.str2set(
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    82
            'task_difficulties_str'),
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    83
        'clean_task_types_str': cleaning.str2set(
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    84
            'task_types_str'),
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    85
        }
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    86
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    87
    params = dicts.merge(params, new_params, sub_merge=True)
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    88
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    89
    super(View, self).__init__(params=params)
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    90
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    91
  def _editGet(self, request, entity, form):
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    92
    """See base.View._editGet().
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    93
    """
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    94
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    95
    if entity.task_difficulties:
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    96
      form.fields['task_difficulties_str'].initial = ', '.join(
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    97
          entity.task_difficulties)
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    98
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    99
    if entity.task_types:
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
   100
      form.fields['task_types_str'].initial = ', '.join(entity.task_types)
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
   101
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
   102
    return super(View, self)._editGet(request, entity, form)
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
   103
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
   104
  def _editPost(self, request, entity, fields):
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
   105
    """See base._editPost().
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
   106
    """
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
   107
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
   108
    fields['task_difficulties'] = fields['task_difficulties_str']
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
   109
    fields['task_types'] = fields['task_types_str']
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
   110
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
   111
    return super(View, self)._editPost(request, entity, fields)
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
   112
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
   113
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
   114
view = View()
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
   115
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
   116
admin = decorators.view(view.admin)
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
   117
create = decorators.view(view.create)
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
   118
delete = decorators.view(view.delete)
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
   119
edit = decorators.view(view.edit)
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
   120
list = decorators.view(view.list)
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
   121
public = decorators.view(view.public)
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
   122
export = decorators.view(view.export)
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
   123
home = decorators.view(view.home)