75 new_params['url_name'] = "club" |
73 new_params['url_name'] = "club" |
76 new_params['sidebar_grouping'] = 'Clubs' |
74 new_params['sidebar_grouping'] = 'Clubs' |
77 |
75 |
78 patterns = [] |
76 patterns = [] |
79 |
77 |
80 patterns += [(r'^%(url_name)s/(?P<access_type>applicant)/%(key_fields)s$', |
78 patterns += [(r'^%(url_name)s/(?P<access_type>apply_member)$', |
81 'soc.views.models.%(module_name)s.applicant', |
|
82 "%(name)s Creation via Accepted Application"), |
|
83 (r'^%(url_name)s/(?P<access_type>apply_member)$', |
|
84 'soc.views.models.%(module_name)s.apply_member', |
79 'soc.views.models.%(module_name)s.apply_member', |
85 "List of all %(name_plural)s you can apply to"),] |
80 "List of all %(name_plural)s you can apply to"),] |
86 |
81 |
87 new_params['extra_django_patterns'] = patterns |
82 new_params['extra_django_patterns'] = patterns |
|
83 |
|
84 new_params['application_logic'] = club_app_logic |
|
85 new_params['group_applicant_url'] = True |
88 |
86 |
89 new_params['sidebar_additional'] = [ |
87 new_params['sidebar_additional'] = [ |
90 ('/' + new_params['url_name'] + '/apply_member', 'Join a Club', 'apply_member'),] |
88 ('/' + new_params['url_name'] + '/apply_member', 'Join a Club', 'apply_member'),] |
91 |
89 |
92 new_params['create_extra_dynafields'] = { |
90 new_params['create_extra_dynafields'] = { |
110 applicant_create_form = dynaform.extendDynaForm( |
108 applicant_create_form = dynaform.extendDynaForm( |
111 dynaform = self._params['create_form'], |
109 dynaform = self._params['create_form'], |
112 dynafields = updated_fields) |
110 dynafields = updated_fields) |
113 |
111 |
114 params['applicant_create_form'] = applicant_create_form |
112 params['applicant_create_form'] = applicant_create_form |
115 |
|
116 @decorators.merge_params |
|
117 @decorators.check_access |
|
118 def applicant(self, request, access_type, |
|
119 page_name=None, params=None, **kwargs): |
|
120 """Handles the creation of a club via an approved club application. |
|
121 |
|
122 Args: |
|
123 request: the standard Django HTTP request object |
|
124 access_type : the name of the access type which should be checked |
|
125 page_name: the page name displayed in templates as page and header title |
|
126 params: a dict with params for this View |
|
127 kwargs: the Key Fields for the specified entity |
|
128 """ |
|
129 |
|
130 # get the context for this webpage |
|
131 context = responses.getUniversalContext(request) |
|
132 context['page_name'] = page_name |
|
133 |
|
134 if request.method == 'POST': |
|
135 return self.applicantPost(request, context, params, **kwargs) |
|
136 else: |
|
137 # request.method == 'GET' |
|
138 return self.applicantGet(request, context, params, **kwargs) |
|
139 |
|
140 def applicantGet(self, request, context, params, **kwargs): |
|
141 """Handles the GET request concerning the creation of a club via an |
|
142 approved club application. |
|
143 |
|
144 Args: |
|
145 request: the standard Django HTTP request object |
|
146 context: dictionary containing the context for this view |
|
147 params: a dict with params for this View |
|
148 kwargs: the Key Fields for the specified entity |
|
149 """ |
|
150 |
|
151 # find the application |
|
152 key_fields = club_app_logic.logic.getKeyFieldsFromFields(kwargs) |
|
153 application = club_app_logic.logic.getFromKeyFields(key_fields) |
|
154 |
|
155 # extract the application fields |
|
156 field_names = application.properties().keys() |
|
157 fields = dict( [(i, getattr(application, i)) for i in field_names] ) |
|
158 |
|
159 # create the form using the fields from the application as the initial value |
|
160 form = params['applicant_create_form'](initial=fields) |
|
161 |
|
162 # construct the appropriate response |
|
163 return super(View, self)._constructResponse(request, entity=None, |
|
164 context=context, form=form, params=params) |
|
165 |
|
166 def applicantPost(self, request, context, params, **kwargs): |
|
167 """Handles the POST request concerning the creation of a club via an |
|
168 approved club application. |
|
169 |
|
170 Args: |
|
171 request: the standard Django HTTP request object |
|
172 context: dictionary containing the context for this view |
|
173 params: a dict with params for this View |
|
174 kwargs: the Key Fields for the specified entity |
|
175 """ |
|
176 |
|
177 # populate the form using the POST data |
|
178 form = params['applicant_create_form'](request.POST) |
|
179 |
|
180 if not form.is_valid(): |
|
181 # return the invalid form response |
|
182 return self._constructResponse(request, entity=None, context=context, |
|
183 form=form, params=params) |
|
184 |
|
185 # collect the cleaned data from the valid form |
|
186 key_name, fields = soc.views.helper.forms.collectCleanedFields(form) |
|
187 |
|
188 # fill in the founder of the club |
|
189 user = user_logic.logic.getForCurrentAccount() |
|
190 fields['founder'] = user |
|
191 |
|
192 if not key_name: |
|
193 key_fields = self._logic.getKeyFieldsFromFields(fields) |
|
194 key_name = self._logic.getKeyNameFromFields(key_fields) |
|
195 |
|
196 # create the club entity |
|
197 entity = self._logic.updateOrCreateFromKeyName(fields, key_name) |
|
198 |
|
199 # redirect to notifications list to see the admin invite |
|
200 return http.HttpResponseRedirect('/notification/list') |
|
201 |
|
202 |
113 |
203 @decorators.merge_params |
114 @decorators.merge_params |
204 @decorators.check_access |
115 @decorators.check_access |
205 def applyMember(self, request, access_type, |
116 def applyMember(self, request, access_type, |
206 page_name=None, params=None, **kwargs): |
117 page_name=None, params=None, **kwargs): |