Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom change_list_template in admin views using mixins #1483

Conversation

nikhaldi
Copy link

Problem

The mixins for the admin integration override the admin change_list_template. This means that any customization of that template done by the user is effectively ignored. This also means that django-export-import is not compatible with mixins from other libraries that customize the object tools in the change list view (e.g., django-admin-sortable2 or reversion).

This issue was reported in #1450

Solution

This makes the change_list_template extend whatever customized template is already present in the class hierarchy. This solution is loosely based on the solution to the same issue in django-admin-sortable2.

Acceptance Criteria

Additional assertions in admin integration tests cover this use case.

@matthewhegarty
Copy link
Contributor

Thanks @nikhaldi. Wondered if you could review @pokken-magic?

@coveralls
Copy link

Coverage Status

Coverage increased (+0.01%) to 98.41% when pulling d5b2761 on nikhaldi:custom-change-list-template into 38e9f95 on django-import-export:main.

@pokken-magic
Copy link

Thanks @nikhaldi. Wondered if you could review @pokken-magic?

I will review but I think it's probably a good idea to have at least a glance with someone who knows django admin templates better than me; I almost exclusively work with DRF so my template fu is less robust.

Copy link

@pokken-magic pokken-magic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks very promising to me, thank you a lot for doing this. Only two minor comments from me.

import_export/admin.py Show resolved Hide resolved
tests/core/tests/test_admin_integration.py Show resolved Hide resolved
Copy link
Author

@nikhaldi nikhaldi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick review!

tests/core/tests/test_admin_integration.py Show resolved Hide resolved
import_export/admin.py Show resolved Hide resolved
@matthewhegarty
Copy link
Contributor

I'm thinking this fix would be better suited to our forthcoming 3.0 release. Is it possible you could reset the base branch to be release-3-x?

@nikhaldi nikhaldi changed the base branch from main to rel-3-x-x August 31, 2022 10:12
@nikhaldi nikhaldi changed the base branch from rel-3-x-x to release-3-x August 31, 2022 10:13
@nikhaldi
Copy link
Author

I'm thinking this fix would be better suited to our forthcoming 3.0 release. Is it possible you could reset the base branch to be release-3-x?

Makes sense, will do. Currently struggling with the mechanics of rebasing but I will figure it out and let you know when it's done.

This allows users to customize the change list templates when using mixins
provided by the library. In particular this enables adding more items to
the object tools, in addition to the ones added by the admin mixins. This
then makes this library compatible with other libraries that extend the
object tools, such as `django-admin-sortable2` or `reversion`.

Fixes django-import-export#1450
@nikhaldi
Copy link
Author

I'm thinking this fix would be better suited to our forthcoming 3.0 release. Is it possible you could reset the base branch to be release-3-x?

This is now rebased on release-3-x

Copy link

@pokken-magic pokken-magic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this all makes sense to me.

@matthewhegarty
Copy link
Contributor

matthewhegarty commented Sep 1, 2022

Thanks Nik for the change, and thanks Ryan for reviewing.

I will review but I think it's probably a good idea to have at least a glance with someone who knows django admin templates better than me

Likewise I don't know too much about admin templates. Looping in @PetrDlouhy in case he has time to review - that would be much appreciated.

@matthewhegarty
Copy link
Contributor

@nikhaldi there is another merge from release-3-x required to fix some issues - thanks

@matthewhegarty
Copy link
Contributor

Can you test using the example application? Looks like this change causes a rendering issue:

Screenshot from 2022-09-02 16-20-10

@nikhaldi
Copy link
Author

nikhaldi commented Sep 2, 2022

@nikhaldi there is another merge from release-3-x required to fix some issues - thanks

Thanks, should now be properly merged.

@nikhaldi
Copy link
Author

nikhaldi commented Sep 2, 2022

Can you test using the example application? Looks like this change causes a rendering issue:

It's not a rendering issue per se, it's just a text-only item that I inserted into the customized change list template. I need to insert something so I can write a test to verify it's working. I turned this into a real link (that goes nowhere) now, so it's maybe a bit less disjointed looking?

Screenshot 2022-09-02 at 17 14 31

Copy link
Contributor

@matthewhegarty matthewhegarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm concerned that the default button will be confusing for users, please see my alternative suggestion.

Should avoid confusion by users using the sample application.
@matthewhegarty
Copy link
Contributor

@nikhaldi thanks for the PR all looks good to me. One final question - do you think there is a risk that this might affect any existing implementations that users might have? If so, it will be fine for the v3 release but we may need to add a note to changelog.rst re breaking changes.

@matthewhegarty
Copy link
Contributor

For some reason, the link still renders when placed in object-tools-items - hence I placed it under result_list

Screenshot from 2022-09-05 19-50-56

Please could you fix this?

@nikhaldi
Copy link
Author

nikhaldi commented Sep 6, 2022

@nikhaldi thanks for the PR all looks good to me. One final question - do you think there is a risk that this might affect any existing implementations that users might have? If so, it will be fine for the v3 release but we may need to add a note to changelog.rst re breaking changes.

I would say the risk is small and it should rarely outright break something, but it can definitely affect existing implementation (e.g., it does in the real-world project I'm working on). I added a comment to the changelog but let me know if this is overkill.

@nikhaldi
Copy link
Author

nikhaldi commented Sep 6, 2022

For some reason, the link still renders when placed in object-tools-items - hence I placed it under result_list

Strange. You can see in the screenshot I posted previously that the list item is in the HTML source but is not rendered in my browser, but it may well be a browser-specific issue. I changed this to a HTML comment now, that will definitely not render and does the job.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants