Permalink
Browse files

Added bogus csrf_exempt decorator to views and added in a bunch of cl…

…eanup. This way we can continue to support legacy django versions until those versions are fully deprecated
  • Loading branch information...
1 parent 1a91a89 commit 1ac4c565f8569355119604b2edafc253f9a7bfef @pydanny pydanny committed Apr 17, 2010
@@ -109,6 +109,10 @@
{% endblock %}
</head>
<body>
+
+
+
+ <h1>{% block title%}{% endblock%}</h1>
{% block body %}
{% endblock %}
@@ -1,14 +0,0 @@
-{% extends "test_app/base.html" %}
-{% load uni_form_tags %}
-
-{% block body%}
-<h1>
- form helper test
-</h1>
-
-{% with form.helper as helper %}
- {% uni_form form helper %}
-{% endwith %}
-
-
-{% endblock %}
@@ -1,11 +1,27 @@
{% extends "test_app/base.html" %}
{% load uni_form_tags %}
-{% block body%}
-<h1>
+{% block head_title %}
+ {{ block.super }}
+ {{ title }}
+{% endblock %}
+
+{% block title %}
+ {{ block.super }}
{{ title }}
-</h1>
+{% endblock %}
+
+
+{% block body%}
+
+{% if form.helper %}
+ {% with form.helper as helper %}
+ {% uni_form form helper %}
+ {% endwith %}
+{% else %}
+ {% uni_form form helper %}
+{% endif %}
+
-{% uni_form form helper %}
{% endblock %}
@@ -1,14 +0,0 @@
-{% extends "test_app/base.html" %}
-{% load uni_form_tags %}
-
-{% block body%}
-<h1>
- view layout test
-</h1>
-
-{% with form.helper as helper %}
- {% uni_form form helper %}
-{% endwith %}
-
-
-{% endblock %}
@@ -1,14 +0,0 @@
-{% extends "test_app/base.html" %}
-{% load uni_form_tags %}
-
-{% block body%}
-<h1>
- view helper test
-</h1>
-
- {% uni_form form helper %}
-
-{% endblock %}
-
-
-
@@ -1,11 +1,18 @@
-# Create your views here.
+from django.conf import settings
from django.shortcuts import render_to_response
from django.template import RequestContext
from uni_form.helpers import FormHelper, Submit, Reset, Hidden
from test_app.forms import TestForm, HelperTestForm, LayoutTestForm, MessageResponseForm
+try:
+ from django.views.decorators.csrf import csrf_exempt
+except ImportError:
+ def csrf_exempt(func):
+ return func
+
+@csrf_exempt
def basic_test(request):
if request.method == "POST":
form = TestForm(request.POST)
@@ -16,6 +23,7 @@ def basic_test(request):
'form': form
}, context_instance=RequestContext(request))
+@csrf_exempt
def view_helper(request):
# Create the form
if request.method == "POST":
@@ -40,12 +48,13 @@ def view_helper(request):
# create the response dictionary
- response_dictionary = {'form':form, 'helper': helper}
+ response_dictionary = {'form':form, 'helper': helper, 'title':'view helper test'}
- return render_to_response('test_app/view_helper.html',
+ return render_to_response('test_app/generic_form_test.html',
response_dictionary,
context_instance=RequestContext(request))
+@csrf_exempt
def view_helper_set_action(request):
# Create the form
@@ -62,30 +71,32 @@ def view_helper_set_action(request):
helper.form_method = 'GET'
# create the response dictionary
- response_dictionary = {'form':form, 'helper': helper}
+ response_dictionary = {'form':form, 'helper': helper, 'title':'view helper action'}
- return render_to_response('test_app/view_helper.html',
+ return render_to_response('test_app/generic_form_test.html',
response_dictionary,
context_instance=RequestContext(request))
+@csrf_exempt
def form_helper(request):
if request.method == "POST":
form = HelperTestForm(request.POST)
else:
form = HelperTestForm()
- return render_to_response('test_app/form_helper.html', {
- 'form': form
+ return render_to_response('test_app/generic_form_test.html', {
+ 'form': form, 'title':'form helper test'
}, context_instance=RequestContext(request))
+@csrf_exempt
def layout_test(request):
if request.method == "POST":
form = LayoutTestForm(request.POST)
else:
form = LayoutTestForm()
- return render_to_response('test_app/form_helper.html', {
- 'form': form
+ return render_to_response('test_app/generic_form_test.html', {
+ 'form': form, 'title': 'layout test'
}, context_instance=RequestContext(request))
def lacking_form_tag(request):
@@ -108,6 +119,7 @@ def lacking_form_tag(request):
response_dictionary,
context_instance=RequestContext(request))
+@csrf_exempt
def message_response(request):
if request.method == "POST":
@@ -120,11 +132,7 @@ def message_response(request):
# add in a error and success button
error = Submit('generate-result','Generate Error')
- helper.add_input(error)
-
- # add in a submit and reset button
- success = Submit('generate-result','Generate Success')
- helper.add_input(success)
+ helper.add_input(error)
# create the response dictionary
response_dictionary = {'form':form, 'helper': helper, 'title':'Message response test'}
@@ -143,6 +151,11 @@ def csrf_token_test(request):
helper = FormHelper()
helper.use_csrf_protection = True
+
+ # add in a submit and reset button
+ success = Submit('check-csrf','Check CSRF')
+ helper.add_input(success)
+
# create the response dictionary
response_dictionary = {'form':form, 'helper': helper, 'title':'CSRF token test'}

0 comments on commit 1ac4c56

Please sign in to comment.