mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2025-05-12 22:25:44 -04:00
add BaseHook concept to underlie all Plugin hooks
This commit is contained in:
parent
ed5357cec9
commit
44669fab73
12 changed files with 212 additions and 79 deletions
|
@ -5,6 +5,7 @@ from typing import Optional, List, Literal
|
|||
from pathlib import Path
|
||||
from pydantic import BaseModel, Field, ConfigDict, computed_field
|
||||
|
||||
from .base_hook import BaseHook, HookType
|
||||
|
||||
ConfigSectionName = Literal[
|
||||
'GENERAL_CONFIG',
|
||||
|
@ -20,24 +21,26 @@ ConfigSectionNames: List[ConfigSectionName] = [
|
|||
]
|
||||
|
||||
|
||||
class BaseConfigSet(BaseModel):
|
||||
class BaseConfigSet(BaseHook):
|
||||
model_config = ConfigDict(arbitrary_types_allowed=True, extra='allow', populate_by_name=True)
|
||||
hook_type: HookType = 'CONFIG'
|
||||
|
||||
section: ConfigSectionName = 'GENERAL_CONFIG'
|
||||
|
||||
@computed_field
|
||||
@property
|
||||
def name(self) -> str:
|
||||
return self.__class__.__name__
|
||||
|
||||
def register(self, settings, parent_plugin=None):
|
||||
"""Installs the ConfigSet into Django settings.CONFIGS (and settings.HOOKS)."""
|
||||
if settings is None:
|
||||
from django.conf import settings as django_settings
|
||||
settings = django_settings
|
||||
|
||||
self._plugin = parent_plugin # for debugging only, never rely on this!
|
||||
|
||||
# install hook into settings.CONFIGS
|
||||
settings.CONFIGS[self.name] = self
|
||||
|
||||
# record installed hook in settings.HOOKS
|
||||
super().register(settings, parent_plugin=parent_plugin)
|
||||
|
||||
|
||||
|
||||
# class WgetToggleConfig(ConfigSet):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue