Changeset - 6a37134172c3
[Not reviewed]
0 3 0
Christopher Neugebauer - 8 years ago 2016-10-14 23:26:36
chrisjrn@gmail.com
Stops relying on a form
3 files changed with 10 insertions and 24 deletions:
0 comments (0 inline, 0 general)
registrasion/reporting/forms.py
Show inline comments
...
 
@@ -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(),
 
    )
registrasion/reporting/reports.py
Show inline comments
...
 
@@ -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)
registrasion/templatetags/registrasion_tags.py
Show inline comments
...
 
@@ -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
0 comments (0 inline, 0 general)