|
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 Club Members. |
|
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 cleaning |
|
28 from soc.logic import dicts |
|
29 from soc.logic.models import club as club_logic |
|
30 from soc.views.helper import access |
|
31 from soc.views.helper import dynaform |
|
32 from soc.views.helper import widgets |
|
33 from soc.views.models import club as club_view |
|
34 from soc.views.models import role |
|
35 |
|
36 import soc.logic.models.club_member |
|
37 |
|
38 |
|
39 class View(role.View): |
|
40 """View methods for the Club Member 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 = {} |
|
52 rights['create'] = [access.checkIsDeveloper] |
|
53 rights['edit'] = [access.checkIsMyActiveRole(soc.logic.models.club_member)] |
|
54 rights['delete'] = [access.checkIsDeveloper] |
|
55 rights['invite'] = [access.checkIsClubAdminForClub] |
|
56 rights['accept_invite'] = [access.checkCanCreateFromRequest('club_member')] |
|
57 rights['request'] = [access.checkAgreesToSiteToS, |
|
58 access.checkCanMakeRequestToGroup(club_logic)] |
|
59 rights['process_request'] = [access.checkIsClubAdminForClub, |
|
60 access.checkCanProcessRequest('club_member')] |
|
61 |
|
62 new_params = {} |
|
63 new_params['logic'] = soc.logic.models.club_member.logic |
|
64 new_params['group_logic'] = club_logic.logic |
|
65 new_params['rights'] = rights |
|
66 |
|
67 new_params['scope_view'] = club_view |
|
68 |
|
69 new_params['name'] = "Club Member" |
|
70 |
|
71 new_params['extra_dynaexclude'] = ['user', 'state'] |
|
72 |
|
73 new_params['create_extra_dynafields'] = { |
|
74 'scope_path': forms.CharField(widget=forms.HiddenInput, |
|
75 required=True), |
|
76 'clean_link_id' : cleaning.clean_existing_user('link_id'), |
|
77 'clean_home_page' : cleaning.clean_url('home_page'), |
|
78 'clean_blog' : cleaning.clean_url('blog'), |
|
79 'clean_photo_url' : cleaning.clean_url('photo_url')} |
|
80 |
|
81 new_params['allow_requests_and_invites'] = True |
|
82 |
|
83 params = dicts.merge(params, new_params) |
|
84 |
|
85 super(View, self).__init__(params=params) |
|
86 |
|
87 # create and store the special form for invited users |
|
88 updated_fields = { |
|
89 'link_id': forms.CharField(widget=widgets.ReadOnlyInput(), |
|
90 required=False)} |
|
91 |
|
92 invited_create_form = dynaform.extendDynaForm( |
|
93 dynaform = self._params['create_form'], |
|
94 dynafields = updated_fields) |
|
95 |
|
96 params['invited_create_form'] = invited_create_form |
|
97 |
|
98 def _editPost(self, request, entity, fields): |
|
99 """See base.View._editPost(). |
|
100 """ |
|
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 process_request = view.processRequest |
|
127 request = view.request |
|
128 public = view.public |
|
129 export = view.export |