mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2025-05-21 10:25:11 -04:00
cleanup plugantic and pkg apps, make BaseHook actually create its own settings
This commit is contained in:
parent
0e79a8b683
commit
b56b1cac35
29 changed files with 272 additions and 466 deletions
|
@ -1,13 +1,14 @@
|
|||
from typing import List, Type, Any, Dict
|
||||
__package__ = 'archivebox.plugantic'
|
||||
|
||||
from pydantic_core import core_schema
|
||||
from pydantic import GetCoreSchemaHandler, BaseModel
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.functional import classproperty
|
||||
from django.core.checks import Warning, Tags, register
|
||||
from .base_hook import BaseHook, HookType
|
||||
from ..config_stubs import AttrDict
|
||||
|
||||
class BaseAdminDataView(BaseModel):
|
||||
name: str = 'NPM Installed Packages'
|
||||
class BaseAdminDataView(BaseHook):
|
||||
hook_type: HookType = "ADMINDATAVIEW"
|
||||
|
||||
verbose_name: str = 'NPM Installed Packages'
|
||||
route: str = '/npm/installed/'
|
||||
view: str = 'builtin_plugins.npm.admin.installed_list_view'
|
||||
items: Dict[str, str] = {
|
||||
|
@ -16,19 +17,22 @@ class BaseAdminDataView(BaseModel):
|
|||
'view': 'builtin_plugins.npm.admin.installed_detail_view',
|
||||
}
|
||||
|
||||
def as_route(self) -> Dict[str, str | Dict[str, str]]:
|
||||
return {
|
||||
'route': self.route,
|
||||
'view': self.view,
|
||||
'name': self.name,
|
||||
'items': self.items,
|
||||
}
|
||||
|
||||
def register(self, settings, parent_plugin=None):
|
||||
"""Regsiter AdminDataViews.as_route() in settings.ADMIN_DATA_VIEWS.URLS at runtime"""
|
||||
self._plugin = parent_plugin # circular ref to parent only here for easier debugging! never depend on circular backref to parent in real code!
|
||||
# self._plugin = parent_plugin # circular ref to parent only here for easier debugging! never depend on circular backref to parent in real code!
|
||||
|
||||
route = self.as_route()
|
||||
self.register_route_in_admin_data_view_urls(settings)
|
||||
|
||||
settings.ADMINDATAVIEWS = getattr(settings, "ADMINDATAVIEWS", None) or AttrDict({})
|
||||
settings.ADMINDATAVIEWS[self.id] = self
|
||||
|
||||
super().register(settings, parent_plugin)
|
||||
|
||||
def register_route_in_admin_data_view_urls(self, settings):
|
||||
route = {
|
||||
"route": self.route,
|
||||
"view": self.view,
|
||||
"name": self.verbose_name,
|
||||
"items": self.items,
|
||||
}
|
||||
if route not in settings.ADMIN_DATA_VIEWS.URLS:
|
||||
settings.ADMIN_DATA_VIEWS.URLS += [route] # append our route (update in place)
|
||||
|
||||
settings.ADMIN_DATA_VIEWS.URLS += [route] # append our route (update in place)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue