Skip to content

Commit

Permalink
Feature: Change InlinePanel for MultipleChoosePanel for better experi…
Browse files Browse the repository at this point in the history
…ence
  • Loading branch information
AdalbertoMoz committed Jun 21, 2024
1 parent da2d912 commit fcb85e5
Show file tree
Hide file tree
Showing 19 changed files with 125 additions and 52 deletions.
3 changes: 2 additions & 1 deletion network-api/networkapi/nav/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ class NavMenu(
panels.MultiFieldPanel(
[
panels.FieldPanel("enable_blog_dropdown"),
panels.InlinePanel(
panels.MultipleChooserPanel(
"featured_blog_topics",
chooser_field_name="topic",
label="Featured Blog Topics",
help_text="Choose up to 4 featured topics",
min_num=0,
Expand Down
9 changes: 7 additions & 2 deletions network-api/networkapi/wagtailpages/pagemodels/app_install.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.db import models
from wagtail.admin.panels import FieldPanel, InlinePanel, MultiFieldPanel
from wagtail.admin.panels import FieldPanel, MultiFieldPanel, MultipleChooserPanel
from wagtail.fields import StreamField
from wagtail_localize.fields import SynchronizedField, TranslatableField

Expand Down Expand Up @@ -58,7 +58,12 @@ class AppInstallPage(CampaignPage):
MultiFieldPanel(
[
FieldPanel("cta"),
InlinePanel("donation_modals", label="Donation Modal", max_num=4),
MultipleChooserPanel(
"donation_modals",
label="Donation Modal",
chooser_field_name="donation_modal",
max_num=4,
),
FieldPanel("body"),
],
heading="Page Content",
Expand Down
29 changes: 21 additions & 8 deletions network-api/networkapi/wagtailpages/pagemodels/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
from django.conf import settings
from django.db import models
from modelcluster.fields import ParentalKey
from wagtail.admin.panels import FieldPanel, InlinePanel, MultiFieldPanel
from wagtail.admin.panels import (
FieldPanel,
InlinePanel,
MultiFieldPanel,
MultipleChooserPanel,
)
from wagtail.fields import RichTextField, StreamField
from wagtail.images import get_image_model_string
from wagtail.models import Orderable as WagtailOrderable
Expand Down Expand Up @@ -224,7 +229,7 @@ class InitiativesPage(PrimaryPage):
FieldPanel("h3"),
FieldPanel("sub_h3"),
InlinePanel("initiative_sections", label="Initiatives"),
InlinePanel("featured_highlights", label="Highlights", max_num=9),
MultipleChooserPanel("featured_highlights", label="Highlights", chooser_field_name="highlight", max_num=9),
]

translatable_fields = [
Expand Down Expand Up @@ -401,7 +406,9 @@ class ParticipatePage2(PrimaryPage):
),
FieldPanel("h2"),
FieldPanel("h2Subheader"),
InlinePanel("featured_highlights", label="Highlights Group 1", max_num=3),
MultipleChooserPanel(
"featured_highlights", label="Highlights Group 1", chooser_field_name="highlight", max_num=3
),
MultiFieldPanel(
[
FieldPanel("ctaHero2"),
Expand All @@ -413,7 +420,9 @@ class ParticipatePage2(PrimaryPage):
heading="CTA 2",
classname="collapsible",
),
InlinePanel("featured_highlights2", label="Highlights Group 2", max_num=6),
MultipleChooserPanel(
"featured_highlights2", label="Highlights Group 2", chooser_field_name="highlight", max_num=6
),
MultiFieldPanel(
[
FieldPanel("ctaHero3"),
Expand Down Expand Up @@ -870,14 +879,14 @@ def get_banner(self):
),
MultiFieldPanel(
[
InlinePanel("focus_areas", min_num=3, max_num=3),
MultipleChooserPanel("focus_areas", chooser_field_name="area", min_num=3, max_num=3),
],
heading="Areas of focus",
classname="collapsible collapsed",
),
MultiFieldPanel(
[
InlinePanel("news_you_can_use", min_num=4, max_num=4),
MultipleChooserPanel("news_you_can_use", chooser_field_name="blog", min_num=4, max_num=4),
],
heading="News you can use",
classname="collapsible",
Expand All @@ -886,7 +895,9 @@ def get_banner(self):
[
FieldPanel("spotlight_image"),
FieldPanel("spotlight_headline"),
InlinePanel("spotlight_posts", label="Posts", min_num=3, max_num=3),
MultipleChooserPanel(
"spotlight_posts", chooser_field_name="blog", label="Posts", min_num=3, max_num=3
),
],
heading="spotlight",
classname="collapsible",
Expand Down Expand Up @@ -916,7 +927,9 @@ def get_banner(self):
FieldPanel("partner_page_text"),
FieldPanel("partner_page"),
FieldPanel("partner_background_image"),
InlinePanel("partner_logos", label="Partner Logo", max_num=7, min_num=1),
MultipleChooserPanel(
"partner_logos", label="Partner Logo", chooser_field_name="logo", max_num=7, min_num=1
),
],
heading="Partner",
classname="collapsible collapsed",
Expand Down
10 changes: 7 additions & 3 deletions network-api/networkapi/wagtailpages/pagemodels/blog/blog.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from wagtail import blocks
from wagtail.admin.panels import (
FieldPanel,
InlinePanel,
MultiFieldPanel,
MultipleChooserPanel,
PageChooserPanel,
PublishingPanel,
TitleFieldPanel,
Expand Down Expand Up @@ -171,7 +171,10 @@ class BlogPage(BasePage):
classname="full title",
widget=TitleWidget(attrs={"class": "max-length-warning", "data-max-length": 60}),
),
MultiFieldPanel([InlinePanel("authors", label="Author", min_num=1)], heading="Author(s)"),
MultiFieldPanel(
[MultipleChooserPanel("authors", label="Author", chooser_field_name="author", min_num=1)],
heading="Author(s)",
),
FieldPanel("topics", widget=CheckboxSelectMultiple),
MultiFieldPanel(
[
Expand All @@ -183,9 +186,10 @@ class BlogPage(BasePage):
FieldPanel("body"),
FieldPanel("feature_author_details", heading="Feature Author Details Section"),
FieldPanel("feature_comments"),
InlinePanel(
MultipleChooserPanel(
"related_posts",
label="Related Blog Posts",
chooser_field_name="related_post",
help_text="Pick three other posts that are related to this post. "
"If you pick fewer than three (or none), saving will "
"automatically bind some related posts based on tag matching.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
from django.shortcuts import get_object_or_404, redirect
from django.template import loader
from modelcluster.fields import ParentalKey, ParentalManyToManyField
from wagtail.admin.panels import FieldPanel, InlinePanel, PageChooserPanel
from wagtail.admin.panels import (
FieldPanel,
InlinePanel,
MultipleChooserPanel,
PageChooserPanel,
)
from wagtail.contrib.routable_page.models import route
from wagtail.fields import StreamField
from wagtail.models import Locale
Expand Down Expand Up @@ -112,9 +117,10 @@ class BlogIndexPage(IndexPage):
subpage_types = ["BlogPage"]

content_panels = IndexPage.content_panels + [
InlinePanel(
MultipleChooserPanel(
"featured_pages",
label="Featured",
chooser_field_name="blog",
help_text="Choose five blog pages to feature",
min_num=5,
max_num=5,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,22 @@ class BuyersGuideArticlePage(BasePage):

content_panels = wagtail_models.Page.content_panels + [
panels.FieldPanel("hero_image"),
panels.InlinePanel("author_profile_relations", heading="Authors", label="Author"),
panels.InlinePanel(
panels.MultipleChooserPanel(
"author_profile_relations", heading="Authors", label="Author", chooser_field_name="author_profile"
),
panels.MultipleChooserPanel(
"content_category_relations",
heading="Content categories",
label="Content category",
chooser_field_name="content_category",
max_num=2,
),
panels.FieldPanel("body"),
panels.InlinePanel(
panels.MultipleChooserPanel(
"related_article_relations",
heading="What to read next (related articles)",
label="Article",
chooser_field_name="article",
max_num=3,
),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from django.db import models
from modelcluster.fields import ParentalKey
from wagtail.admin.panels import FieldPanel, InlinePanel, MultiFieldPanel
from wagtail.admin.panels import FieldPanel, MultiFieldPanel, MultipleChooserPanel
from wagtail.blocks import RichTextBlock
from wagtail.fields import StreamField
from wagtail.models import Orderable, Page, TranslatableMixin
Expand Down Expand Up @@ -92,7 +92,9 @@ def get_donation_modal_json(self):
content_panels = Page.content_panels + [
FieldPanel("header"),
FieldPanel("cta"),
InlinePanel("donation_modal_relations", label="Donation Modal", max_num=4),
MultipleChooserPanel(
"donation_modal_relations", label="Donation Modal", chooser_field_name="donation_modal", max_num=4
),
FieldPanel("body"),
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from django.utils.text import slugify
from modelcluster.fields import ParentalKey
from modelcluster.models import ClusterableModel
from wagtail.admin.panels import FieldPanel, InlinePanel, MultiFieldPanel
from wagtail.admin.panels import FieldPanel, MultiFieldPanel, MultipleChooserPanel
from wagtail.contrib.settings.models import BaseGenericSetting
from wagtail.models import Orderable, TranslatableMixin
from wagtail.search import index
Expand Down Expand Up @@ -111,10 +111,11 @@ class BuyersGuideProductCategory(
FieldPanel("hidden"),
FieldPanel("share_image"),
FieldPanel("show_cta"),
InlinePanel(
MultipleChooserPanel(
"related_article_relations",
heading="Related articles",
label="Article",
chooser_field_name="article",
max_num=6,
),
]
Expand Down Expand Up @@ -235,7 +236,7 @@ class Meta:
class BuyersGuideCategoryNav(BaseGenericSetting, ClusterableModel):
panels = [
MultiFieldPanel(
[InlinePanel("category_relations")],
[MultipleChooserPanel("category_relations", chooser_field_name="category")],
heading="Categories",
),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.db import models
from modelcluster.fields import ParentalKey
from wagtail import models as wagtail_models
from wagtail.admin.panels import FieldPanel, InlinePanel
from wagtail.admin.panels import FieldPanel, MultipleChooserPanel
from wagtail.contrib.routable_page import models as routable_models
from wagtail.models import Orderable, TranslatableMixin
from wagtail_localize.fields import SynchronizedField, TranslatableField
Expand Down Expand Up @@ -35,10 +35,11 @@ class BuyersGuideEditorialContentIndexPage(
template = "pages/buyersguide/editorial_content_index_page.html"

content_panels = wagtail_models.Page.content_panels + [
InlinePanel(
MultipleChooserPanel(
"related_article_relations",
heading="Popular articles",
label="Article",
chooser_field_name="article",
max_num=3,
),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
from wagtail.admin.panels import (
FieldPanel,
HelpPanel,
InlinePanel,
MultiFieldPanel,
MultipleChooserPanel,
PageChooserPanel,
TitleFieldPanel,
)
Expand Down Expand Up @@ -112,10 +112,11 @@ class BuyersGuidePage(RoutablePageMixin, BasePage):
),
HelpPanel(content="<h2>Supporting Featured Pages</h2>"),
FieldPanel("hero_supporting_pages_heading", heading="Heading"),
InlinePanel(
MultipleChooserPanel(
"hero_supporting_page_relations",
heading="Supporting Pages",
label="Page",
chooser_field_name="supporting_page",
),
],
heading="Hero",
Expand All @@ -124,26 +125,29 @@ class BuyersGuidePage(RoutablePageMixin, BasePage):
"featured_advice_article",
page_type="wagtailpages.BuyersGuideArticlePage",
),
InlinePanel(
MultipleChooserPanel(
"featured_article_relations",
heading="Popular articles",
label="Article",
chooser_field_name="article",
max_num=3,
),
InlinePanel(
MultipleChooserPanel(
"featured_update_relations",
heading="In the press",
label="Press update",
chooser_field_name="update",
max_num=3,
),
MultiFieldPanel(
children=[
FieldPanel("cutoff_date"),
HelpPanel(content="<h2>Excluded categories</h2>"),
InlinePanel(
MultipleChooserPanel(
"excluded_categories",
heading="Excluded categories",
label="Category",
chooser_field_name="category",
min_num=0,
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@
from django.utils.translation import gettext, gettext_lazy
from modelcluster.fields import ParentalKey
from wagtail import hooks
from wagtail.admin.panels import FieldPanel, InlinePanel, MultiFieldPanel
from wagtail.admin.panels import (
FieldPanel,
InlinePanel,
MultiFieldPanel,
MultipleChooserPanel,
)
from wagtail.fields import RichTextField
from wagtail.models import Orderable, Page, PageManager, PageQuerySet, TranslatableMixin
from wagtail.search import index
Expand Down Expand Up @@ -689,7 +694,7 @@ def get_preview_template(self, request, mode_name):
FieldPanel("company"),
MultiFieldPanel(
[
InlinePanel("product_categories", label="Category"),
MultipleChooserPanel("product_categories", label="Category", chooser_field_name="category"),
],
heading="Product Category",
classname="collapsible",
Expand Down Expand Up @@ -753,20 +758,21 @@ def get_preview_template(self, request, mode_name):
classname="collapsible",
),
MultiFieldPanel(
[InlinePanel("updates", label="Update")],
[MultipleChooserPanel("updates", label="Update", chooser_field_name="update")],
heading="News Links",
classname="collapsible",
),
MultiFieldPanel(
[InlinePanel("related_product_pages", label="Product")],
[MultipleChooserPanel("related_product_pages", label="Product", chooser_field_name="related_product")],
heading="Related Products",
),
MultiFieldPanel(
[
InlinePanel(
MultipleChooserPanel(
"related_article_relations",
heading="Related articles",
label="Article",
chooser_field_name="article",
max_num=5,
),
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.db import models
from modelcluster import fields as cluster_fields
from wagtail.admin.panels import InlinePanel, PageChooserPanel
from wagtail.admin.panels import MultipleChooserPanel, PageChooserPanel
from wagtail.models import Orderable, TranslatableMixin
from wagtail_localize.fields import SynchronizedField, TranslatableField

Expand Down Expand Up @@ -62,7 +62,11 @@ class CampaignIndexPage(IndexPage):
template = "wagtailpages/index_page.html"

content_panels = IndexPage.content_panels + [
InlinePanel("featured_campaign_pages", label="Featured Pages"),
MultipleChooserPanel(
"featured_campaign_pages",
label="Featured Pages",
chooser_field_name="featured_page",
),
]

def get_entries(self, context=None):
Expand Down
Loading

0 comments on commit fcb85e5

Please sign in to comment.