Stops relying on a form
This commit is contained in:
		
							parent
							
								
									ed2327bedd
								
							
						
					
					
						commit
						6a37134172
					
				
					 3 changed files with 10 additions and 24 deletions
				
			
		|  | @ -81,16 +81,3 @@ def model_fields_form_factory(model): | |||
|         ) | ||||
| 
 | ||||
|     return ModelFieldsForm | ||||
| 
 | ||||
| 
 | ||||
| class SectionContentTypeForm(forms.Form): | ||||
|     section = forms.IntegerField( | ||||
|         required=False, | ||||
|         min_value=0, | ||||
|         widget=forms.HiddenInput(), | ||||
|     ) | ||||
| 
 | ||||
|     content_type = forms.CharField( | ||||
|         required=False, | ||||
|         widget=forms.HiddenInput(), | ||||
|     ) | ||||
|  |  | |||
|  | @ -216,10 +216,6 @@ class ReportView(object): | |||
| 
 | ||||
|     def __init__(self, inner_view, title, form_type): | ||||
|         # Consolidate form_type so it has content type and section | ||||
|         bases = [forms.SectionContentTypeForm, form_type] | ||||
|         bases = [base for base in bases if base is not None] | ||||
|         form_type = forms.mix_form(*bases) | ||||
| 
 | ||||
|         self.inner_view = inner_view | ||||
|         self.title = title | ||||
|         self.form_type = form_type | ||||
|  | @ -254,7 +250,7 @@ class ReportView(object): | |||
|         renderers = { | ||||
|             "text/csv": self._render_as_csv, | ||||
|             "text/html": self._render_as_html, | ||||
|             "": self._render_as_html, | ||||
|             None: self._render_as_html, | ||||
|         } | ||||
|         render = renderers[data.content_type] | ||||
|         return render(data) | ||||
|  | @ -292,9 +288,10 @@ class ReportViewRequestData(object): | |||
|         # Calculate other data | ||||
|         self.form = report_view.get_form(request) | ||||
| 
 | ||||
|         # Content type and section come from the form | ||||
|         self.content_type = self.form.cleaned_data["content_type"] | ||||
|         self.section = self.form.cleaned_data["section"] | ||||
|         # Content type and section come from request.GET | ||||
|         self.content_type = request.GET.get("content_type") | ||||
|         self.section = request.GET.get("section") | ||||
|         self.section = int(self.section) if self.section else None | ||||
| 
 | ||||
|         # Reports come from calling the inner view | ||||
|         reports = report_view.inner_view(request, self.form, *a, **k) | ||||
|  |  | |||
|  | @ -80,9 +80,11 @@ def items_purchased(context, category=None): | |||
| @register.assignment_tag(takes_context=True) | ||||
| def report_as_csv(context, section): | ||||
| 
 | ||||
|     query = dict(context.request.GET) | ||||
|     query["section"] = section | ||||
|     query["content_type"] = "text/csv" | ||||
|     old_query = context.request.META["QUERY_STRING"] | ||||
|     query = dict([("section", section), ("content_type", "text/csv")]) | ||||
|     querystring = urlencode(query) | ||||
| 
 | ||||
|     if old_query: | ||||
|         querystring = old_query + "&" + querystring | ||||
| 
 | ||||
|     return context.request.path + "?" + querystring | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Christopher Neugebauer
						Christopher Neugebauer