app/soc/modules/ghop/views/models/program.py
author Madhusudan.C.S <madhusudancs@gmail.com>
Sat, 22 Aug 2009 03:56:25 +0530
changeset 2784 801eee4eda9a
parent 2783 339696f3f5cf
permissions -rw-r--r--
Added timeline view for GHOP. Moved the method _createTimelineForType from Views to Logic for both core Program and GHOPProgram. Added default values parameter to apps_tasks_limit and slots in Program model. Registered timeline view for the sitemap in GHOP callback.py. Added timeline view module and class which overrides the edit method. Overriding the params['edit_form'] to accommodate dynainclude and dynaexclude fields.
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
2784
801eee4eda9a Added timeline view for GHOP.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2783
diff changeset
    37
from soc.modules.ghop.logic.models import program as ghop_program_logic
2783
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    38
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
    39
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    40
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    41
class View(program.View):
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    42
  """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
    43
  """
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    44
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    45
  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
    46
    """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
    47
    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
    48
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    49
    Params:
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    50
      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
    51
    """
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    52
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    53
    new_params = {}
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    54
    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
    55
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    56
    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
    57
    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
    58
    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
    59
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    60
    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
    61
    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
    62
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    63
    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
    64
                                       'min_slots', 'max_slots',
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    65
                                       'slots', 'slot_allocation',
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    66
                                       'allocations_visible',
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    67
                                       'task_difficulties', 'task_types',
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
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    70
    new_params['create_dynafields'] = [
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    71
        {'name': 'task_difficulties_str',
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    72
         'base': forms.fields.CharField,
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    73
         'label': 'Task Difficulty levels',
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    74
         },
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    75
        {'name': 'task_types_str',
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    76
         'base': forms.fields.CharField,
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    77
         'label': 'Task Types',
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
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    81
    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
    82
        '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
    83
            'task_difficulties_str'),
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    84
        '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
    85
            'task_types_str'),
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
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    88
    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
    89
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    90
    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
    91
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    92
  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
    93
    """See base.View._editGet().
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
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    96
    if entity.task_difficulties:
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    97
      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
    98
          entity.task_difficulties)
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
    99
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
   100
    if entity.task_types:
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
   101
      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
   102
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
   103
    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
   104
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
   105
  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
   106
    """See base._editPost().
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
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
   109
    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
   110
    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
   111
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
   112
    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
   113
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
   114
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
   115
view = View()
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
   116
339696f3f5cf Extended program configuration create/edit views specifically to support GHOP.
Madhusudan C.S <madhusudancs@gmail.com>
parents:
diff changeset
   117
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
   118
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
   119
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
   120
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
   121
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
   122
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
   123
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
   124
home = decorators.view(view.home)