2008-06-06 21:39:42 +08:00
|
|
|
import os
|
|
|
|
|
2007-09-03 19:21:40 +08:00
|
|
|
from django.contrib.auth.decorators import login_required
|
|
|
|
from django.http import HttpResponse, HttpResponseRedirect, HttpResponseServerError
|
2007-05-10 21:46:15 +08:00
|
|
|
|
|
|
|
def no_template_view(request):
|
|
|
|
"A simple view that expects a GET request, and returns a rendered template"
|
2007-07-20 22:32:20 +08:00
|
|
|
return HttpResponse("No template used. Sample content: twice once twice. Content ends.")
|
2007-05-10 21:46:15 +08:00
|
|
|
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 20:11:04 +08:00
|
|
|
def file_upload_view(request):
|
|
|
|
"""
|
|
|
|
Check that a file upload can be updated into the POST dictionary without
|
|
|
|
going pear-shaped.
|
|
|
|
"""
|
|
|
|
form_data = request.POST.copy()
|
|
|
|
form_data.update(request.FILES)
|
|
|
|
if isinstance(form_data['file_field'], dict) and isinstance(form_data['name'], unicode):
|
2008-06-06 21:39:42 +08:00
|
|
|
# If a file is posted, the dummy client should only post the file name,
|
|
|
|
# not the full path.
|
|
|
|
if os.path.dirname(form_data['file_field']['filename']) != '':
|
|
|
|
return HttpResponseServerError()
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 20:11:04 +08:00
|
|
|
return HttpResponse('')
|
|
|
|
else:
|
|
|
|
return HttpResponseServerError()
|
|
|
|
|
2007-09-03 19:21:40 +08:00
|
|
|
def get_view(request):
|
2008-03-20 14:50:54 +08:00
|
|
|
"A simple login protected view"
|
2007-09-03 19:21:40 +08:00
|
|
|
return HttpResponse("Hello world")
|
|
|
|
get_view = login_required(get_view)
|
|
|
|
|
2008-03-20 14:50:54 +08:00
|
|
|
def view_with_argument(request, name):
|
|
|
|
"""A view that takes a string argument
|
|
|
|
|
|
|
|
The purpose of this view is to check that if a space is provided in
|
|
|
|
the argument, the test framework unescapes the %20 before passing
|
|
|
|
the value to the view.
|
|
|
|
"""
|
|
|
|
if name == 'Arthur Dent':
|
|
|
|
return HttpResponse('Hi, Arthur')
|
|
|
|
else:
|
|
|
|
return HttpResponse('Howdy, %s' % name)
|
|
|
|
|
2007-09-03 19:21:40 +08:00
|
|
|
def login_protected_redirect_view(request):
|
|
|
|
"A view that redirects all requests to the GET view"
|
|
|
|
return HttpResponseRedirect('/test_client_regress/get_view/')
|
|
|
|
login_protected_redirect_view = login_required(login_protected_redirect_view)
|