2005-07-13 09:25:57 +08:00
|
|
|
"""
|
2005-07-16 00:52:08 +08:00
|
|
|
Pages in Django can are served up with custom HTTP headers containing useful
|
|
|
|
information about those pages -- namely, the content type and object ID.
|
2005-07-13 09:25:57 +08:00
|
|
|
|
|
|
|
This module contains utility functions for retrieving and doing interesting
|
|
|
|
things with these special "X-Headers" (so called because the HTTP spec demands
|
2005-07-16 00:52:08 +08:00
|
|
|
that custom headers are prefxed with "X-").
|
2005-07-13 09:25:57 +08:00
|
|
|
|
|
|
|
Next time you're at slashdot.org, watch out for X-Fry and X-Bender. :)
|
|
|
|
"""
|
|
|
|
|
2006-05-02 09:31:56 +08:00
|
|
|
def populate_xheaders(request, response, model, object_id):
|
2005-07-13 09:25:57 +08:00
|
|
|
"""
|
|
|
|
Adds the "X-Object-Type" and "X-Object-Id" headers to the given
|
2006-05-02 09:31:56 +08:00
|
|
|
HttpResponse according to the given model and object_id -- but only if the
|
2006-09-22 11:17:28 +08:00
|
|
|
given HttpRequest object has an IP address within the INTERNAL_IPS setting
|
|
|
|
or if the request is from a logged in staff member.
|
2005-07-13 09:25:57 +08:00
|
|
|
"""
|
2006-05-02 09:31:56 +08:00
|
|
|
from django.conf import settings
|
2006-09-22 11:17:28 +08:00
|
|
|
if request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS or (request.user.is_authenticated() and request.user.is_staff):
|
2006-05-02 09:31:56 +08:00
|
|
|
response['X-Object-Type'] = "%s.%s" % (model._meta.app_label, model._meta.object_name.lower())
|
2005-07-13 09:25:57 +08:00
|
|
|
response['X-Object-Id'] = str(object_id)
|