Converted request.META['REQUEST_METHOD'] calls to request.method, throughout the Django codebase

git-svn-id: http://code.djangoproject.com/svn/django/trunk@3171 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2006-06-20 04:34:13 +00:00
parent b93de6a2cb
commit 37addba352
7 changed files with 10 additions and 11 deletions

View File

@ -68,7 +68,7 @@ class WSGIRequest(http.HttpRequest):
def _load_post_and_files(self): def _load_post_and_files(self):
# Populates self._post and self._files # Populates self._post and self._files
if self.environ['REQUEST_METHOD'] == 'POST': if self.method == 'POST':
if self.environ.get('CONTENT_TYPE', '').startswith('multipart'): if self.environ.get('CONTENT_TYPE', '').startswith('multipart'):
header_dict = dict([(k, v) for k, v in self.environ.items() if k.startswith('HTTP_')]) header_dict = dict([(k, v) for k, v in self.environ.items() if k.startswith('HTTP_')])
header_dict['Content-Type'] = self.environ.get('CONTENT_TYPE', '') header_dict['Content-Type'] = self.environ.get('CONTENT_TYPE', '')

View File

@ -33,7 +33,7 @@ class CacheMiddleware(object):
def process_request(self, request): def process_request(self, request):
"Checks whether the page is already cached and returns the cached version if available." "Checks whether the page is already cached and returns the cached version if available."
if not request.META['REQUEST_METHOD'] in ('GET', 'HEAD') or request.GET: if not request.method in ('GET', 'HEAD') or request.GET:
request._cache_update_cache = False request._cache_update_cache = False
return None # Don't bother checking the cache. return None # Don't bother checking the cache.
@ -55,7 +55,7 @@ class CacheMiddleware(object):
if not hasattr(request, '_cache_update_cache') or not request._cache_update_cache: if not hasattr(request, '_cache_update_cache') or not request._cache_update_cache:
# We don't need to update the cache, just return. # We don't need to update the cache, just return.
return response return response
if not request.META['REQUEST_METHOD'] == 'GET': if request.method != 'GET':
# This is a stronger requirement than above. It is needed # This is a stronger requirement than above. It is needed
# because of interactions between this middleware and the # because of interactions between this middleware and the
# HTTPMiddleware, which throws the body of a HEAD-request # HTTPMiddleware, which throws the body of a HEAD-request

View File

@ -39,7 +39,7 @@ class CommonMiddleware(object):
# trailing slash or a file extension. # trailing slash or a file extension.
if settings.APPEND_SLASH and (old_url[1][-1] != '/') and ('.' not in old_url[1].split('/')[-1]): if settings.APPEND_SLASH and (old_url[1][-1] != '/') and ('.' not in old_url[1].split('/')[-1]):
new_url[1] = new_url[1] + '/' new_url[1] = new_url[1] + '/'
if settings.DEBUG and request.META['REQUEST_METHOD'].lower() == 'post': if settings.DEBUG and request.method == 'POST':
raise RuntimeError, "You called this URL via POST, but the URL doesn't end in a slash and you have APPEND_SLASH set. Django can't redirect to the slash URL while maintaining POST data. Change your form to point to %s%s (note the trailing slash), or set APPEND_SLASH=False in your Django settings." % (new_url[0], new_url[1]) raise RuntimeError, "You called this URL via POST, but the URL doesn't end in a slash and you have APPEND_SLASH set. Django can't redirect to the slash URL while maintaining POST data. Change your form to point to %s%s (note the trailing slash), or set APPEND_SLASH=False in your Django settings." % (new_url[0], new_url[1])
if new_url != old_url: if new_url != old_url:
# Redirect # Redirect

View File

@ -11,7 +11,7 @@ class XViewMiddleware(object):
with an x-header indicating the view function. This is used by the with an x-header indicating the view function. This is used by the
documentation module to lookup the view function for an arbitrary page. documentation module to lookup the view function for an arbitrary page.
""" """
if request.META['REQUEST_METHOD'] == 'HEAD' and request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS: if request.method == 'HEAD' and request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS:
response = http.HttpResponse() response = http.HttpResponse()
response['X-View'] = "%s.%s" % (view_func.__module__, view_func.__name__) response['X-View'] = "%s.%s" % (view_func.__module__, view_func.__name__)
return response return response

View File

@ -31,7 +31,7 @@ class ConditionalGetMiddleware(object):
response.content = '' response.content = ''
response['Content-Length'] = '0' response['Content-Length'] = '0'
if request.META['REQUEST_METHOD'] == 'HEAD': if request.method == 'HEAD':
response.content = '' response.content = ''
return response return response

View File

@ -17,12 +17,11 @@ def require_http_methods(request_method_list):
# I can assume now that only GET or POST requests make it this far # I can assume now that only GET or POST requests make it this far
# ... # ...
Note that request methods ARE case sensitive. Note that request methods should be in uppercase.
""" """
def decorator(func): def decorator(func):
def inner(request, *args, **kwargs): def inner(request, *args, **kwargs):
method = request.META.get("REQUEST_METHOD", None) if request.method not in request_method_list:
if method not in request_method_list:
return HttpResponseNotAllowed(request_method_list) return HttpResponseNotAllowed(request_method_list)
return func(request, *args, **kwargs) return func(request, *args, **kwargs)
return inner return inner

View File

@ -106,7 +106,7 @@ def update_object(request, model, object_id=None, slug=None,
if request.POST: if request.POST:
new_data = request.POST.copy() new_data = request.POST.copy()
if model._meta.has_field_type(FileField): if model._meta.has_field_type(FileField):
new_data.update(request.FILES) new_data.update(request.FILES)
errors = manipulator.get_validation_errors(new_data) errors = manipulator.get_validation_errors(new_data)
manipulator.do_html2python(new_data) manipulator.do_html2python(new_data)
@ -178,7 +178,7 @@ def delete_object(request, model, post_delete_redirect,
except ObjectDoesNotExist: except ObjectDoesNotExist:
raise Http404, "No %s found for %s" % (model._meta.app_label, lookup_kwargs) raise Http404, "No %s found for %s" % (model._meta.app_label, lookup_kwargs)
if request.META['REQUEST_METHOD'] == 'POST': if request.method == 'POST':
object.delete() object.delete()
if not request.user.is_anonymous(): if not request.user.is_anonymous():
request.user.message_set.create(message="The %s was deleted." % model._meta.verbose_name) request.user.message_set.create(message="The %s was deleted." % model._meta.verbose_name)