Login

In page edit object links

Author:
punteney
Posted:
April 11, 2008
Language:
JavaScript
Version:
Not specified
Score:
2 (after 2 ratings)

This javascript has the functionality of the 'Edit Object' bookmarklet as described by James Bennett but instead of putting it within a bookmarklet it creates a div on the page with a link to the main admin screen, an edit the object link, and logout link.

Just include the javascript on any page you want the links to show up on and make sure that the page is using the populate_xheaders function to provide the needed headers as described here. The built in generic views provide the needed headers by default.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function django_admin_links_div() {
    // Update these variables for your site
    var admin_url = '/admin/';
    var div_title = 'Admin';
    var div_style = 'position: fixed; top: 0; right: 0; border: solid #008999 1px; padding: 3px 5px 3px 5px; text-align: center; color: #000; background: #EEDEBC; font-size: 11px; z-index:999;';
    // end variables to update
    if(typeof ActiveXObject != 'undefined') {
       var x = new ActiveXObject('Microsoft.XMLHTTP');
    }
    else if(typeof XMLHttpRequest != 'undefined') {
       var x = new XMLHttpRequest();
    }
    else {
       return;
    }
    x.open('GET', location.href, false);
    x.send(null);
    try {
       var type = x.getResponseHeader('x-object-type');
       var id = x.getResponseHeader('x-object-id');
    }
    catch(e) {
       return;
    }
    var div = document.createElement('div');
    div.style.cssText = div_style;
    div.innerHTML = '<b><a href="'+admin_url+'">'+div_title+'</a></b><br /><a href="'+admin_url + type.split('.').join('/') + '/' + id + '/">Edit '+type.split('.')[1]+'</a> &nbsp; <a href="'+admin_url+'logout/">Logout</a>';
    document.body.appendChild(div);
}
django_admin_links_div();

More like this

  1. Django Collapsed Stacked Inlines by applecat 1 year, 1 month ago
  2. Django Collapsed Stacked Inlines by mkarajohn 3 years, 2 months ago
  3. Dynamically adding forms to a formset. OOP version. by halfnibble 8 years, 10 months ago
  4. Convert multiple select for m2m to multiple checkboxes in django admin form by abidibo 10 years, 11 months ago
  5. Django admin inline ordering - javascript only implementation by ojhilt 11 years, 3 months ago

Comments

Please login first before commenting.