2 Pages in Django can are served up with custom HTTP headers containing useful
3 information about those pages -- namely, the content type and object ID.
5 This module contains utility functions for retrieving and doing interesting
6 things with these special "X-Headers" (so called because the HTTP spec demands
7 that custom headers are prefixed with "X-").
9 Next time you're at slashdot.org, watch out for X-Fry and X-Bender. :)
12 def populate_xheaders(request
, response
, model
, object_id
):
14 Adds the "X-Object-Type" and "X-Object-Id" headers to the given
15 HttpResponse according to the given model and object_id -- but only if the
16 given HttpRequest object has an IP address within the INTERNAL_IPS setting
17 or if the request is from a logged in staff member.
19 from google
.appengine
._internal
.django
.conf
import settings
20 if (request
.META
.get('REMOTE_ADDR') in settings
.INTERNAL_IPS
21 or (hasattr(request
, 'user') and request
.user
.is_active
22 and request
.user
.is_staff
)):
23 response
['X-Object-Type'] = "%s.%s" % (model
._meta
.app_label
, model
._meta
.object_name
.lower())
24 response
['X-Object-Id'] = str(object_id
)