mirror of
https://github.com/django/django.git
synced 2025-08-03 18:38:50 +00:00
Fixed #2070: refactored Django's file upload capabilities.
A description of the new features can be found in the new [http://www.djangoproject.com/documentation/upload_handing/ upload handling documentation]; the executive summary is that Django will now happily handle uploads of large files without issues. This changes the representation of uploaded files from dictionaries to bona fide objects; see BackwardsIncompatibleChanges for details. git-svn-id: http://code.djangoproject.com/svn/django/trunk@7814 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
ef76102e89
commit
d725cc9734
38 changed files with 2290 additions and 153 deletions
|
@ -1,36 +1,18 @@
|
|||
import os
|
||||
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.http import HttpResponse, HttpResponseRedirect, HttpResponseServerError
|
||||
from django.http import HttpResponse, HttpResponseRedirect
|
||||
from django.core.exceptions import SuspiciousOperation
|
||||
|
||||
def no_template_view(request):
|
||||
"A simple view that expects a GET request, and returns a rendered template"
|
||||
return HttpResponse("No template used. Sample content: twice once twice. Content ends.")
|
||||
|
||||
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):
|
||||
# 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()
|
||||
return HttpResponse('')
|
||||
else:
|
||||
return HttpResponseServerError()
|
||||
|
||||
def staff_only_view(request):
|
||||
"A view that can only be visited by staff. Non staff members get an exception"
|
||||
if request.user.is_staff:
|
||||
return HttpResponse('')
|
||||
else:
|
||||
raise SuspiciousOperation()
|
||||
|
||||
|
||||
def get_view(request):
|
||||
"A simple login protected view"
|
||||
return HttpResponse("Hello world")
|
||||
|
@ -51,4 +33,4 @@ def view_with_argument(request, name):
|
|||
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)
|
||||
login_protected_redirect_view = login_required(login_protected_redirect_view)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue