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

Help requested with creating custom home page #543

Closed
Sreini opened this issue Dec 18, 2022 · 6 comments
Closed

Help requested with creating custom home page #543

Sreini opened this issue Dec 18, 2022 · 6 comments
Labels
Type: Question Further information is requested

Comments

@Sreini
Copy link

Sreini commented Dec 18, 2022

Hello,

First of all I would like to thank the creators for the cool software they put together. After struggling a little bit to put everything together I now am starting to grasp some of the ideas behind it and have a working website.

However, I now want to create a custom home page where my latest articles show up in a "news website" look. So, the "most important" article will have a headline format, and then other articles underneath it will show up in a more toned down way etc etc.

The best strategy for this seems to be based on this question I found: #530

In short, it is to create a custom "Latest Pages" block template. The advantages of this is that I would be using mostly pre-existing functionality.

However, I don't want just any article to show up in the headline. I was thinking of letting my editors use a "Headline" classifier term to point out what articles they want in the headline.

However, I also don't want only those articles showing up in the headline. Therefore what I would actually want to achieve is the following:

  1. Load the x latest articles
  2. sort these articles so that the articles with the "Headline" classifier go to the top (because If there are not enough "Headline" articles recently I still want my home page to show recent articles, i.e I don't want ONLY "headline" articles).
  3. display these pages in my own custom way

The step I'm unsure of is mostly number 2. I do not know how to do that.

So my questions are:

  • Is my thinking sound? Or should I use some other strategy?
  • If it is sound, how can I achieve this effect the best way?

Edit: I guess what I'm asking is: how do I add a custom ordering of pages based on a classifier term?

@Sreini Sreini added the Type: Question Further information is requested label Dec 18, 2022
@Sreini
Copy link
Author

Sreini commented Dec 18, 2022

After typing everything out I realize this literally already exists but I had missunderstood what it did. In fact, it does exactly what I'm asking for here:
image

@Sreini Sreini closed this as completed Dec 18, 2022
@vsalvino
Copy link
Contributor

Great! Yes there is a lot of power in the classifier system, unfortunately it is not very well documented. We need more "how-to" guides to help expose some of these features.

@Sreini
Copy link
Author

Sreini commented Dec 20, 2022

Actually after trying this a bit more I'm struck with one issue. How would I go about it if i want to have one "Latest Articles" block where I follow the ordering of a classifier, and then in another "Latest Pages" block I do not. Concretely I want to have one block where I have my headlines, and another where I have a "news stream" where news articles appear exclusively in the order which they were published. However all my articles are children of my one "Articles" page.

What do you recommend I do in this case?

@Sreini Sreini reopened this Dec 20, 2022
@Sreini
Copy link
Author

Sreini commented Dec 23, 2022

@vsalvino tagging you in case you hadn't seen this.

I'd be open to making a pull request if this is not possible, if we discuss the design and the how and what.

@Sreini
Copy link
Author

Sreini commented Dec 25, 2022

class PageListWithOrderOverrideBlock(PageListBlock):
    """
    Latest Page Preview block that allows user to override parent page ordering
    """

    override_order = blocks.BooleanBlock(
        required=False,
        default=False,
        label=_("Override parent ordering with first published date"),
    )

    class Meta:
        template = "coderedcms/blocks/pagelist_block.html"
        icon = "list-ul"
        label = _("Latest Pages with Override Ordering")

    def get_context(self, value, parent_context=None):

        context = super().get_context(value, parent_context=parent_context)

        indexer = value["indexed_by"].specific
        # try to use the CoderedPage `get_index_children()`,
        # but fall back to get_children if this is a non-CoderedPage
        if hasattr(indexer, "get_index_children"):
            pages = indexer.get_index_children()
            if value["classified_by"]:
                try:
                    pages = pages.filter(
                        classifier_terms=value["classified_by"]
                    )
                except AttributeError:
                    # `pages` is not a queryset, or is not a queryset of CoderedPage.
                    logger.warning(
                        (
                            "Tried to filter by ClassifierTerm in PageListBlock, "
                            "but <%s.%s ('%s')>.get_index_children() "
                            "did not return a queryset or is not a queryset of "
                            "CoderedPage models."
                        ),
                        indexer._meta.app_label,
                        indexer.__class__.__name__,
                        indexer.title,
                    )
        else:
            pages = indexer.get_children().live()

        if self.override_order:
            pages = pages.order_by("-first_published_at")
        context["pages"] = pages[: value["num_posts"]]
        return context

I have added a new block that will hopefully fix this issue. However, even if I run migrations, I do not seem to be able to select this block. Is there anything else I need to do?

@Sreini
Copy link
Author

Sreini commented Jan 1, 2023

I got this working thanks to finally (after reading through a lot of the code) understanding this issue and the solution inside of it: #305

However I feel like my use case is quite common, so I wonder if me making a pull request to change the existing PageListBlock would be appreciated?

@Sreini Sreini closed this as not planned Won't fix, can't repro, duplicate, stale Mar 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants