Skip to content

Commit

Permalink
Set inline label number in django admin 1.9+. fixes #79
Browse files Browse the repository at this point in the history
  • Loading branch information
fdintino committed Jul 11, 2017
1 parent efb64f4 commit add6726
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 6 deletions.
7 changes: 6 additions & 1 deletion nested_admin/static/nested_admin/dist/nested_admin.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion nested_admin/static/nested_admin/dist/nested_admin.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion nested_admin/static/nested_admin/dist/nested_admin.min.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import regexQuote from './regexquote';
import './jquery.ui.nestedsortable';

export function updatePositions(prefix) {
var position = 0,
var position = 0, // the value of the position formfield
count = 1, // The count displayed in stacked inline headers
$group = $('#' + prefix + '-group'),
groupData = $group.djnData(),
fieldNames = groupData.fieldNames,
Expand Down Expand Up @@ -48,6 +49,11 @@ export function updatePositions(prefix) {
return;
}

// Set header position for stacked inlines in Django 1.9+
var $inlineLabel = $this.find('> h3 > .inline_label');
$inlineLabel.html($inlineLabel.html().replace(/(#\d+)/g, '#' + count));
count++;

var $fields = $this.djangoFormField('*'),
$positionField,
setPosition = false;
Expand Down
26 changes: 25 additions & 1 deletion nested_admin/tests/two_deep/tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import time
from unittest import skipIf
from unittest import skipIf, SkipTest

import django

Expand Down Expand Up @@ -778,6 +778,30 @@ class TestStackedInlineAdmin(InlineAdminTestCaseMixin, BaseNestedAdminTestCase):
root_model = StackedGroup
nested_models = (StackedSection, StackedItem)

def test_add_item_inline_label_update(self):
if django.VERSION < (1, 9):
raise SkipTest("Test only applies to Django 1.9+")
if self.has_grappelli:
raise SkipTest("Test does not apply if using django-grappelli")
if self.has_suit:
raise SkipTest("Test does not apply if using django-suit")
group = self.root_model.objects.create(slug='test')
self.section_cls.objects.create(slug='test', group=group, position=0)

self.load_admin(group)
item_verbose_name = self.item_cls._meta.verbose_name.title()
with self.clickable_xpath('//a[contains(string(.), "Add another %s")]' % item_verbose_name) as el:
el.click()
with self.clickable_xpath('//input[@name="section_set-0-item_set-0-name"]') as el:
el.send_keys("Test 1")
with self.clickable_xpath('//a[contains(string(.), "Add another %s")]' % item_verbose_name) as el:
el.click()
with self.clickable_xpath('//input[@name="section_set-0-item_set-0-name"]') as el:
el.send_keys("Test 2")

inline_label = self.get_item([0, 1]).find_element_by_class_name('inline_label')
self.assertEqual(inline_label.text, '#2')


class TestTabularInlineAdmin(InlineAdminTestCaseMixin, BaseNestedAdminTestCase):

Expand Down

0 comments on commit add6726

Please sign in to comment.