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