Fixed #407 -- Code no longer assumes request.META['REMOTE_ADDR'] exists. Thanks, sune.kirkeby@gmail.com

git-svn-id: http://code.djangoproject.com/svn/django/trunk@580 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2005-08-31 16:27:59 +00:00
parent abe7fb8173
commit cb6aa1035b
4 changed files with 5 additions and 5 deletions

View File

@ -204,7 +204,7 @@ def post_comment(request):
new_data = request.POST.copy() new_data = request.POST.copy()
new_data['content_type_id'] = content_type_id new_data['content_type_id'] = content_type_id
new_data['object_id'] = object_id new_data['object_id'] = object_id
new_data['ip_address'] = request.META['REMOTE_ADDR'] new_data['ip_address'] = request.META.get('REMOTE_ADDR')
new_data['is_public'] = comments.IS_PUBLIC in option_list new_data['is_public'] = comments.IS_PUBLIC in option_list
response = HttpResponse() response = HttpResponse()
manipulator = PublicCommentManipulator(request.user, manipulator = PublicCommentManipulator(request.user,

View File

@ -79,7 +79,7 @@ class BaseHandler:
if DEBUG: if DEBUG:
return self.get_technical_error_response() return self.get_technical_error_response()
else: else:
subject = 'Database error (%s IP): %s' % ((request.META['REMOTE_ADDR'] in INTERNAL_IPS and 'internal' or 'EXTERNAL'), getattr(request, 'path', '')) subject = 'Database error (%s IP): %s' % ((request.META.get('REMOTE_ADDR') in INTERNAL_IPS and 'internal' or 'EXTERNAL'), getattr(request, 'path', ''))
message = "%s\n\n%s" % (self._get_traceback(), request) message = "%s\n\n%s" % (self._get_traceback(), request)
mail_admins(subject, message, fail_silently=True) mail_admins(subject, message, fail_silently=True)
return self.get_friendly_error_response(request, resolver) return self.get_friendly_error_response(request, resolver)
@ -89,7 +89,7 @@ class BaseHandler:
if DEBUG: if DEBUG:
return self.get_technical_error_response() return self.get_technical_error_response()
else: else:
subject = 'Coding error (%s IP): %s' % ((request.META['REMOTE_ADDR'] in INTERNAL_IPS and 'internal' or 'EXTERNAL'), getattr(request, 'path', '')) subject = 'Coding error (%s IP): %s' % ((request.META.get('REMOTE_ADDR') in INTERNAL_IPS and 'internal' or 'EXTERNAL'), getattr(request, 'path', ''))
try: try:
request_repr = repr(request) request_repr = repr(request)
except: except:

View File

@ -17,6 +17,6 @@ def populate_xheaders(request, response, package, python_module_name, object_id)
within the INTERNAL_IPS setting. within the INTERNAL_IPS setting.
""" """
from django.conf.settings import INTERNAL_IPS from django.conf.settings import INTERNAL_IPS
if request.META['REMOTE_ADDR'] in INTERNAL_IPS: if request.META.get('REMOTE_ADDR') in INTERNAL_IPS:
response['X-Object-Type'] = "%s.%s" % (package, python_module_name) response['X-Object-Type'] = "%s.%s" % (package, python_module_name)
response['X-Object-Id'] = str(object_id) response['X-Object-Id'] = str(object_id)

View File

@ -12,7 +12,7 @@ class XViewMiddleware:
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['REMOTE_ADDR'] in settings.INTERNAL_IPS: if request.META['REQUEST_METHOD'] == 'HEAD' and request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS:
response = httpwrappers.HttpResponse() response = httpwrappers.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