3 # Copyright 2009 the Melange authors.
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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.
17 """Views for Club Members.
21 '"Lennard de Rijk" <ljvderijk@gmail.com>'
25 from django
import forms
27 from soc
.logic
import dicts
28 from soc
.logic
.models
import club
as club_logic
29 from soc
.logic
.models
import club_member
as club_member_logic
30 from soc
.logic
.models
import club_admin
as club_admin_logic
31 from soc
.views
.helper
import access
32 from soc
.views
.helper
import decorators
33 from soc
.views
.helper
import dynaform
34 from soc
.views
.helper
import widgets
35 from soc
.views
.models
import club
as club_view
36 from soc
.views
.models
import role
38 import soc
.logic
.models
.club_member
39 import soc
.logic
.models
.club_admin
42 class View(role
.View
):
43 """View methods for the Club Member model.
46 def __init__(self
, params
=None):
47 """Defines the fields and methods required for the base View class
48 to provide the user with list, public, create, edit and delete views.
51 params: a dict with params for this View
54 rights
= access
.Checker(params
)
55 rights
['create'] = ['checkIsDeveloper']
56 rights
['edit'] = [('checkHasActiveRoleForScope', club_member_logic
.logic
),
57 ('checkIsMyEntity', [club_member_logic
.logic
, 'user', True])]
58 rights
['delete'] = ['checkIsDeveloper']
59 rights
['invite'] = [('checkHasActiveRoleForScope', club_admin_logic
.logic
)]
60 rights
['accept_invite'] = [('checkCanCreateFromRequest','club_member')]
61 rights
['request'] = ['checkIsUser',
62 ('checkCanMakeRequestToGroup', club_logic
)]
63 rights
['process_request'] = [('checkHasActiveRoleForScope',
64 club_admin_logic
.logic
),
65 ('checkCanProcessRequest','club_member')]
66 rights
['manage'] = [('checkIsAllowedToManageRole',
67 [soc
.logic
.models
.club_member
.logic
,
68 club_admin_logic
.logic
])]
71 new_params
['logic'] = soc
.logic
.models
.club_member
.logic
72 new_params
['group_logic'] = club_logic
.logic
73 new_params
['group_view'] = club_view
.view
74 new_params
['rights'] = rights
76 new_params
['scope_view'] = club_view
78 new_params
['name'] = "Club Member"
79 new_params
['sidebar_grouping'] = 'Clubs'
81 new_params
['extra_dynaexclude'] = ['agreed_to_tos']
83 new_params
['allow_requests_and_invites'] = True
84 new_params
['show_in_roles_overview'] = False
86 params
= dicts
.merge(params
, new_params
)
88 super(View
, self
).__init
__(params
=params
)
90 # register the role with the group_view
91 self
._params
['group_view'].registerRole(self
._params
['module_name'], self
)
93 # create and store the special form for invited users
95 'link_id': forms
.CharField(widget
=widgets
.ReadOnlyInput(),
98 invited_create_form
= dynaform
.extendDynaForm(
99 dynaform
= self
._params
['create_form'],
100 dynaproperties
= updated_fields
)
102 self
._params
['invited_create_form'] = invited_create_form
104 def _editPost(self
, request
, entity
, fields
):
105 """See base.View._editPost().
109 fields
['user'] = fields
['link_id']
110 fields
['link_id'] = fields
['user'].link_id
112 super(View
, self
)._editPost
(request
, entity
, fields
)
114 def _acceptInvitePost(self
, fields
, request
, context
, params
, **kwargs
):
115 """Fills in the fields that were missing in the invited_created_form.
117 For params see base.View._acceptInvitePost()
119 # fill in the appropriate fields that were missing in the form
120 fields
['user'] = fields
['link_id']
121 fields
['link_id'] = fields
['user'].link_id
126 accept_invite
= decorators
.view(view
.acceptInvite
)
127 admin
= decorators
.view(view
.admin
)
128 create
= decorators
.view(view
.create
)
129 delete
= decorators
.view(view
.delete
)
130 edit
= decorators
.view(view
.edit
)
131 invite
= decorators
.view(view
.invite
)
132 list = decorators
.view(view
.list)
133 manage
= decorators
.view(view
.manage
)
134 process_request
= decorators
.view(view
.processRequest
)
135 role_request
= decorators
.view(view
.request
)
136 public
= decorators
.view(view
.public
)
137 export
= decorators
.view(view
.export
)