80 } |
80 } |
81 |
81 |
82 params = dicts.merge(params, new_params) |
82 params = dicts.merge(params, new_params) |
83 |
83 |
84 super(View, self).__init__(params=params) |
84 super(View, self).__init__(params=params) |
85 |
85 |
86 # create and store the special form for applicants |
86 # create and store the special form for applicants |
87 updated_fields = { |
87 updated_fields = { |
88 'link_id': forms.CharField(widget=widgets.ReadOnlyInput(), |
88 'link_id': forms.CharField(widget=widgets.ReadOnlyInput(), |
89 required=False)} |
89 required=False)} |
90 |
90 |
91 applicant_create_form = dynaform.extendDynaForm( |
91 applicant_create_form = dynaform.extendDynaForm( |
92 dynaform = self._params['create_form'], |
92 dynaform = self._params['create_form'], |
93 dynafields = updated_fields) |
93 dynafields = updated_fields) |
94 |
94 |
95 params['applicant_create_form'] = applicant_create_form |
95 params['applicant_create_form'] = applicant_create_form |
96 |
96 |
97 |
97 |
98 def applicant(self, request, access_type, |
98 def applicant(self, request, access_type, |
99 page_name=None, params=None, **kwargs): |
99 page_name=None, params=None, **kwargs): |
100 """Handles the creation of a club via an approved club application. |
100 """Handles the creation of a club via an approved club application. |
101 |
101 |
102 Args: |
102 Args: |
103 request: the standard Django HTTP request object |
103 request: the standard Django HTTP request object |
104 page_name: the page name displayed in templates as page and header title |
104 page_name: the page name displayed in templates as page and header title |
105 params: a dict with params for this View |
105 params: a dict with params for this View |
106 kwargs: the Key Fields for the specified entity |
106 kwargs: the Key Fields for the specified entity |
107 """ |
107 """ |
108 |
108 |
109 |
109 |
110 # merge the params |
110 # merge the params |
111 params = dicts.merge(params, self._params) |
111 params = dicts.merge(params, self._params) |
112 |
112 |
113 # check if the current user has access to this page |
113 # check if the current user has access to this page |
114 try: |
114 try: |
115 access.checkAccess(access_type, request, rights=params['rights']) |
115 access.checkAccess(access_type, request, rights=params['rights']) |
116 except out_of_band.Error, error: |
116 except out_of_band.Error, error: |
117 return responses.errorResponse(error, request) |
117 return responses.errorResponse(error, request) |
118 |
118 |
119 # get the context for this webpage |
119 # get the context for this webpage |
120 context = responses.getUniversalContext(request) |
120 context = responses.getUniversalContext(request) |
121 context['page_name'] = page_name |
121 context['page_name'] = page_name |
122 |
122 |
123 |
123 |
124 if request.method == 'POST': |
124 if request.method == 'POST': |
125 return self.applicantPost(request, context, params, **kwargs) |
125 return self.applicantPost(request, context, params, **kwargs) |
126 else: |
126 else: |
127 # request.method == 'GET' |
127 # request.method == 'GET' |
128 return self.applicantGet(request, context, params, **kwargs) |
128 return self.applicantGet(request, context, params, **kwargs) |
129 |
129 |
130 |
130 |
131 def applicantGet(self, request, context, params, **kwargs): |
131 def applicantGet(self, request, context, params, **kwargs): |
132 """Handles the GET request concerning the creation of a club via an |
132 """Handles the GET request concerning the creation of a club via an |
133 approved club application. |
133 approved club application. |
134 |
134 |
135 Args: |
135 Args: |
136 request: the standard Django HTTP request object |
136 request: the standard Django HTTP request object |
137 context: dictionary containing the context for this view |
137 context: dictionary containing the context for this view |
138 params: a dict with params for this View |
138 params: a dict with params for this View |
139 kwargs: the Key Fields for the specified entity |
139 kwargs: the Key Fields for the specified entity |
140 """ |
140 """ |
141 |
141 |
142 # find the application |
142 # find the application |
143 key_fields = group_app_logic.logic.getKeyFieldsFromDict(kwargs) |
143 key_fields = group_app_logic.logic.getKeyFieldsFromDict(kwargs) |
144 application = group_app_logic.logic.getFromFields(**key_fields) |
144 application = group_app_logic.logic.getFromFields(**key_fields) |
145 |
145 |
146 # extract the application fields |
146 # extract the application fields |
147 field_names = application.properties().keys() |
147 field_names = application.properties().keys() |
148 fields = dict( [(i, getattr(application, i)) for i in field_names] ) |
148 fields = dict( [(i, getattr(application, i)) for i in field_names] ) |
149 |
149 |
150 # create the form using the fields from the application as the initial value |
150 # create the form using the fields from the application as the initial value |
151 form = params['applicant_create_form'](initial=fields) |
151 form = params['applicant_create_form'](initial=fields) |
152 |
152 |
153 # construct the appropriate response |
153 # construct the appropriate response |
154 return super(View, self)._constructResponse(request, entity=None, |
154 return super(View, self)._constructResponse(request, entity=None, |
155 context=context, form=form, params=params) |
155 context=context, form=form, params=params) |
156 |
156 |
157 |
157 |
158 def applicantPost(self, request, context, params, **kwargs): |
158 def applicantPost(self, request, context, params, **kwargs): |
159 """Handles the POST request concerning the creation of a club via an |
159 """Handles the POST request concerning the creation of a club via an |
160 approved club application. |
160 approved club application. |
161 |
161 |
162 Args: |
162 Args: |
163 request: the standard Django HTTP request object |
163 request: the standard Django HTTP request object |
164 context: dictionary containing the context for this view |
164 context: dictionary containing the context for this view |
165 params: a dict with params for this View |
165 params: a dict with params for this View |
166 kwargs: the Key Fields for the specified entity |
166 kwargs: the Key Fields for the specified entity |
167 """ |
167 """ |
168 |
168 |
169 # populate the form using the POST data |
169 # populate the form using the POST data |
170 form = params['applicant_create_form'](request.POST) |
170 form = params['applicant_create_form'](request.POST) |
171 |
171 |
172 if not form.is_valid(): |
172 if not form.is_valid(): |
173 # return the invalid form response |
173 # return the invalid form response |
174 return self._constructResponse(request, entity=None, context=context, |
174 return self._constructResponse(request, entity=None, context=context, |
175 form=form, params=params) |
175 form=form, params=params) |
176 |
176 |
177 # collect the cleaned data from the valid form |
177 # collect the cleaned data from the valid form |
178 key_name, fields = soc.views.helper.forms.collectCleanedFields(form) |
178 key_name, fields = soc.views.helper.forms.collectCleanedFields(form) |
179 |
179 |
180 # fill in the founder of the club |
180 # fill in the founder of the club |
181 account = users.get_current_user() |
181 account = users.get_current_user() |
182 user = user_logic.logic.getForFields({'account': account}, unique=True) |
182 user = user_logic.logic.getForFields({'account': account}, unique=True) |
183 fields['founder'] = user |
183 fields['founder'] = user |
184 |
184 |
185 if not key_name: |
185 if not key_name: |
186 key_fields = self._logic.getKeyFieldsFromDict(fields) |
186 key_fields = self._logic.getKeyFieldsFromDict(fields) |
187 key_name = self._logic.getKeyNameForFields(key_fields) |
187 key_name = self._logic.getKeyNameForFields(key_fields) |
188 |
188 |
189 # create the club entity |
189 # create the club entity |
190 entity = self._logic.updateOrCreateFromKeyName(fields, key_name) |
190 entity = self._logic.updateOrCreateFromKeyName(fields, key_name) |
191 |
191 |
192 # redirect to notifications list to see the admin invite |
192 # redirect to notifications list to see the admin invite |
193 return http.HttpResponseRedirect('/notification/list') |
193 return http.HttpResponseRedirect('/notification/list') |
194 |
194 |
195 |
195 |
196 def _editGet(self, request, entity, form): |
196 def _editGet(self, request, entity, form): |