29 from django.utils.translation import ugettext |
29 from django.utils.translation import ugettext |
30 |
30 |
31 from soc.logic import cleaning |
31 from soc.logic import cleaning |
32 from soc.logic import dicts |
32 from soc.logic import dicts |
33 from soc.logic.models import user as user_logic |
33 from soc.logic.models import user as user_logic |
|
34 from soc.logic.models.request import logic as request_logic |
34 from soc.views import helper |
35 from soc.views import helper |
35 from soc.views.helper import access |
36 from soc.views.helper import access |
36 from soc.views.helper import decorators |
37 from soc.views.helper import decorators |
37 from soc.views.helper import dynaform |
38 from soc.views.helper import dynaform |
38 from soc.views.helper import redirects |
39 from soc.views.helper import redirects |
39 from soc.views.helper import responses |
40 from soc.views.helper import responses |
40 from soc.views.helper import widgets |
41 from soc.views.helper import widgets |
41 from soc.views.models import base |
42 from soc.views.models import base |
42 |
43 |
43 import soc.models.request |
44 import soc.models.request |
44 import soc.logic.models.request |
|
45 import soc.logic.dicts |
45 import soc.logic.dicts |
46 import soc.views.helper |
46 import soc.views.helper |
47 import soc.views.helper.lists |
47 import soc.views.helper.lists |
48 import soc.views.helper.responses |
48 import soc.views.helper.responses |
49 |
49 |
69 rights['delete'] = ['checkIsDeveloper'] |
69 rights['delete'] = ['checkIsDeveloper'] |
70 rights['roles'] = ['checkIsUser'] |
70 rights['roles'] = ['checkIsUser'] |
71 |
71 |
72 new_params = {} |
72 new_params = {} |
73 new_params['rights'] = rights |
73 new_params['rights'] = rights |
74 new_params['logic'] = soc.logic.models.request.logic |
74 new_params['logic'] = request_logic |
75 |
75 |
76 new_params['name'] = "Request" |
76 new_params['name'] = "Request" |
77 |
77 |
78 new_params['sidebar_defaults'] = [('/%s/list', 'List %(name_plural)s', |
78 new_params['sidebar_defaults'] = [('/%s/list', 'List %(name_plural)s', |
79 'list')] |
79 'list')] |
80 |
80 |
81 new_params['create_template'] = ['soc/request/create.html'] |
81 new_params['create_template'] = ['soc/request/create.html'] |
82 |
82 |
83 new_params['extra_dynaexclude'] = ['status', 'role_verbose', 'created_on'] |
83 new_params['extra_dynaexclude'] = ['user', 'role', 'group', 'status'] |
84 |
84 |
85 new_params['create_extra_dynaproperties'] = { |
85 patterns = [ |
86 'link_id': widgets.ReferenceField(reference_url='user'), |
86 (r'^%(url_name)s/(?P<access_type>process_invite)/(?P<id>[0-9]*)$', |
87 'role': forms.CharField(widget=widgets.ReadOnlyInput(), |
|
88 required=True), |
|
89 'clean_link_id': cleaning.clean_existing_user('link_id'), |
|
90 } |
|
91 |
|
92 new_params['edit_extra_dynaproperties'] = { |
|
93 'scope_path': forms.CharField(widget=forms.HiddenInput, |
|
94 required=True), |
|
95 } |
|
96 |
|
97 patterns = [(r'^%(url_name)s/(?P<access_type>process_invite)/' |
|
98 '%(key_fields)s$', |
|
99 'soc.views.models.%(module_name)s.process_invite', |
87 'soc.views.models.%(module_name)s.process_invite', |
100 'Process Invite to become')] |
88 'Process Invite to become')] |
101 |
89 |
102 new_params['extra_django_patterns'] = patterns |
90 new_params['extra_django_patterns'] = patterns |
103 |
91 |
108 params = dicts.merge(params, new_params) |
96 params = dicts.merge(params, new_params) |
109 |
97 |
110 super(View, self).__init__(params=params) |
98 super(View, self).__init__(params=params) |
111 |
99 |
112 # create and store the special forms for invite and requests |
100 # create and store the special forms for invite and requests |
113 self._params['invite_form'] = self._params['create_form'] |
101 self._params['request_form'] = self._params['create_form'] |
114 |
102 |
115 updated_fields = { |
103 updated_fields = { |
116 'link_id': forms.CharField(widget=widgets.ReadOnlyInput(), |
104 'user_id': widgets.ReferenceField(reference_url='user'), |
117 required=True), |
105 'clean_user_id': cleaning.clean_existing_user('user_id'), |
118 'group_id': forms.CharField(widget=widgets.ReadOnlyInput(), |
106 } |
119 required=True)} |
107 |
120 |
108 invite_form = dynaform.extendDynaForm( |
121 request_form = dynaform.extendDynaForm( |
|
122 dynaform = self._params['create_form'], |
109 dynaform = self._params['create_form'], |
123 dynaproperties = updated_fields) |
110 dynaproperties = updated_fields) |
124 |
111 # reverse the fields so that user_id field comes first |
125 self._params['request_form'] = request_form |
112 invite_form.base_fields.keyOrder.reverse() |
|
113 |
|
114 self._params['invite_form'] = invite_form |
126 |
115 |
127 def _edit(self, request, entity, context, params): |
116 def _edit(self, request, entity, context, params): |
128 """Hook for edit View. |
117 """Hook for edit View. |
129 |
118 |
130 Changes the page name to contain request information. |
119 Changes the page name to contain request information. |
131 |
120 |
132 For args see base.View._edit(). |
121 For args see base.View._edit(). |
133 """ |
122 """ |
|
123 |
|
124 # TODO: editing request, so you can also edit message |
134 context['page_name'] = '%s to become a %s for %s' % (context['page_name'], |
125 context['page_name'] = '%s to become a %s for %s' % (context['page_name'], |
135 entity.role_verbose, |
126 entity.role_verbose, |
136 entity.scope.name) |
127 entity.scope.name) |
137 |
128 |
138 @decorators.merge_params |
129 @decorators.merge_params |
147 page_name: the page name displayed in templates as page and header title |
138 page_name: the page name displayed in templates as page and header title |
148 params: a dict with params for this View |
139 params: a dict with params for this View |
149 kwargs: the Key Fields for the specified entity |
140 kwargs: the Key Fields for the specified entity |
150 """ |
141 """ |
151 |
142 |
|
143 from soc.views.models.role import ROLE_VIEWS |
|
144 |
152 # get the context for this webpage |
145 # get the context for this webpage |
153 context = responses.getUniversalContext(request) |
146 context = responses.getUniversalContext(request) |
154 helper.responses.useJavaScript(context, params['js_uses_all']) |
147 helper.responses.useJavaScript(context, params['js_uses_all']) |
155 |
148 |
156 request_logic = params['logic'] |
|
157 |
|
158 # get the request entity using the information from kwargs |
149 # get the request entity using the information from kwargs |
159 fields = {'link_id': kwargs['link_id'], |
150 request_entity = request_logic.getFromIDOr404(int(kwargs['id'])) |
160 'scope_path': kwargs['scope_path'], |
151 |
161 'role': kwargs['role'], |
152 role_params = ROLE_VIEWS[request_entity.role].getParams() |
162 'status': 'group_accepted'} |
|
163 request_entity = request_logic.getForFields(fields, unique=True) |
|
164 |
153 |
165 # set the page name using the request_entity |
154 # set the page name using the request_entity |
166 context['page_name'] = '%s %s for %s' % (page_name, |
155 context['page_name'] = '%s %s for %s' % (page_name, |
167 request_entity.role_verbose, request_entity.scope.name) |
156 role_params['url_name'], request_entity.group.name) |
168 |
157 |
169 get_dict = request.GET |
158 get_dict = request.GET |
170 |
159 |
171 if 'status' in get_dict.keys(): |
160 if 'status' in get_dict.keys(): |
172 if get_dict['status'] == 'rejected': |
161 if get_dict['status'] == 'rejected': |
178 return http.HttpResponseRedirect('/user/requests') |
167 return http.HttpResponseRedirect('/user/requests') |
179 |
168 |
180 # put the entity in the context |
169 # put the entity in the context |
181 context['entity'] = request_entity |
170 context['entity'] = request_entity |
182 context['module_name'] = params['module_name'] |
171 context['module_name'] = params['module_name'] |
|
172 context['role_name'] = role_params['name'] |
183 context['invite_accepted_redirect'] = ( |
173 context['invite_accepted_redirect'] = ( |
184 redirects.getInviteAcceptedRedirect(request_entity, self._params)) |
174 redirects.getInviteAcceptedRedirect(request_entity, self._params)) |
185 |
175 |
186 #display the invite processing page using the appropriate template |
176 #display the invite processing page using the appropriate template |
187 template = params['invite_processing_template'] |
177 template = params['invite_processing_template'] |
207 |
197 |
208 # construct the Unhandled Invites list |
198 # construct the Unhandled Invites list |
209 |
199 |
210 # only select the Invites for this user that haven't been handled yet |
200 # only select the Invites for this user that haven't been handled yet |
211 # pylint: disable-msg=E1103 |
201 # pylint: disable-msg=E1103 |
212 filter = {'link_id': user_entity.link_id, |
202 filter = {'user': user_entity, |
213 'status': 'group_accepted'} |
203 'status': 'group_accepted'} |
214 |
204 |
215 uh_params = params.copy() |
205 uh_params = params.copy() |
216 uh_params['list_action'] = (redirects.getInviteProcessRedirect, None) |
206 uh_params['list_action'] = (redirects.getInviteProcessRedirect, None) |
217 uh_params['list_description'] = ugettext( |
207 uh_params['list_description'] = ugettext( |
222 |
212 |
223 # construct the Open Requests list |
213 # construct the Open Requests list |
224 |
214 |
225 # only select the requests from the user |
215 # only select the requests from the user |
226 # that haven't been accepted by an admin yet |
216 # that haven't been accepted by an admin yet |
227 filter = {'link_id': user_entity.link_id, |
217 filter = {'user': user_entity, |
228 'status': 'new'} |
218 'status': 'new'} |
229 |
219 |
230 ar_params = params.copy() |
220 ar_params = params.copy() |
231 ar_params['list_description'] = ugettext( |
221 ar_params['list_description'] = ugettext( |
232 "List of your pending requests.") |
222 "List of your pending requests.") |