Fix user_self calling editGet with a wrong parameter
[Melange.git] / app / soc / views / models / club.py
blob0a12f489556f1a6064c9eb0c2a874fbf5926f74c
1 #!/usr/bin/python2.5
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 Clubs.
18 """
20 __authors__ = [
21 '"Sverre Rabbelier" <sverre@rabbelier.nl>',
22 '"Lennard de Rijk" <ljvderijk@gmail.com>',
26 from django import forms
27 from django.utils.translation import ugettext
29 from soc.logic import cleaning
30 from soc.logic import dicts
31 from soc.logic.models import club_app as club_app_logic
32 from soc.logic.models import club as club_logic
33 from soc.logic.models import club_admin as club_admin_logic
34 from soc.views.helper import access
35 from soc.views.helper import decorators
36 from soc.views.helper import dynaform
37 from soc.views.helper import redirects
38 from soc.views.helper import widgets
39 from soc.views.models import group
41 import soc.logic.models.club
44 class View(group.View):
45 """View methods for the Club model.
46 """
48 def __init__(self, params=None):
49 """Defines the fields and methods required for the base View class
50 to provide the user with list, public, create, edit and delete views.
52 Params:
53 params: a dict with params for this View
54 """
56 rights = access.Checker(params)
57 rights['create'] = ['checkIsDeveloper']
58 rights['edit'] = [('checkHasActiveRoleForLinkId', club_admin_logic.logic),
59 ('checkGroupIsActiveForLinkId', club_logic.logic)]
60 rights['delete'] = ['checkIsDeveloper']
61 rights['home'] = ['allow']
62 rights['list'] = ['checkIsDeveloper']
63 rights['apply_member'] = ['checkIsUser',
64 ('checkGroupIsActiveForScopeAndLinkId',
65 club_logic.logic)]
66 rights['list_requests'] = [('checkHasActiveRoleForLinkId',
67 club_admin_logic.logic)]
68 rights['list_roles'] = [('checkHasActiveRoleForLinkId',
69 club_admin_logic.logic)]
70 rights['applicant'] = [('checkIsApplicationAccepted',
71 club_app_logic.logic)]
73 new_params = {}
74 new_params['logic'] = soc.logic.models.club.logic
75 new_params['rights'] = rights
76 new_params['name'] = "Club"
77 new_params['url_name'] = "club"
78 new_params['document_prefix'] = "club"
79 new_params['sidebar_grouping'] = 'Clubs'
81 new_params['public_template'] = 'soc/group/public.html'
83 patterns = []
85 patterns += [(r'^%(url_name)s/(?P<access_type>apply_member)$',
86 'soc.views.models.%(module_name)s.apply_member',
87 "List of all %(name_plural)s you can apply to"),]
89 new_params['extra_django_patterns'] = patterns
91 new_params['application_logic'] = club_app_logic
92 new_params['group_applicant_url'] = True
94 new_params['sidebar_additional'] = [
95 ('/' + new_params['url_name'] + '/apply_member',
96 'Join a Club', 'apply_member'),]
98 new_params['create_dynafields'] = [
99 {'name': 'link_id',
100 'base': forms.fields.CharField,
101 'label': 'Club Link ID',
105 new_params['create_extra_dynaproperties'] = {
106 'clean' : cleaning.validate_new_group('link_id', 'scope_path',
107 club_logic, club_app_logic)}
109 # get rid of the clean method
110 new_params['edit_extra_dynaproperties'] = {
111 'clean' : (lambda x: x.cleaned_data)}
113 params = dicts.merge(params, new_params)
115 super(View, self).__init__(params=params)
117 # create and store the special form for applicants
118 updated_fields = {
119 'link_id': forms.CharField(widget=widgets.ReadOnlyInput(),
120 required=False),
121 'clean_link_id': cleaning.clean_link_id('link_id')}
123 applicant_create_form = dynaform.extendDynaForm(
124 dynaform = self._params['create_form'],
125 dynaproperties = updated_fields)
127 self._params['applicant_create_form'] = applicant_create_form
129 @decorators.merge_params
130 @decorators.check_access
131 def applyMember(self, request, access_type,
132 page_name=None, params=None, **kwargs):
133 """Shows a list of all clubs and you can choose one to
134 apply to become a member.
136 Args:
137 request: the standard Django HTTP request object
138 access_type : the name of the access type which should be checked
139 page_name: the page name displayed in templates as page and header title
140 params: a dict with params for this View
141 kwargs: the Key Fields for the specified entity
144 list_params = params.copy()
145 list_params['list_action'] = (redirects.getRequestRedirectForRole,
146 'club_member')
147 list_params['list_description'] = ugettext('Choose a club to '
148 'apply to become a Club Member.')
150 return self.list(request, access_type,
151 page_name, params=list_params, filter=None)
154 def _getExtraMenuItems(self, role_description, params=None):
155 """Used to create the specific club menu entries.
157 For args see group.View._getExtraMenuItems().
160 submenus = []
162 group_entity = role_description['group']
163 roles = role_description['roles']
165 if roles.get('club_admin'):
166 # add a link to the management page
167 submenu = (redirects.getListRolesRedirect(group_entity, params),
168 "Manage Admins and Members", 'any_access')
169 submenus.append(submenu)
171 # add a link to invite an admin
172 submenu = (redirects.getInviteRedirectForRole(group_entity, 'club_admin'),
173 "Invite an Admin", 'any_access')
174 submenus.append(submenu)
176 # add a link to invite a member
177 submenu = (redirects.getInviteRedirectForRole(group_entity,
178 'club_member'), "Invite a Member", 'any_access')
179 submenus.append(submenu)
181 # add a link to the request page
182 submenu = (redirects.getListRequestsRedirect(group_entity, params),
183 "List Requests and Invites", 'any_access')
184 submenus.append(submenu)
186 # add a link to the edit page
187 submenu = (redirects.getEditRedirect(group_entity, params),
188 "Edit Club Profile", 'any_access')
189 submenus.append(submenu)
191 if roles.get('club_member') or roles.get('club_admin'):
192 submenu = (redirects.getCreateDocumentRedirect(group_entity, 'club'),
193 "Create a New Document", 'any_access')
194 submenus.append(submenu)
196 submenu = (redirects.getListDocumentsRedirect(group_entity, 'club'),
197 "List Documents", 'any_access')
198 submenus.append(submenu)
200 if roles.get('club_admin'):
201 # add a link to resign as club admin
202 submenu = (redirects.getManageRedirect(roles['club_admin'],
203 {'url_name': 'club_admin'}),
204 "Resign as Club Admin", 'any_access')
205 submenus.append(submenu)
207 if roles.get('club_member'):
208 # add a link to resign as club member
209 submenu = (redirects.getManageRedirect(roles['club_member'],
210 {'url_name' : 'club_member'}),
211 "Resign as Club Member", 'any_access')
212 submenus.append(submenu)
214 return submenus
217 view = View()
219 admin = decorators.view(view.admin)
220 applicant = decorators.view(view.applicant)
221 apply_member = decorators.view(view.applyMember)
222 create = decorators.view(view.create)
223 delete = decorators.view(view.delete)
224 edit = decorators.view(view.edit)
225 home = decorators.view(view.home)
226 list = decorators.view(view.list)
227 list_requests = decorators.view(view.listRequests)
228 list_roles = decorators.view(view.listRoles)
229 public = decorators.view(view.public)
230 export = decorators.view(view.export)
231 pick = decorators.view(view.pick)