forked from pydanny/django-uni-form
-
Notifications
You must be signed in to change notification settings - Fork 0
/
views.py
134 lines (100 loc) · 3.73 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# Create your views here.
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
def basic_test(request):
if request.method == "POST":
form = TestForm(request.POST)
else:
form = TestForm()
return render_to_response('test_app/test_template.html', {
'form': form
}, context_instance=RequestContext(request))
def view_helper(request):
# Create the form
if request.method == "POST":
form = TestForm(request.POST)
else:
form = TestForm()
# create a formHelper
helper = FormHelper()
# Add in a class and id
helper.form_id = 'this-form-rocks'
helper.form_class = 'search'
# add in a submit and reset button
submit = Submit('search','search this site')
helper.add_input(submit)
reset = Reset('reset','reset button')
helper.add_input(reset)
hidden = Hidden('not-seen','hidden value stored here')
helper.add_input(hidden)
# create the response dictionary
response_dictionary = {'form':form, 'helper': helper}
return render_to_response('test_app/view_helper.html',
response_dictionary,
context_instance=RequestContext(request))
def view_helper_set_action(request):
# Create the form
form = TestForm()
# create a formHelper
helper = FormHelper()
# add in a submit and reset button
submit = Submit('send-away','Send to other page')
helper.add_input(submit)
helper.form_action = 'view_helper'
helper.form_method = 'GET'
# create the response dictionary
response_dictionary = {'form':form, 'helper': helper}
return render_to_response('test_app/view_helper.html',
response_dictionary,
context_instance=RequestContext(request))
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
}, context_instance=RequestContext(request))
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
}, context_instance=RequestContext(request))
def lacking_form_tag(request):
# Create the form
if request.method == "POST":
form = TestForm(request.POST)
else:
form = TestForm()
# create a formHelper
helper = FormHelper()
# remove the form tag
helper.form_tag = False
# create the response dictionary
response_dictionary = {'form':form, 'helper': helper}
return render_to_response('test_app/lacking_form_tag.html',
response_dictionary,
context_instance=RequestContext(request))
def message_response(request):
if request.method == "POST":
form = MessageResponseForm(request.POST)
else:
form = MessageResponseForm()
# create a formHelper
helper = FormHelper()
# 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)
# create the response dictionary
response_dictionary = {'form':form, 'helper': helper}
return render_to_response('test_app/message_response.html',
response_dictionary,
context_instance=RequestContext(request))