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

Move template partial logic to mixin #103

Open
joshuadavidthomas opened this issue Aug 6, 2024 · 0 comments
Open

Move template partial logic to mixin #103

joshuadavidthomas opened this issue Aug 6, 2024 · 0 comments
Labels
🚨 breaking Breaking changes 🏋️ improvement Enhancements or optimizations to existing functionality

Comments

@joshuadavidthomas
Copy link
Member

In the most recent release (v0.15.0) I had to introduce a breaking change to crud.CRUDView related to template partials. I originally copied the code dealing with that from a project that used it and didn't think through all of the downstream effects it would have.

I think template partials should be an opt-in thing per-project, and right now that's accomplished via a class attribute enable_template_partials flag on CRUDView. I wonder if moving all the template partial logic to a specific mixin for that would be a good workaround for allowing project's to opt-in, by just adding it to the view class inheritence? This way, CRUDView could be left alone and continue to function without breaking projects using it and you could opt in by choice.

It could also allow a space for expanding the functionality of the template partial rendering, as right now it's just focused on the list view.

class TemplatePartialMixin:
	list_partial: ClassVar[str] = "object-list"

    def get_template_names(self):
        template_names = super().get_template_names()

        if (
            self.role == Role.LIST
            and getattr(self.request, "htmx", False)
            and self.request.htmx
            and not self.kwargs.get(self.page_kwarg, None)  # pyright: ignore[reportAny]
            and not self.request.GET.get(self.page_kwarg, None)
        ):
            template_names = [
                f"{template_name}#{self.list_partial}"
                for template_name in template_names
            ]

        return template_names
@joshuadavidthomas joshuadavidthomas added 🚨 breaking Breaking changes 🏋️ improvement Enhancements or optimizations to existing functionality labels Aug 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🚨 breaking Breaking changes 🏋️ improvement Enhancements or optimizations to existing functionality
Projects
None yet
Development

No branches or pull requests

1 participant