|
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 Organizations. |
|
18 """ |
|
19 |
|
20 __authors__ = [ |
|
21 '"Madhusudan.C.S" <madhusudancs@gmail.com>' |
|
22 ] |
|
23 |
|
24 |
|
25 import datetime |
|
26 |
|
27 from django import forms |
|
28 from django.utils.translation import ugettext |
|
29 |
|
30 from soc.logic import cleaning |
|
31 from soc.logic import dicts |
|
32 from soc.logic.helper import timeline as timeline_helper |
|
33 from soc.views.helper import decorators |
|
34 from soc.views.helper import lists |
|
35 from soc.views.helper import redirects |
|
36 from soc.views.models import organization |
|
37 from soc.views.sitemap import sidebar |
|
38 |
|
39 import soc.cache.logic |
|
40 |
|
41 from soc.modules.ghop.logic.models import organization as ghop_org_logic |
|
42 from soc.modules.ghop.logic.models import org_admin as ghop_org_admin_logic |
|
43 from soc.modules.ghop.views.helper import access as ghop_access |
|
44 from soc.modules.ghop.views.models import program as ghop_program_view |
|
45 from soc.modules.ghop.views.helper import redirects as ghop_redirects |
|
46 |
|
47 import soc.modules.ghop.logic.models.organization |
|
48 |
|
49 |
|
50 class View(organization.View): |
|
51 """View methods for the GHOP Organization model. |
|
52 """ |
|
53 |
|
54 DEF_OPEN_PROJECTS_MSG_FMT = ugettext( |
|
55 'List of tasks published by %s that are open.') |
|
56 |
|
57 DEF_CLAIMED_PROJECTS_MSG_FMT = ugettext( |
|
58 'List of tasks published by %s that are claimed.') |
|
59 |
|
60 DEF_CLOSED_PROJECTS_MSG_FMT = ugettext( |
|
61 'List of tasks published by %s that are closed.') |
|
62 |
|
63 |
|
64 def __init__(self, params=None): |
|
65 """Defines the fields and methods required for the program View class |
|
66 to provide the user with list, public, create, edit and delete views. |
|
67 |
|
68 Params: |
|
69 params: a dict with params for this View |
|
70 """ |
|
71 |
|
72 rights = ghop_access.GHOPChecker(params) |
|
73 rights['create'] = ['checkIsDeveloper'] |
|
74 rights['edit'] = [('checkHasActiveRoleForKeyFieldsAsScope', |
|
75 ghop_org_admin_logic.logic,), |
|
76 ('checkGroupIsActiveForLinkId', ghop_org_logic.logic)] |
|
77 rights['delete'] = ['checkIsDeveloper'] |
|
78 rights['home'] = ['allow'] |
|
79 rights['public_list'] = ['allow'] |
|
80 rights['apply_mentor'] = ['checkIsUser'] |
|
81 rights['list_requests'] = [('checkHasActiveRoleForKeyFieldsAsScope', |
|
82 ghop_org_admin_logic.logic)] |
|
83 rights['list_roles'] = [('checkHasActiveRoleForKeyFieldsAsScope', |
|
84 ghop_org_admin_logic.logic)] |
|
85 |
|
86 new_params = {} |
|
87 new_params['logic'] = soc.modules.ghop.logic.models.organization.logic |
|
88 new_params['rights'] = rights |
|
89 |
|
90 new_params['scope_view'] = ghop_program_view |
|
91 |
|
92 new_params['name'] = "GHOP Organization" |
|
93 new_params['module_name'] = "organization" |
|
94 new_params['sidebar_grouping'] = 'Organizations' |
|
95 |
|
96 new_params['public_template'] = 'modules/ghop/organization/public.html' |
|
97 new_params['list_row'] = 'modules/ghop/organization/list/row.html' |
|
98 new_params['list_heading'] = 'modules/ghop/organization/list/heading.html' |
|
99 new_params['home_template'] = 'modules/ghop/organization/home.html' |
|
100 |
|
101 new_params['module_package'] = 'soc.modules.ghop.views.models' |
|
102 new_params['url_name'] = 'ghop/org' |
|
103 new_params['document_prefix'] = 'ghop_org' |
|
104 |
|
105 new_params['extra_dynaexclude'] = ['slots', 'slots_calculated', |
|
106 'nr_applications', 'nr_mentors', |
|
107 'slots_desired', 'ideas', |
|
108 'task_quota_limit'] |
|
109 |
|
110 params = dicts.merge(params, new_params, sub_merge=True) |
|
111 |
|
112 super(View, self).__init__(params=params) |
|
113 |
|
114 def _public(self, request, entity, context): |
|
115 """See base.View._public(). |
|
116 """ |
|
117 |
|
118 from soc.modules.ghop.views.models import task as ghop_task_view |
|
119 |
|
120 contents = [] |
|
121 |
|
122 ghop_program_entity = entity.scope |
|
123 |
|
124 if timeline_helper.isAfterEvent(ghop_program_entity.timeline, |
|
125 'student_signup_start'): |
|
126 # open tasks |
|
127 to_params = ghop_task_view.view.getParams().copy() |
|
128 |
|
129 # define the list redirect action to show the task public page |
|
130 to_params['list_action'] = (redirects.getPublicRedirect, to_params) |
|
131 to_params['list_description'] = self.DEF_OPEN_PROJECTS_MSG_FMT %( |
|
132 entity.name) |
|
133 to_params['list_heading'] = 'modules/ghop/task/list/heading.html' |
|
134 to_params['list_row'] = 'modules/ghop/task/list/row.html' |
|
135 |
|
136 filter = {'scope': entity, |
|
137 'status': ['Open', 'Reopened']} |
|
138 |
|
139 to_list = lists.getListContent(request, to_params, filter, idx=0, |
|
140 need_content=True) |
|
141 |
|
142 if to_list: |
|
143 to_list['data'].sort(key=lambda task: task.modified_on) |
|
144 |
|
145 contents.append(to_list) |
|
146 |
|
147 # claimed tasks |
|
148 tc_params = to_params.copy() |
|
149 |
|
150 tc_params['list_description'] = self.DEF_CLAIMED_PROJECTS_MSG_FMT %( |
|
151 entity.name) |
|
152 |
|
153 filter = {'scope': entity, |
|
154 'status': ['ClaimRequested', 'Claimed', 'NeedsAction', |
|
155 'NeedsReview', 'NeedsWork']} |
|
156 |
|
157 tc_list = lists.getListContent(request, tc_params, filter, idx=1, |
|
158 need_content=True) |
|
159 |
|
160 if tc_list: |
|
161 tc_list['data'].sort(key=lambda task: task.modified_on) |
|
162 |
|
163 contents.append(tc_list) |
|
164 |
|
165 # closed tasks |
|
166 tcs_params = to_params.copy() |
|
167 |
|
168 tcs_params['list_description'] = self.DEF_CLOSED_PROJECTS_MSG_FMT %( |
|
169 entity.name) |
|
170 |
|
171 filter = {'scope': entity, |
|
172 'status': ['AwaitingRegistration', 'Closed']} |
|
173 |
|
174 tcs_list = lists.getListContent(request, tcs_params, filter, idx=2, |
|
175 need_content=True) |
|
176 |
|
177 if tcs_list: |
|
178 tcs_list['data'].sort(key=lambda task: task.modified_on) |
|
179 |
|
180 contents.append(tcs_list) |
|
181 |
|
182 # construct the list and put it into the context |
|
183 context['list'] = soc.logic.lists.Lists(contents) |
|
184 |
|
185 return super(View, self)._public(request=request, entity=entity, |
|
186 context=context) |
|
187 |
|
188 def _getExtraMenuItems(self, role_description, params=None): |
|
189 """Used to create the specific GHOP Organization menu entries. |
|
190 |
|
191 For args see soc.views.models.organization.View._getExtraMenuItems(). |
|
192 """ |
|
193 submenus = [] |
|
194 |
|
195 group_entity = role_description['group'] |
|
196 program_entity = group_entity.scope |
|
197 roles = role_description['roles'] |
|
198 |
|
199 if roles.get('ghop_org_admin') or roles.get('ghop_mentor'): |
|
200 # add a link to view all the organization tasks. |
|
201 submenu = (ghop_redirects.getListTasksRedirect( |
|
202 group_entity, {'url_name': 'ghop/task'}), |
|
203 "View all Tasks", 'any_access') |
|
204 submenus.append(submenu) |
|
205 |
|
206 |
|
207 if roles.get('ghop_org_admin'): |
|
208 # add a link to create task |
|
209 submenu = (redirects.getCreateRedirect( |
|
210 group_entity, {'url_name': 'ghop/task'}), |
|
211 "Create a Task", 'any_access') |
|
212 submenus.append(submenu) |
|
213 |
|
214 # add a link to the management page |
|
215 submenu = (redirects.getListRolesRedirect(group_entity, params), |
|
216 "Manage Admins and Mentors", 'any_access') |
|
217 submenus.append(submenu) |
|
218 |
|
219 # add a link to invite an org admin |
|
220 submenu = (redirects.getInviteRedirectForRole( |
|
221 group_entity, 'ghop/org_admin'), |
|
222 "Invite an Admin", 'any_access') |
|
223 submenus.append(submenu) |
|
224 |
|
225 # add a link to invite a member |
|
226 submenu = (redirects.getInviteRedirectForRole( |
|
227 group_entity, 'ghop/mentor'), "Invite a Mentor", 'any_access') |
|
228 submenus.append(submenu) |
|
229 |
|
230 # add a link to the request page |
|
231 submenu = (redirects.getListRequestsRedirect(group_entity, params), |
|
232 "List Requests and Invites", 'any_access') |
|
233 submenus.append(submenu) |
|
234 |
|
235 # add a link to the edit page |
|
236 submenu = (redirects.getEditRedirect(group_entity, params), |
|
237 "Edit Organization Profile", 'any_access') |
|
238 submenus.append(submenu) |
|
239 |
|
240 if roles.get('ghop_mentor'): |
|
241 # add a link to suggest task |
|
242 submenu = (ghop_redirects.getSuggestTaskRedirect( |
|
243 group_entity, {'url_name': 'ghop/task'}), |
|
244 "Suggest a Task", 'any_access') |
|
245 submenus.append(submenu) |
|
246 |
|
247 if roles.get('ghop_org_admin') or roles.get('ghop_mentor'): |
|
248 submenu = (redirects.getCreateDocumentRedirect(group_entity, 'ghop_org'), |
|
249 "Create a New Document", 'any_access') |
|
250 submenus.append(submenu) |
|
251 |
|
252 submenu = (redirects.getListDocumentsRedirect(group_entity, 'ghop_org'), |
|
253 "List Documents", 'any_access') |
|
254 submenus.append(submenu) |
|
255 |
|
256 if roles.get('org_admin'): |
|
257 # add a link to the resign page |
|
258 submenu = (redirects.getManageRedirect(roles['ghop_org_admin'], |
|
259 {'url_name': 'ghop/org_admin'}), |
|
260 "Resign as Admin", 'any_access') |
|
261 submenus.append(submenu) |
|
262 |
|
263 # add a link to the edit page |
|
264 submenu = (redirects.getEditRedirect(roles['ghop_org_admin'], |
|
265 {'url_name': 'ghop/org_admin'}), |
|
266 "Edit My Admin Profile", 'any_access') |
|
267 submenus.append(submenu) |
|
268 |
|
269 |
|
270 if roles.get('ghop_mentor'): |
|
271 # add a link to the resign page |
|
272 submenu = (redirects.getManageRedirect(roles['ghop_mentor'], |
|
273 {'url_name' : 'ghop/mentor'}), |
|
274 "Resign as Mentor", 'any_access') |
|
275 submenus.append(submenu) |
|
276 |
|
277 # add a link to the edit page |
|
278 submenu = (redirects.getEditRedirect(roles['ghop_mentor'], |
|
279 {'url_name': 'ghop/mentor'}), |
|
280 "Edit My Mentor Profile", 'any_access') |
|
281 submenus.append(submenu) |
|
282 |
|
283 return submenus |
|
284 |
|
285 |
|
286 view = View() |
|
287 |
|
288 admin = decorators.view(view.admin) |
|
289 create = decorators.view(view.create) |
|
290 delete = decorators.view(view.delete) |
|
291 edit = decorators.view(view.edit) |
|
292 list = decorators.view(view.list) |
|
293 public = decorators.view(view.public) |
|
294 export = decorators.view(view.export) |
|
295 home = decorators.view(view.home) |