author | Lennard de Rijk <ljvderijk@gmail.com> |
Mon, 02 Feb 2009 20:07:52 +0000 | |
changeset 1190 | 449b9d93d890 |
parent 1184 | bd9c6101d41d |
child 1203 | 38225f2ad3a6 |
permissions | -rw-r--r-- |
1137 | 1 |
#!/usr/bin/python2.5 |
2 |
# |
|
3 |
# Copyright 2008 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 |
"""Views for Organization Mentors. |
|
18 |
""" |
|
19 |
||
20 |
__authors__ = [ |
|
21 |
'"Lennard de Rijk" <ljvderijk@gmail.com>' |
|
22 |
] |
|
23 |
||
24 |
||
25 |
from django import forms |
|
26 |
||
27 |
from soc.logic import dicts |
|
28 |
from soc.logic.models import organization as org_logic |
|
29 |
from soc.views.helper import access |
|
30 |
from soc.views.helper import dynaform |
|
31 |
from soc.views.helper import widgets |
|
32 |
from soc.views.models import organization as org_view |
|
33 |
from soc.views.models import role |
|
34 |
||
35 |
import soc.logic.models.mentor |
|
36 |
import soc.logic.models.org_admin |
|
37 |
||
38 |
||
39 |
class View(role.View): |
|
40 |
"""View methods for the Organization Mentors model. |
|
41 |
""" |
|
42 |
||
43 |
def __init__(self, params=None): |
|
44 |
"""Defines the fields and methods required for the base View class |
|
45 |
to provide the user with list, public, create, edit and delete views. |
|
46 |
||
47 |
Params: |
|
48 |
params: a dict with params for this View |
|
49 |
""" |
|
50 |
||
51 |
rights = access.Checker(params) |
|
52 |
rights['create'] = ['checkIsDeveloper'] |
|
1163
d8c50be19232
Cleaned up access.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1137
diff
changeset
|
53 |
rights['edit'] = [('checkHasRole', soc.logic.models.mentor.logic)] |
1137 | 54 |
rights['delete'] = ['checkIsDeveloper'] |
55 |
# TODO accessCheck checkIsAdministratorForOrg |
|
56 |
rights['invite'] = ['checkIsDeveloper'] |
|
57 |
rights['accept_invite'] = [('checkCanCreateFromRequest', 'mentor')] |
|
58 |
# TODO accessCheck checkIsAdministratorForOrg |
|
59 |
rights['process_request'] = ['checkIsDeveloper', |
|
60 |
('checkCanProcessRequest', 'mentor')] |
|
61 |
rights['manage'] = [ |
|
1184
bd9c6101d41d
Use .logic in checkIsAllowedToManageRole at the caller
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1163
diff
changeset
|
62 |
('checkIsAllowedToManageRole', [soc.logic.models.mentor.logic, |
bd9c6101d41d
Use .logic in checkIsAllowedToManageRole at the caller
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1163
diff
changeset
|
63 |
soc.logic.models.org_admin.logic])] |
1137 | 64 |
|
65 |
new_params = {} |
|
66 |
new_params['logic'] = soc.logic.models.mentor.logic |
|
67 |
new_params['group_logic'] = org_logic.logic |
|
68 |
new_params['group_view'] = org_view.view |
|
69 |
new_params['rights'] = rights |
|
70 |
||
71 |
new_params['scope_view'] = org_view |
|
72 |
||
73 |
new_params['name'] = "Mentor" |
|
74 |
new_params['module_name'] = "mentor" |
|
75 |
new_params['sidebar_grouping'] = 'Organizations' |
|
76 |
||
77 |
new_params['extra_dynaexclude'] = ['agreed_to_tos'] |
|
78 |
||
79 |
new_params['allow_requests_and_invites'] = True |
|
80 |
||
81 |
params = dicts.merge(params, new_params) |
|
82 |
||
83 |
super(View, self).__init__(params=params) |
|
84 |
||
85 |
# register the role with the group_view |
|
86 |
params['group_view'].registerRole(params['module_name'], self) |
|
87 |
||
88 |
# create and store the special form for invited users |
|
89 |
updated_fields = { |
|
90 |
'link_id': forms.CharField(widget=widgets.ReadOnlyInput(), |
|
91 |
required=False)} |
|
92 |
||
93 |
invited_create_form = dynaform.extendDynaForm( |
|
94 |
dynaform = self._params['create_form'], |
|
95 |
dynafields = updated_fields) |
|
96 |
||
97 |
params['invited_create_form'] = invited_create_form |
|
98 |
||
99 |
def _editPost(self, request, entity, fields): |
|
100 |
"""See base.View._editPost(). |
|
101 |
""" |
|
102 |
if not entity: |
|
103 |
fields['user'] = fields['link_id'] |
|
104 |
fields['link_id'] = fields['user'].link_id |
|
105 |
||
106 |
super(View, self)._editPost(request, entity, fields) |
|
107 |
||
108 |
def _acceptInvitePost(self, fields, request, context, params, **kwargs): |
|
109 |
"""Fills in the fields that were missing in the invited_created_form. |
|
110 |
||
111 |
For params see base.View._acceptInvitePost() |
|
112 |
""" |
|
113 |
# fill in the appropriate fields that were missing in the form |
|
114 |
fields['user'] = fields['link_id'] |
|
115 |
fields['link_id'] = fields['user'].link_id |
|
116 |
||
117 |
||
118 |
view = View() |
|
119 |
||
120 |
accept_invite = view.acceptInvite |
|
121 |
create = view.create |
|
122 |
delete = view.delete |
|
123 |
edit = view.edit |
|
124 |
invite = view.invite |
|
125 |
list = view.list |
|
126 |
manage = view.manage |
|
127 |
process_request = view.processRequest |
|
128 |
request = view.request |
|
129 |
public = view.public |
|
130 |
export = view.export |
|
131 |