-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add NewsItemViewSet * Add TopicChooserViewSet * Update dependencies * Add StackOverflow link
- Loading branch information
Showing
6 changed files
with
94 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters