mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2025-05-14 23:24:30 -04:00
BasePlugin system expanded and registration system improved
This commit is contained in:
parent
f1579bfdcd
commit
9af260df16
50 changed files with 1062 additions and 973 deletions
34
archivebox/plugantic/base_admindataview.py
Normal file
34
archivebox/plugantic/base_admindataview.py
Normal file
|
@ -0,0 +1,34 @@
|
|||
from typing import List, Type, Any, Dict
|
||||
|
||||
from pydantic_core import core_schema
|
||||
from pydantic import GetCoreSchemaHandler, BaseModel
|
||||
|
||||
from django.utils.functional import classproperty
|
||||
from django.core.checks import Warning, Tags, register
|
||||
|
||||
class BaseAdminDataView(BaseModel):
|
||||
name: str = 'NPM Installed Packages'
|
||||
route: str = '/npm/installed/'
|
||||
view: str = 'builtin_plugins.npm.admin.installed_list_view'
|
||||
items: Dict[str, str] = {
|
||||
"name": "installed_npm_pkg",
|
||||
'route': '<str:key>/',
|
||||
'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!
|
||||
|
||||
route = self.as_route()
|
||||
if route not in settings.ADMIN_DATA_VIEWS.URLS:
|
||||
settings.ADMIN_DATA_VIEWS.URLS += [route] # append our route (update in place)
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue