Skip to content

Commit

Permalink
update: use signal to gather config sections
Browse files Browse the repository at this point in the history
  • Loading branch information
mutantsan committed Feb 12, 2024
1 parent 92fe621 commit 0933676
Showing 1 changed file with 30 additions and 30 deletions.
60 changes: 30 additions & 30 deletions ckanext/tour/plugin.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from __future__ import annotations

from typing import Literal

import ckan.types as types
import ckan.plugins as plugins
import ckan.plugins.toolkit as tk

from ckanext.collection.interfaces import ICollection, CollectionFactory

from ckanext.ap_main.interfaces import IAdminPanel
from ckanext.ap_main.types import ConfigurationItem, SectionConfig

from ckanext.tour.collection import TourListCollection
Expand All @@ -18,8 +20,8 @@
@tk.blanket.validators
class TourPlugin(plugins.SingletonPlugin):
plugins.implements(plugins.IConfigurer)
plugins.implements(IAdminPanel, inherit=True)
plugins.implements(ICollection, inherit=True)
plugins.implements(plugins.ISignal)

# IConfigurer

Expand All @@ -28,36 +30,34 @@ def update_config(self, config_):
tk.add_public_directory(config_, "public")
tk.add_resource("assets", "tour")

# IAdminPanel

def register_config_sections(
self, config_list: list[SectionConfig]
) -> list[SectionConfig]:
config_list.append(
SectionConfig(
name="Tour",
configs=[
# ConfigurationItem(
# name="Global settings",
# blueprint="tour.config",
# info="Global configuration for a tour",
# ),
ConfigurationItem(
name="List of tours",
blueprint="tour.list",
info="Manage existing tours",
),
ConfigurationItem(
name="Add tour",
blueprint="tour.add",
info="Add new tour",
),
],
)
)
return config_list
# ISignal

def get_signal_subscriptions(self) -> types.SignalMapping:
return {
tk.signals.ckanext.signal("ap_main:collect_config_sections"): [
collect_config_sections_subs
],
}

# ICollection

def get_collection_factories(self) -> dict[str, CollectionFactory]:
return {"tour-list": TourListCollection}


def collect_config_sections_subs(sender: None):
return SectionConfig(
name="Tour",
configs=[
ConfigurationItem(
name="List of tours",
blueprint="tour.list",
info="Manage existing tours",
),
ConfigurationItem(
name="Add tour",
blueprint="tour.add",
info="Add new tour",
),
],
)

0 comments on commit 0933676

Please sign in to comment.