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

Working fine, but instead of showing name of page, the breadcrumb shows the slug of the page #5

Open
SEGATON opened this issue Apr 6, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@SEGATON
Copy link

SEGATON commented Apr 6, 2023

Screenshot 2023-04-06 at 5 51 21 PM

It works fine, but its showing the slug not the page title.

Any idea what may have cause this?

~Cheers

@SEGATON
Copy link
Author

SEGATON commented Apr 9, 2023

Anybody?

@marcanuy marcanuy added the enhancement New feature or request label Apr 10, 2023
@marcanuy
Copy link
Owner

This is the intended behavior, showing the page title instead requires to process each level but can be a good feature for the next versions.

@vanderzielj
Copy link

I was not satisfied with this behavior either so much that it might have been a blocker. However, Since the heart of the implementation is just a context processor, I took that part and the classes and incorporated it into my own code (with your license and an attribution, of course) without installing the application. I added a method to fetch the view from the resolver (all of my views are class-based views). With the view I was able to get the model and from the model grab the instance for the breadcrumb item to get the name of the item. Barring that I simply title-case the breadcrumb:

    def _get_resolver_match(self):
        try:
            return resolve(self.path)
        except Resolver404:
            return None

    def _get_model_from_view(self):
        if self.resolved_url:
            view_func = self.resolver_match.func

            # Check if the view function is a class-based view
            if hasattr(view_func, "view_class"):
                # Retrieve the model attribute from the view class
                view_class = view_func.view_class
                if hasattr(view_class, "model") and hasattr(view_class.model, "name"):
                    model = view_class.model
                    return model

        return None

    def get_url(self):
        if self.resolved_url:
            return reverse(
                self.resolver_match.view_name, kwargs=self.resolver_match.kwargs
            )

        result = urljoin(self.base_url, self.path)
        return result

    def get_name(self):
        # if hasattr(settings, "BREADCRUMBS_VERBOSE_NAME") and settings.BREADCRUMBS_VERBOSE_NAME:
        #     return self.name_raw
        view_model = self._get_model_from_view()
        if view_model and "pk" in self.resolver_match.kwargs:
            model_instance = view_model.objects.get(pk=self.resolver_match.kwargs["pk"])

            return model_instance.name or self.resolver_match.kwargs["pk"]

        # if self.position == 2:
        #     try:
        #         return apps.get_app_config(self.name_raw).verbose_name
        #     finally:
        #         pass

        return self.name_raw.title()

I posted an "issue" #9 about the commented-out code. I do not understand the intention of that code.

breadcrumbs.zip

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

No branches or pull requests

3 participants