-
Notifications
You must be signed in to change notification settings - Fork 32
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
Add RFC 007, PageConfigs #7
base: main
Are you sure you want to change the base?
Conversation
Could we renumber this to 7 to match the pull request number? I know this might introduce confusing gaps but I think it would be nice to have an easy way to get back to the initial discussion from the RFC number. Also, cheers for making an RFC! |
I've renumbered it, as suggested. |
I agree this aspect of Wagtail is badly in need of a clean-up - thanks for tackling it @timheap! I like the idea of 'wrapping' models in helper classes that provide the configuration for a particular problem domain, instead of cramming the base model with peripherally-relevant settings and methods - like django.contrib.admin does with ModelAdmin classes, and Django Rest Framework does with serializers. We should absolutely do more of that. (I'm sure the design pattern folks must have a name for this - I really should read the Gang Of Four book some day...) Do we gain anything from having a central PageConfig registry for these things, rather than each module defining their own distinct wrapper? (It seems to me that PageConfigs are liable to get just as bloated as Page models do at the moment.) I could imagine a setup where each app has a There are a few things I'm reluctant to offload to a wrapper class - to me Probably the toughest decision for me here is what to do about the whole page template rendering infrastructure. The principle of |
I agree that individual configurations would be technically cleaner, but I don't think it strikes the right balance between technical purity and developer usability. Consider the configuration for a searchable, sitemappable, static-generatable page: from .models import MyPage
@register_page_config(MyPage)
class MyPageConfig(PageConfig):
subpage_types = []
base_form_class = MyPageForm
content_panels = [
# ...
]
@register_search_config(MyPage)
class MyPageSearchConfig(SearchConfig):
search_fields = [
# ....
]
@register_sitemap_config(MyPage)
class MyPageSitemapConfig(SitemapConfig):
def get_sitemap_urls(self, page):
return ['/', '/foo/', '/bar/'] And then repeat this for another few pages. I think we will loose a considerable amount of convenience and developer friendliness that currently exists with the way Wagtail groups everything together. Split across multiple files, and the sheer number of files with tiny snippets of configuration would become unmanageable in a different way. It would also make interactions between different mixins difficult. Consider a RoutablePage that knew how to automatically fill out If you swap how you think about the models vs. configurations, I think I can convince you that the PageConfig class is the correct place for the This then makes it clear where the rendering functionality should live: on the PageConfig, which is what makes a Page a Page. The model merely stores the data for the PageConfig to use later when needed. It also adheres more to the MVC ideal, and opens up the possibility of multiple renderings for the same underlying datastore. |
On a sidenote, I feel like the Proxy page models RFC wagtail/wagtail#1736 is meant to solve some of the same issues: i.e. having a separate entity in the admin that renders the page with a different template, without duplicating the data definition. But instead of registering a page config, it works by subclassing a page. Although, I guess it doesn't make things much more MVC-like. |
No description provided.