-
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.
Merge branch 'feature/changelist-text' into develop
- Loading branch information
Showing
13 changed files
with
172 additions
and
21 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.
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{% extends 'admin/change_list.html' %} | ||
{% block content %}{{ block.super }} | ||
|
||
{% for template, position in cl.model_admin.baton_cl_includes %} | ||
<template data-position="{{ position }}"> | ||
<div class="baton-cl-include baton-cl-include-{{ position }}"> | ||
{% include template %} | ||
</div> | ||
</template> | ||
{% endfor %} | ||
{% endblock %} |
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,32 @@ | ||
Form includes | ||
========= | ||
|
||
.. image:: images/baton-cl-includes.png | ||
|
||
Baton lets you include templates directly inside the change list page, in any position you desire. It's as simple as specifying the template path and the position of the template:: | ||
|
||
@admin.register(News) | ||
class NewsAdmin(admin.ModelAdmin): | ||
#... | ||
baton_cl_includes = [ | ||
('news/admin_include_top.html', 'top', ), | ||
('news/admin_include_below.html', 'below', ) | ||
] | ||
|
||
In this case, Baton will place the content of the ``admin_include_top.html`` template at the top of the changelist section (above the search field), and the content of the ``admin_include_below.html`` below the changelist form. | ||
|
||
You can specify the following positions: | ||
|
||
+----------------------------------------+--------------------------------------------------------------------+ | ||
| Position | Description | | ||
+========================================+====================================================================+ | ||
| top | the template is placed inside the changelist form, at the top | | ||
+----------------------------------------+--------------------------------------------------------------------+ | ||
| bottom | the template is placed inside the changelist form, at the bottom | | ||
+----------------------------------------+--------------------------------------------------------------------+ | ||
| above | the template is placed above the changelist form | | ||
+----------------------------------------+--------------------------------------------------------------------+ | ||
| below | the template is placed below the changelist form | | ||
+----------------------------------------+--------------------------------------------------------------------+ | ||
|
||
And, of course, you can access the all the changelist view context variables inside your template. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import os | ||
import time | ||
|
||
from django.test import TestCase | ||
from selenium import webdriver | ||
from selenium.webdriver.chrome.options import Options | ||
from selenium.webdriver.common.by import By | ||
from selenium.webdriver.support.ui import WebDriverWait | ||
from webdriver_manager.chrome import ChromeDriverManager | ||
|
||
from .utils import element_has_css_class | ||
|
||
os.environ['WDM_LOG_LEVEL'] = '0' | ||
|
||
|
||
class TestBatonClIncludes(TestCase): | ||
def setUp(self): | ||
chrome_options = Options() | ||
chrome_options.add_argument("--headless") | ||
chrome_options.add_argument('--no-sandbox') | ||
chrome_options.add_argument('--disable-extensions') | ||
chrome_options.add_argument('--disable-dev-shm-usage') | ||
self.driver = webdriver.Chrome( | ||
ChromeDriverManager().install(), | ||
options=chrome_options, | ||
) | ||
self.driver.set_window_size(1920, 1080) | ||
self.driver.implicitly_wait(10) | ||
self.login() | ||
|
||
def tearDown(self): | ||
self.driver.quit() | ||
|
||
def login(self): | ||
self.driver.get('http://localhost:8000/admin/news/news/') | ||
username_field = self.driver.find_element_by_id("id_username") | ||
password_field = self.driver.find_element_by_id("id_password") | ||
button = self.driver.find_element_by_css_selector('input[type=submit]') | ||
|
||
username_field.send_keys('admin') | ||
time.sleep(1) | ||
password_field.send_keys('admin') | ||
time.sleep(1) | ||
button.click() | ||
|
||
def test_includes(self): | ||
# Wait until baton is ready | ||
wait = WebDriverWait(self.driver, 10) | ||
wait.until(element_has_css_class((By.TAG_NAME, 'body'), "baton-ready")) | ||
time.sleep(2) | ||
|
||
# tabs number | ||
include = self.driver.find_element_by_css_selector( | ||
'.baton-cl-include-top') | ||
self.assertEqual(include.is_displayed(), True) | ||
parent = include.find_element_by_xpath('..') | ||
self.assertEqual(parent.get_attribute('id'), 'changelist-form') |
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
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,3 @@ | ||
<p> | ||
In ut quam vitae odio lacinia tincidunt. Sed magna purus, fermentum eu, tincidunt eu, varius ut, felis. Quisque id mi. Vestibulum dapibus nunc ac augue. Praesent ac massa at ligula laoreet iaculis. Nullam quis ante. Nam at tortor in tellus interdum sagittis. Praesent egestas neque eu enim. Proin viverra, ligula sit amet ultrices semper, ligula arcu tristique sapien, a accumsan nisi mauris ac eros. Aliquam eu nunc. | ||
</p> |