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

support for subpages #29

Open
jorenham opened this issue Mar 2, 2018 · 6 comments
Open

support for subpages #29

jorenham opened this issue Mar 2, 2018 · 6 comments

Comments

@jorenham
Copy link

jorenham commented Mar 2, 2018

http://docs.wagtail.io/en/stable/reference/contrib/routablepage.html
Perhaps using a setting to enable this.

@robmoorman
Copy link
Collaborator

Thanks for your suggestions @jorenham . First thought will be override the get_static_site_paths method.

You can use this already to make your custom page render multiple static html files. However we want to provide people with off-the-shelf solutions to make it much easier as you suggest.

Could you let me know if this works (for now) for you?

@robmoorman
Copy link
Collaborator

@jorenham
Copy link
Author

jorenham commented Mar 5, 2018

@robmoorman The get_static_site_paths solution does not seem to do the trick. Adding a print statement to it reveals it does not get called when building.

@jorenham
Copy link
Author

jorenham commented Mar 18, 2018

I solved it. Just add the attribute subpage_urls = ['some_sub_page/'] to your routable page models and import of the following views instead of 'wagtailbakery.views.AllPagesView'.

import logging

import os
from django.test.client import RequestFactory
from wagtailbakery.views import AllPagesView, AllPublishedPagesView

logger = logging.getLogger(__name__)


class AllSubpagesView(AllPagesView):
    def build_subpages(self, obj):
        site = obj.get_site()
        base_url = self.get_url(obj)

        for subpage_url in obj.subpage_urls:
            url = base_url + subpage_url
            logger.debug("Building %s" % url)
            self.request = RequestFactory(SERVER_NAME=site.hostname).get(url)
            self.set_kwargs(obj)

            build_path = self.get_subpage_build_path(obj, subpage_url)
            self.build_file(build_path, self.get_content(obj))

    def get_subpage_build_path(self, obj, subpage_url):
        base_path = os.path.dirname(self.get_build_path(obj))
        path = os.path.join(base_path, subpage_url)

        os.path.exists(path) or os.makedirs(path)

        return os.path.join(path, 'index.html')

    def build_queryset(self):
        super(AllSubpagesView, self).build_queryset()

        for item in self.get_queryset().all():
            specific_item = item.specific
            if hasattr(specific_item, 'subpage_urls'):
                self.build_subpages(specific_item)


class AllPublishedSubpagesView(AllSubpagesView, AllPublishedPagesView):
    pass

@robmoorman
Copy link
Collaborator

That's awesome @jorenham . I'll keep your implementation as an example till we have supported this.

@smulloni
Copy link

smulloni commented Jun 7, 2021

This or something like it would be great to add to wagtail-bakery itself. Any blockers?

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

No branches or pull requests

4 participants