-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
closes #143
- Loading branch information
Showing
14 changed files
with
75 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ Getting started | |
|
||
installation | ||
configuration | ||
page_detection | ||
signals | ||
js_utilities | ||
js_translations | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
Page Detection | ||
============== | ||
|
||
Baton triggers some of its functionalities basing upon the current page. For example, it will trigger the tab functionality only when the current page is an add form or change form page. | ||
|
||
Baton understands which page is currently displayed performing some basic regular expressions against the location pathname. | ||
There may be cases in which you'd like to serve such contents at different and custom urls, in such cases you need a way to tell Baton which kind of page is tied to that url. | ||
|
||
For this reason you can inject your custom hook, a javascript function which should return the page type and that receives as first argument the Baton's default function to use as fallback, i.e. :: | ||
|
||
<!-- admin/base_site.html --> | ||
<script> | ||
(function ($, undefined) { | ||
$(document).ready(function () { | ||
Baton.detectPageHook = fn => /newschange/.test(location.pathname) ? 'change_form' : fn() | ||
Baton.init(JSON.parse(document.getElementById('baton-config').textContent)); | ||
}) | ||
})(jQuery, undefined) | ||
</script> | ||
|
||
In this case we tell Baton that when the location pathname includes the string ``newschange``, then the page should be considered a ``change_form``, otherwise we let Baton guess the page type. | ||
|
||
So, in order to hook into the Baton page detection system, just define a ``Baton.detectPageHook`` function which receives the default function as first argument and should return the page type. | ||
|
||
The available page types are the following: ``dashboard``, ``admindocs``, ``login``, ``logout``, ``passowrd_change``, ``password_change_success``, ``add_form``, ``change_form``, ``changelist``, ``filer``, ``default``. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
from django.shortcuts import render | ||
from .admin import NewsAdmin | ||
from .models import News | ||
from baton.autodiscover import admin | ||
|
||
# Create your views here. | ||
|
||
def news_change_view(request, id): | ||
return NewsAdmin(News, admin.site).change_view(request, str(id)) |