Browse files

Replace render_to_response by new render

It was a strange use of RequestContext by the way...
  • Loading branch information...
1 parent c93de5c commit e828ba253c898ea8d4eb60736f7045d5c8804d14 @stephane committed Nov 26, 2012
Showing with 22 additions and 22 deletions.
  1. +0 −1 django_select2/util.py
  2. +1 −1 testapp/testapp/testmain/forms.py
  3. +21 −20 testapp/testapp/testmain/views.py
View
1 django_select2/util.py
@@ -290,7 +290,6 @@ def timer_end(t):
def timer(f):
def inner(*args, **kwargs):
-
t = timer_start(f.func_name)
ret = f(*args, **kwargs)
timer_end(t)
View
2 testapp/testapp/testmain/forms.py
@@ -60,7 +60,7 @@ def get_results(self, request, term, page, context):
class EmployeeForm(forms.ModelForm):
manager = EmployeeChoices(required=False)
dept = ModelSelect2Field(queryset=Dept.objects)
-
+
class Meta:
model = Employee
View
41 testapp/testapp/testmain/views.py
@@ -1,58 +1,59 @@
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
-from django.shortcuts import render_to_response, get_object_or_404
-from django.template import RequestContext
+from django.shortcuts import render, get_object_or_404
from .forms import EmployeeForm, DeptForm, MixedForm, InitialValueForm
from .models import Employee, Dept
+
def test_single_value_model_field(request):
- return render_to_response('list.html', RequestContext(request, {
- 'title': 'Employees',
- 'href': 'test_single_value_model_field1',
- 'object_list': Employee.objects.all()
- }))
+ return render(request, 'list.html', {
+ 'title': 'Employees',
+ 'href': 'test_single_value_model_field1',
+ 'object_list': Employee.objects.all()
+ })
+
def test_single_value_model_field1(request, id):
- emp = get_object_or_404(Employee, pk=id)
+ emp = get_object_or_404(Employee, pk=id)
if request.POST:
form = EmployeeForm(data=request.POST, instance=emp)
if form.is_valid():
form.save()
return HttpResponseRedirect(reverse('home'))
else:
form = EmployeeForm(instance=emp)
- return render_to_response('form.html', RequestContext(request, {'form': form}))
+ return render(request, 'form.html', {'form': form})
def test_multi_values_model_field(request):
- return render_to_response('list.html', RequestContext(request, {
- 'title': 'Departments',
- 'href': 'test_multi_values_model_field1',
- 'object_list': Dept.objects.all()
- }))
+ return render(request, 'list.html', {
+ 'title': 'Departments',
+ 'href': 'test_multi_values_model_field1',
+ 'object_list': Dept.objects.all()
+ })
+
def test_multi_values_model_field1(request, id):
- dept = get_object_or_404(Dept, pk=id)
+ dept = get_object_or_404(Dept, pk=id)
if request.POST:
form = DeptForm(data=request.POST, instance=dept)
if form.is_valid():
form.save()
return HttpResponseRedirect(reverse('home'))
else:
form = DeptForm(instance=dept)
- return render_to_response('form.html', RequestContext(request, {'form': form}))
+ return render(request, 'form.html', {'form': form})
+
def test_mixed_form(request):
if request.POST:
form = MixedForm(request.POST)
form.is_valid()
else:
form = MixedForm()
- return render_to_response('form.html', RequestContext(request, {'form': form}))
+ return render(request, 'form.html', {'form': form})
def test_init_values(request):
- return render_to_response('form.html', RequestContext(request, {'form': InitialValueForm()}))
-
-
+ return render(request, 'form.html', {'form': InitialValueForm()})

0 comments on commit e828ba2

Please sign in to comment.