|
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 import soc.modules.ghop.logic.models.program |
|
38 |
|
39 |
|
40 class View(program.View): |
|
41 """View methods for the GHOP Program model. |
|
42 """ |
|
43 |
|
44 def __init__(self, params=None): |
|
45 """Defines the fields and methods required for the program View class |
|
46 to provide the user with list, public, create, edit and delete views. |
|
47 |
|
48 Params: |
|
49 params: a dict with params for this View |
|
50 """ |
|
51 |
|
52 new_params = {} |
|
53 new_params['logic'] = soc.modules.ghop.logic.models.program.logic |
|
54 |
|
55 new_params['name'] = "GHOP Program" |
|
56 new_params['module_name'] = "program" |
|
57 new_params['sidebar_grouping'] = 'Programs' |
|
58 |
|
59 new_params['module_package'] = 'soc.modules.ghop.views.models' |
|
60 new_params['url_name'] = 'ghop/program' |
|
61 |
|
62 new_params['extra_dynaexclude'] = ['apps_tasks_limit', |
|
63 'min_slots', 'max_slots', |
|
64 'slots', 'slot_allocation', |
|
65 'allocations_visible', |
|
66 'task_difficulties', 'task_types', |
|
67 ] |
|
68 |
|
69 new_params['create_dynafields'] = [ |
|
70 {'name': 'task_difficulties_str', |
|
71 'base': forms.fields.CharField, |
|
72 'label': 'Task Difficulty levels', |
|
73 }, |
|
74 {'name': 'task_types_str', |
|
75 'base': forms.fields.CharField, |
|
76 'label': 'Task Types', |
|
77 }, |
|
78 ] |
|
79 |
|
80 new_params['create_extra_dynaproperties'] = { |
|
81 'clean_task_difficulties_str': cleaning.str2set( |
|
82 'task_difficulties_str'), |
|
83 'clean_task_types_str': cleaning.str2set( |
|
84 'task_types_str'), |
|
85 } |
|
86 |
|
87 params = dicts.merge(params, new_params, sub_merge=True) |
|
88 |
|
89 super(View, self).__init__(params=params) |
|
90 |
|
91 def _editGet(self, request, entity, form): |
|
92 """See base.View._editGet(). |
|
93 """ |
|
94 |
|
95 if entity.task_difficulties: |
|
96 form.fields['task_difficulties_str'].initial = ', '.join( |
|
97 entity.task_difficulties) |
|
98 |
|
99 if entity.task_types: |
|
100 form.fields['task_types_str'].initial = ', '.join(entity.task_types) |
|
101 |
|
102 return super(View, self)._editGet(request, entity, form) |
|
103 |
|
104 def _editPost(self, request, entity, fields): |
|
105 """See base._editPost(). |
|
106 """ |
|
107 |
|
108 fields['task_difficulties'] = fields['task_difficulties_str'] |
|
109 fields['task_types'] = fields['task_types_str'] |
|
110 |
|
111 return super(View, self)._editPost(request, entity, fields) |
|
112 |
|
113 |
|
114 view = View() |
|
115 |
|
116 admin = decorators.view(view.admin) |
|
117 create = decorators.view(view.create) |
|
118 delete = decorators.view(view.delete) |
|
119 edit = decorators.view(view.edit) |
|
120 list = decorators.view(view.list) |
|
121 public = decorators.view(view.public) |
|
122 export = decorators.view(view.export) |
|
123 home = decorators.view(view.home) |