Skip to content

Commit

Permalink
News generic listing (#1064)
Browse files Browse the repository at this point in the history
* Add NewsItemViewSet

* Add TopicChooserViewSet

* Update dependencies

* Add StackOverflow link
  • Loading branch information
brylie committed May 21, 2024
1 parent bcd3fc7 commit 657b1f7
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 46 deletions.
19 changes: 19 additions & 0 deletions facets/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from wagtail.admin.viewsets.chooser import ChooserViewSet

from .models import Topic


class TopicChooserViewSet(ChooserViewSet):
icon = "tag"
model = Topic
choose_one_text = "Choose a topic"
choose_another_text = "Choose another topic"
# TODO: determine how to enable editing/creation of topics
# which is made difficult since they are pages,
# so need to be placed into the Wagtail page tree
# https://stackoverflow.com/questions/78513604/automatically-specify-parent-page-when-creating-new-page-instances-via-chooservi
# edit_item_text = "Edit topic"
# form_fields = ["title"]


topic_chooser_viewset = TopicChooserViewSet("topic_chooser")
8 changes: 8 additions & 0 deletions facets/wagtail_hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from wagtail import hooks

from .views import topic_chooser_viewset


@hooks.register("register_admin_viewset")
def register_topic_chooser_viewset():
return topic_chooser_viewset
49 changes: 48 additions & 1 deletion news/views.py
Original file line number Diff line number Diff line change
@@ -1 +1,48 @@
# Create your views here.
from wagtail.admin.viewsets.pages import PageListingViewSet
from wagtail.admin.ui.tables import DateColumn
from wagtail.admin.ui.tables.pages import (
BulkActionsColumn,
PageTitleColumn,
PageStatusColumn,
)
from .models import NewsItem


class NewsItemFilterSet(PageListingViewSet.filterset_class):
class Meta:
model = NewsItem
fields = [
"topics",
]


class NewsItemViewSet(PageListingViewSet):
model = NewsItem
menu_label = "News Items"
icon = "list-ul"
add_to_admin_menu = True
columns = [
PageTitleColumn(
"title",
label="Title",
sort_key="title",
),
DateColumn(
"publication_date",
label="Publication Date",
sort_key="publication_date",
),
PageStatusColumn(
"live",
label="Live",
sort_key="live",
),
BulkActionsColumn(
"bulk_actions",
label="Bulk Actions",
),
]
filterset_class = NewsItemFilterSet


news_item_viewset = NewsItemViewSet("news_items")
36 changes: 5 additions & 31 deletions news/wagtail_hooks.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,7 @@
from wagtail_modeladmin.options import (
ModelAdmin,
ModelAdminGroup,
modeladmin_register,
)
from wagtail import hooks
from .views import news_item_viewset

from .models import NewsItem


class NewsItemModelAdmin(ModelAdmin):
model = NewsItem
menu_icon = "list-ul"
menu_label = "Items"
menu_order = 100
add_to_settings_menu = False
exclude_from_explorer = False
list_per_page = 10
list_display = (
"title",
"publication_date",
)
search_fields = ("title",)
list_filter = ("publication_date",)


class NewsAdminGroup(ModelAdminGroup):
menu_label = "News"
menu_icon = "comment"
menu_order = 300
items = (NewsItemModelAdmin,)


modeladmin_register(NewsAdminGroup)
@hooks.register("register_admin_viewset")
def register_news_item_viewset():
return news_item_viewset
16 changes: 8 additions & 8 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# pip-compile --extra=dev --output-file=requirements-dev.txt pyproject.toml
#
annotated-types==0.6.0
annotated-types==0.7.0
# via pydantic
anyascii==0.3.2
# via wagtail
Expand All @@ -15,9 +15,9 @@ asgiref==3.8.1
# django-stubs
beautifulsoup4==4.12.3
# via wagtail
boto3==1.34.105
boto3==1.34.109
# via Western-Friend-website (pyproject.toml)
botocore==1.34.105
botocore==1.34.109
# via
# boto3
# s3transfer
Expand Down Expand Up @@ -195,13 +195,13 @@ pytz==2024.1
# l18n
pyyaml==6.0.1
# via pre-commit
requests==2.31.0
requests==2.32.1
# via
# Western-Friend-website (pyproject.toml)
# wagtail
s3transfer==0.10.1
# via boto3
sentry-sdk==2.1.1
sentry-sdk==2.2.1
# via Western-Friend-website (pyproject.toml)
six==1.16.0
# via
Expand All @@ -221,7 +221,7 @@ types-html5lib==1.1.11.20240228
# via types-beautifulsoup4
types-pyyaml==6.0.12.20240311
# via django-stubs
types-requests==2.31.0.20240406
types-requests==2.32.0.20240521
# via Western-Friend-website (pyproject.toml)
typing-extensions==4.11.0
# via
Expand All @@ -241,11 +241,11 @@ urllib3==2.2.1
# requests
# sentry-sdk
# types-requests
validate-pyproject==0.17
validate-pyproject==0.18
# via Western-Friend-website (pyproject.toml)
virtualenv==20.26.2
# via pre-commit
wagtail==6.1
wagtail==6.1.1
# via
# Western-Friend-website (pyproject.toml)
# wagtail-color-panel
Expand Down
12 changes: 6 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
#
# pip-compile --output-file=requirements.txt pyproject.toml
#
annotated-types==0.6.0
annotated-types==0.7.0
# via pydantic
anyascii==0.3.2
# via wagtail
asgiref==3.8.1
# via django
beautifulsoup4==4.12.3
# via wagtail
boto3==1.34.105
boto3==1.34.109
# via Western-Friend-website (pyproject.toml)
botocore==1.34.105
botocore==1.34.109
# via
# boto3
# s3transfer
Expand Down Expand Up @@ -136,13 +136,13 @@ pytz==2024.1
# via
# django-modelcluster
# l18n
requests==2.31.0
requests==2.32.1
# via
# Western-Friend-website (pyproject.toml)
# wagtail
s3transfer==0.10.1
# via boto3
sentry-sdk==2.1.1
sentry-sdk==2.2.1
# via Western-Friend-website (pyproject.toml)
six==1.16.0
# via
Expand All @@ -167,7 +167,7 @@ urllib3==2.2.1
# botocore
# requests
# sentry-sdk
wagtail==6.1
wagtail==6.1.1
# via
# Western-Friend-website (pyproject.toml)
# wagtail-color-panel
Expand Down

0 comments on commit 657b1f7

Please sign in to comment.