author | Sverre Rabbelier <srabbelier@gmail.com> |
Sat, 14 Feb 2009 20:22:17 +0000 | |
changeset 1323 | a666374587df |
parent 1307 | 091a21cf3627 |
child 1343 | 4ba39392c854 |
permissions | -rw-r--r-- |
1137 | 1 |
#!/usr/bin/python2.5 |
2 |
# |
|
1307
091a21cf3627
Update the copyright notice for 2009.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1284
diff
changeset
|
3 |
# Copyright 2009 the Melange authors. |
1137 | 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 |
"""Views for Organization Mentors. |
|
18 |
""" |
|
19 |
||
20 |
__authors__ = [ |
|
21 |
'"Lennard de Rijk" <ljvderijk@gmail.com>' |
|
1284
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
22 |
'"Sverre Rabbelier" <sverre@rabbelier.nl>', |
1137 | 23 |
] |
24 |
||
25 |
||
26 |
from django import forms |
|
1284
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
27 |
from django.utils.translation import ugettext |
1137 | 28 |
|
29 |
from soc.logic import dicts |
|
30 |
from soc.logic.models import organization as org_logic |
|
31 |
from soc.views.helper import access |
|
32 |
from soc.views.helper import dynaform |
|
33 |
from soc.views.helper import widgets |
|
34 |
from soc.views.models import organization as org_view |
|
35 |
from soc.views.models import role |
|
36 |
||
37 |
import soc.logic.models.mentor |
|
38 |
import soc.logic.models.org_admin |
|
39 |
||
40 |
||
41 |
class View(role.View): |
|
42 |
"""View methods for the Organization Mentors model. |
|
43 |
""" |
|
44 |
||
45 |
def __init__(self, params=None): |
|
46 |
"""Defines the fields and methods required for the base 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 |
rights = access.Checker(params) |
|
54 |
rights['create'] = ['checkIsDeveloper'] |
|
1248
f318538394d9
Rename checkHasActiveRole to checkHasActiveRoleForScope
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1203
diff
changeset
|
55 |
rights['edit'] = [('checkHasActiveRoleForScope', soc.logic.models.mentor.logic)] |
1137 | 56 |
rights['delete'] = ['checkIsDeveloper'] |
57 |
# TODO accessCheck checkIsAdministratorForOrg |
|
58 |
rights['invite'] = ['checkIsDeveloper'] |
|
59 |
rights['accept_invite'] = [('checkCanCreateFromRequest', 'mentor')] |
|
60 |
# TODO accessCheck checkIsAdministratorForOrg |
|
61 |
rights['process_request'] = ['checkIsDeveloper', |
|
62 |
('checkCanProcessRequest', 'mentor')] |
|
63 |
rights['manage'] = [ |
|
1184
bd9c6101d41d
Use .logic in checkIsAllowedToManageRole at the caller
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1163
diff
changeset
|
64 |
('checkIsAllowedToManageRole', [soc.logic.models.mentor.logic, |
bd9c6101d41d
Use .logic in checkIsAllowedToManageRole at the caller
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1163
diff
changeset
|
65 |
soc.logic.models.org_admin.logic])] |
1137 | 66 |
|
67 |
new_params = {} |
|
68 |
new_params['logic'] = soc.logic.models.mentor.logic |
|
69 |
new_params['group_logic'] = org_logic.logic |
|
70 |
new_params['group_view'] = org_view.view |
|
71 |
new_params['rights'] = rights |
|
72 |
||
73 |
new_params['scope_view'] = org_view |
|
74 |
||
75 |
new_params['name'] = "Mentor" |
|
76 |
new_params['module_name'] = "mentor" |
|
77 |
new_params['sidebar_grouping'] = 'Organizations' |
|
78 |
||
79 |
new_params['extra_dynaexclude'] = ['agreed_to_tos'] |
|
80 |
||
1284
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
81 |
new_params['create_extra_dynafields'] = { |
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
82 |
'scope_path': forms.fields.CharField(widget=forms.HiddenInput, |
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
83 |
required=True), |
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
84 |
'mentor_agreement': forms.fields.CharField(required=False, |
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
85 |
widget=widgets.AgreementField), |
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
86 |
'agreed_to_mentor_agreement': forms.fields.BooleanField( |
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
87 |
initial=False, required=True, |
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
88 |
label=ugettext('I agree to the Mentor Agreement')), |
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
89 |
} |
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
90 |
|
1137 | 91 |
new_params['allow_requests_and_invites'] = True |
92 |
||
93 |
params = dicts.merge(params, new_params) |
|
94 |
||
95 |
super(View, self).__init__(params=params) |
|
96 |
||
97 |
# register the role with the group_view |
|
98 |
params['group_view'].registerRole(params['module_name'], self) |
|
99 |
||
100 |
# create and store the special form for invited users |
|
101 |
updated_fields = { |
|
102 |
'link_id': forms.CharField(widget=widgets.ReadOnlyInput(), |
|
1284
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
103 |
required=False), |
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
104 |
'mentor_agreement': forms.fields.Field(required=False, |
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
105 |
widget=widgets.AgreementField), |
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
106 |
} |
1137 | 107 |
|
108 |
invited_create_form = dynaform.extendDynaForm( |
|
109 |
dynaform = self._params['create_form'], |
|
110 |
dynafields = updated_fields) |
|
111 |
||
112 |
params['invited_create_form'] = invited_create_form |
|
113 |
||
114 |
def _editPost(self, request, entity, fields): |
|
115 |
"""See base.View._editPost(). |
|
116 |
""" |
|
117 |
if not entity: |
|
118 |
fields['user'] = fields['link_id'] |
|
119 |
fields['link_id'] = fields['user'].link_id |
|
120 |
||
1284
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
121 |
fields['agreed_to_tos'] = fields['agreed_to_mentor_agreement'] |
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
122 |
|
1137 | 123 |
super(View, self)._editPost(request, entity, fields) |
124 |
||
125 |
def _acceptInvitePost(self, fields, request, context, params, **kwargs): |
|
126 |
"""Fills in the fields that were missing in the invited_created_form. |
|
127 |
||
128 |
For params see base.View._acceptInvitePost() |
|
129 |
""" |
|
1284
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
130 |
|
1137 | 131 |
# fill in the appropriate fields that were missing in the form |
132 |
fields['user'] = fields['link_id'] |
|
133 |
fields['link_id'] = fields['user'].link_id |
|
1284
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
134 |
fields['agreed_to_tos'] = fields['agreed_to_mentor_agreement'] |
1137 | 135 |
|
1284
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
136 |
def _editGet(self, request, entity, form): |
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
137 |
"""Sets the content of the agreed_to_tos_on field and replaces. |
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
138 |
|
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
139 |
Also replaces the agreed_to_tos field with a hidden field when the ToS has been signed. |
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
140 |
For params see base.View._editGet(). |
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
141 |
""" |
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
142 |
|
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
143 |
if entity.agreed_to_tos: |
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
144 |
form.fields['agreed_to_mentor_agreement'] = forms.fields.BooleanField( |
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
145 |
widget=forms.HiddenInput, initial=entity.agreed_to_tos, |
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
146 |
required=True) |
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
147 |
|
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
148 |
super(View, self)._editGet(request, entity, form) |
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
149 |
|
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
150 |
def _editContext(self, request, context): |
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
151 |
"""See base.View._editContext. |
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
152 |
""" |
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
153 |
|
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
154 |
entity = context['entity'] |
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
155 |
form = context['form'] |
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
156 |
|
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
157 |
if 'scope_path' in form.initial: |
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
158 |
scope_path = form.initial['scope_path'] |
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
159 |
elif 'scope_path' in request.POST: |
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
160 |
# TODO: do this nicely |
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
161 |
scope_path = request.POST['scope_path'] |
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
162 |
else: |
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
163 |
# TODO: is this always sufficient? |
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
164 |
form.fields['mentor_agreement'] = None |
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
165 |
return |
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
166 |
|
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
167 |
entity = org_logic.logic.getFromKeyName(scope_path) |
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
168 |
|
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
169 |
if not (entity and entity.scope and entity.scope.mentor_agreement): |
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
170 |
return |
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
171 |
|
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
172 |
content = entity.scope.mentor_agreement.content |
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
173 |
|
92f7a24d8f42
Add ToS agreement to mentor application related forms.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1248
diff
changeset
|
174 |
form.fields['mentor_agreement'].widget.text = content |
1137 | 175 |
|
176 |
view = View() |
|
177 |
||
178 |
accept_invite = view.acceptInvite |
|
179 |
create = view.create |
|
180 |
delete = view.delete |
|
181 |
edit = view.edit |
|
182 |
invite = view.invite |
|
183 |
list = view.list |
|
184 |
manage = view.manage |
|
185 |
process_request = view.processRequest |
|
186 |
request = view.request |
|
187 |
public = view.public |
|
188 |
export = view.export |
|
189 |