Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

* removed RemovedInDjango40Warning warning message, thanks to @Ivan-Feofanov
* fixed a bug where the handle_action function does not pass through parent objects into `get_inline_instances`

## [2.4.0] - 2021-02-08

Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
- [@tony](https://github.com/tony)
- [@tripliks](https://github.com/tripliks)
- [@Ivan-Feofanov](https://github.com/Ivan-Feofanov)
- [@asgoel](https://github.com/asgoel)
2 changes: 1 addition & 1 deletion inline_actions/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def _handle_action(self, request, object_id=None):
# parent_obj is None because `object_id` is None

else:
for inline in self.get_inline_instances(request):
for inline in self.get_inline_instances(request, obj=parent_obj):
inline_class_name = inline.__class__.__name__.lower()
matches_inline_class = inline_class_name == admin_class_name
matches_model = inline.model == model
Expand Down
13 changes: 12 additions & 1 deletion test_proj/blog/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from inline_actions.admin import InlineActionsMixin, InlineActionsModelAdminMixin

from . import forms
from .models import Article, Author, AuthorProxy
from .models import Article, Author, AuthorProxy, AuthorSecondProxy


class UnPublishActionsMixin(object):
Expand Down Expand Up @@ -138,6 +138,17 @@ class AuthorAdmin(InlineActionsModelAdminMixin, admin.ModelAdmin):
inline_actions = None


@admin.register(AuthorSecondProxy)
class AuthorMaybeInlineAdmin(InlineActionsModelAdminMixin, admin.ModelAdmin):
list_display = ('name',)
inline_actions = None

def get_inlines(self, request, obj):
if not obj or obj.name != 'DISPLAY INLINE':
return []
return [ArticleInline]


@admin.register(Article)
class ArticleAdmin(
UnPublishActionsMixin,
Expand Down
5 changes: 5 additions & 0 deletions test_proj/blog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,8 @@ def __str__(self):
class AuthorProxy(Author):
class Meta:
proxy = True


class AuthorSecondProxy(Author):
class Meta:
proxy = True
37 changes: 37 additions & 0 deletions test_proj/blog/tests/test_inline_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,43 @@ def test_publish_action(admin_client, mocker, article):
assert article.status == Article.DRAFT


def test_publish_action_works_with_dynamic_inlines(
admin_client, mocker, author, article
):
"""
Tests whether we can execute an inline action if the inline class is dynamically displayed.
"""
from ..admin import UnPublishActionsMixin

author.name = 'DISPLAY INLINE'
author.save()

mocker.spy(UnPublishActionsMixin, 'get_inline_actions')
mocker.spy(UnPublishActionsMixin, 'publish')
mocker.spy(UnPublishActionsMixin, 'unpublish')
assert article.status == Article.DRAFT

publish_input_name = (
'_action__articleinline__inline__publish__blog__article__{}'.format(article.pk)
)
unpublish_input_name = (
'_action__articleinline__inline__unpublish__blog__article__{}'.format(
article.pk
)
)
author_url = reverse('admin:blog_authorsecondproxy_change', args=(author.pk,))
changeview = admin_client.get(author_url)
assert UnPublishActionsMixin.get_inline_actions.call_count > 0
assert publish_input_name in dict(changeview.form.fields)
# execute and test publish action
changeview = changeview.form.submit(name=publish_input_name).follow()
article = Article.objects.get(pk=article.pk)
assert publish_input_name not in dict(changeview.form.fields)
assert unpublish_input_name in dict(changeview.form.fields)
assert UnPublishActionsMixin.publish.call_count == 1
assert article.status == Article.PUBLISHED


def test_view_action(admin_client, mocker, article):
"""Test view action."""
from inline_actions.actions import ViewAction
Expand Down