Code

Ticket #2747: django-3764-XheaderDoc.diff.txt

File django-3764-XheaderDoc.diff.txt, 2.5 KB (added by anonymous, 8 years ago)
Line 
1This patch makes bookmarklets work for people without static IPs on their
2development workstations. All the nice bookmarkletts django provides now
3work  not only ffor uders coming from INTERNAL_IPS but from all users where
4is_staff=True.
5  --md@hudora.de
6
7Index: django/core/xheaders.py
8===================================================================
9--- django/core/xheaders.py     (revision 3764)
10+++ django/core/xheaders.py     (working copy)
11@@ -13,9 +13,11 @@
12     """
13     Adds the "X-Object-Type" and "X-Object-Id" headers to the given
14     HttpResponse according to the given model and object_id -- but only if the
15-    given HttpRequest object has an IP address within the INTERNAL_IPS setting.
16+    given HttpRequest object has an IP address within the INTERNAL_IPS setting
17+    or if the request is from a logged in staff user.
18     """
19     from django.conf import settings
20-    if request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS:
21+    if (request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS) \
22+      or (request.user.is_authenticated() 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)
25Index: django/middleware/doc.py
26===================================================================
27--- django/middleware/doc.py    (revision 3764)
28+++ django/middleware/doc.py    (working copy)
29@@ -7,11 +7,14 @@
30     """
31     def process_view(self, request, view_func, view_args, view_kwargs):
32         """
33-        If the request method is HEAD and the IP is internal, quickly return
34-        with an x-header indicating the view function.  This is used by the
35-        documentation module to lookup the view function for an arbitrary page.
36+        If the request method is HEAD and the IP is internal or the user is
37+        a logged in staff user, quickly return with an x-header indicating
38+        the view function.  This is used by the documentation module to
39+        lookup the view function for an arbitrary page.
40         """
41-        if request.method == 'HEAD' and request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS:
42+        if request.method == 'HEAD' \
43+            and ((request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS) \
44+              or (request.user.is_authenticated() and request.user.is_staff)):
45             response = http.HttpResponse()
46             response['X-View'] = "%s.%s" % (view_func.__module__, view_func.__name__)
47             return response