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 |
|
29 from soc.logic import cleaning |
|
30 from soc.logic import dicts |
|
31 from soc.logic.helper import timeline as timeline_helper |
|
32 from soc.views.helper import decorators |
|
33 from soc.views.helper import redirects |
|
34 from soc.views.models import organization |
|
35 from soc.views.sitemap import sidebar |
|
36 |
|
37 import soc.cache.logic |
|
38 |
|
39 from soc.modules.ghop.views.models import program as ghop_program_view |
|
40 from soc.modules.ghop.views.helper import redirects as ghop_redirects |
|
41 |
|
42 import soc.modules.ghop.logic.models.organization |
|
43 |
|
44 |
|
45 class View(organization.View): |
|
46 """View methods for the GHOP Program model. |
|
47 """ |
|
48 |
|
49 def __init__(self, params=None): |
|
50 """Defines the fields and methods required for the program View class |
|
51 to provide the user with list, public, create, edit and delete views. |
|
52 |
|
53 Params: |
|
54 params: a dict with params for this View |
|
55 """ |
|
56 |
|
57 new_params = {} |
|
58 new_params['logic'] = soc.modules.ghop.logic.models.organization.logic |
|
59 new_params['scope_view'] = ghop_program_view |
|
60 |
|
61 new_params['name'] = "GHOP Organization" |
|
62 new_params['module_name'] = "organization" |
|
63 new_params['sidebar_grouping'] = 'Organizations' |
|
64 |
|
65 new_params['module_package'] = 'soc.modules.ghop.views.models' |
|
66 new_params['url_name'] = 'ghop/org' |
|
67 |
|
68 new_params['extra_dynaexclude'] = ['slots', 'slots_calculated', |
|
69 'nr_applications', 'nr_mentors', |
|
70 'slots_desired', 'ideas', |
|
71 'task_quota_limit'] |
|
72 |
|
73 params = dicts.merge(params, new_params, sub_merge=True) |
|
74 |
|
75 super(View, self).__init__(params=params) |
|
76 |
|
77 def _getExtraMenuItems(self, role_description, params=None): |
|
78 """Used to create the specific GHOP Organization menu entries. |
|
79 |
|
80 For args see soc.views.models.organization.View._getExtraMenuItems(). |
|
81 """ |
|
82 submenus = [] |
|
83 |
|
84 group_entity = role_description['group'] |
|
85 program_entity = group_entity.scope |
|
86 roles = role_description['roles'] |
|
87 |
|
88 if roles.get('ghop_org_admin') or roles.get('ghop_mentor'): |
|
89 # add a link to view all the organization tasks. |
|
90 submenu = (ghop_redirects.getListTasksRedirect( |
|
91 group_entity, {'url_name': 'ghop/task'}), |
|
92 "View all Tasks", 'any_access') |
|
93 submenus.append(submenu) |
|
94 |
|
95 |
|
96 if roles.get('ghop_org_admin'): |
|
97 # add a link to create task |
|
98 submenu = (redirects.getCreateRedirect( |
|
99 group_entity, {'url_name': 'ghop/task'}), |
|
100 "Create a Task", 'any_access') |
|
101 submenus.append(submenu) |
|
102 |
|
103 # add a link to the management page |
|
104 submenu = (redirects.getListRolesRedirect(group_entity, params), |
|
105 "Manage Admins and Mentors", 'any_access') |
|
106 submenus.append(submenu) |
|
107 |
|
108 # add a link to invite an org admin |
|
109 submenu = (redirects.getInviteRedirectForRole( |
|
110 group_entity, 'ghop/org_admin'), |
|
111 "Invite an Admin", 'any_access') |
|
112 submenus.append(submenu) |
|
113 |
|
114 # add a link to invite a member |
|
115 submenu = (redirects.getInviteRedirectForRole( |
|
116 group_entity, 'ghop/mentor'), "Invite a Mentor", 'any_access') |
|
117 submenus.append(submenu) |
|
118 |
|
119 # add a link to the request page |
|
120 submenu = (redirects.getListRequestsRedirect(group_entity, params), |
|
121 "List Requests and Invites", 'any_access') |
|
122 submenus.append(submenu) |
|
123 |
|
124 # add a link to the edit page |
|
125 submenu = (redirects.getEditRedirect(group_entity, params), |
|
126 "Edit Organization Profile", 'any_access') |
|
127 submenus.append(submenu) |
|
128 |
|
129 if roles.get('ghop_mentor'): |
|
130 # add a link to suggest task |
|
131 submenu = (ghop_redirects.getSuggestTaskRedirect( |
|
132 group_entity, {'url_name': 'ghop/task'}), |
|
133 "Suggest a Task", 'any_access') |
|
134 submenus.append(submenu) |
|
135 |
|
136 if roles.get('ghop_org_admin') or roles.get('ghop_mentor'): |
|
137 submenu = (redirects.getCreateDocumentRedirect(group_entity, 'ghop_org'), |
|
138 "Create a New Document", 'any_access') |
|
139 submenus.append(submenu) |
|
140 |
|
141 submenu = (redirects.getListDocumentsRedirect(group_entity, 'ghop_org'), |
|
142 "List Documents", 'any_access') |
|
143 submenus.append(submenu) |
|
144 |
|
145 if roles.get('org_admin'): |
|
146 # add a link to the resign page |
|
147 submenu = (redirects.getManageRedirect(roles['ghop_org_admin'], |
|
148 {'url_name': 'ghop/org_admin'}), |
|
149 "Resign as Admin", 'any_access') |
|
150 submenus.append(submenu) |
|
151 |
|
152 # add a link to the edit page |
|
153 submenu = (redirects.getEditRedirect(roles['ghop_org_admin'], |
|
154 {'url_name': 'ghop/org_admin'}), |
|
155 "Edit My Admin Profile", 'any_access') |
|
156 submenus.append(submenu) |
|
157 |
|
158 |
|
159 if roles.get('ghop_mentor'): |
|
160 # add a link to the resign page |
|
161 submenu = (redirects.getManageRedirect(roles['ghop_mentor'], |
|
162 {'url_name' : 'ghop/mentor'}), |
|
163 "Resign as Mentor", 'any_access') |
|
164 submenus.append(submenu) |
|
165 |
|
166 # add a link to the edit page |
|
167 submenu = (redirects.getEditRedirect(roles['ghop_mentor'], |
|
168 {'url_name': 'ghop/mentor'}), |
|
169 "Edit My Mentor Profile", 'any_access') |
|
170 submenus.append(submenu) |
|
171 |
|
172 return submenus |
|
173 |
|
174 |
|
175 view = View() |
|
176 |
|
177 admin = decorators.view(view.admin) |
|
178 create = decorators.view(view.create) |
|
179 delete = decorators.view(view.delete) |
|
180 edit = decorators.view(view.edit) |
|
181 list = decorators.view(view.list) |
|
182 public = decorators.view(view.public) |
|
183 export = decorators.view(view.export) |
|
184 home = decorators.view(view.home) |
|