-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: DbCollection(TableData, TableColumns, DbConnection)
- Loading branch information
1 parent
42e547f
commit 48a1b24
Showing
18 changed files
with
756 additions
and
506 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
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
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
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,24 @@ | ||
from __future__ import annotations | ||
|
||
from ckanext.collection import types | ||
from ckanext.collection.utils.data import StaticData | ||
|
||
from .api import ApiCollection, ApiListCollection, ApiSearchCollection | ||
from .base import Collection | ||
from .db import DbCollection | ||
from .explorer import CollectionExplorerCollection | ||
from .model import ModelCollection | ||
|
||
__all__ = [ | ||
"Collection", | ||
"DbCollection", | ||
"ApiCollection", | ||
"ApiSearchCollection", | ||
"ApiListCollection", | ||
"ModelCollection", | ||
"CollectionExplorerCollection", | ||
] | ||
|
||
|
||
class StaticCollection(Collection[types.TData]): | ||
DataFactory = StaticData |
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,18 @@ | ||
from __future__ import annotations | ||
|
||
from ckanext.collection import types | ||
from ckanext.collection.utils.data import ApiData, ApiListData, ApiSearchData | ||
|
||
from .base import Collection | ||
|
||
|
||
class ApiCollection(Collection[types.TData]): | ||
DataFactory = ApiData | ||
|
||
|
||
class ApiSearchCollection(ApiCollection[types.TData]): | ||
DataFactory = ApiSearchData | ||
|
||
|
||
class ApiListCollection(ApiCollection[types.TData]): | ||
DataFactory = ApiListData |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Any | ||
|
||
from typing_extensions import Self | ||
|
||
from ckanext.collection import types | ||
from ckanext.collection.utils.columns import TableColunns | ||
from ckanext.collection.utils.data import TableData | ||
from ckanext.collection.utils.db_connection import DbConnection | ||
|
||
from .base import Collection | ||
|
||
|
||
class DbCollection(Collection[types.TData], types.BaseDbCollection[types.TData]): | ||
_service_names: tuple[str, ...] = ("db_connection",) + Collection._service_names | ||
DbConnectionFactory: type[DbConnection[Self]] = DbConnection | ||
DataFactory = TableData | ||
ColumnsFactory = TableColunns | ||
|
||
def make_db_connection(self, **kwargs: Any) -> DbConnection[Self]: | ||
"""Return connection.""" | ||
return self.DbConnectionFactory(self, **kwargs) |
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,41 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Iterable | ||
|
||
from ckan.authz import is_authorized_boolean | ||
|
||
from ckanext.collection import shared | ||
from ckanext.collection.utils.data import Data | ||
from ckanext.collection.utils.serialize import HtmlSerializer | ||
|
||
from .base import Collection | ||
|
||
|
||
class CollectionExplorerCollection(Collection[str]): | ||
"""Collection of all registered collections. | ||
It exists for debugging and serves as an example of non-canonical usage of | ||
collections. | ||
""" | ||
|
||
class DataFactory(Data[str, "CollectionExplorerCollection"], shared.UserTrait): | ||
static_names = shared.configurable_attribute( | ||
default_factory=lambda self: map(str, shared.collection_registry.members), | ||
) | ||
|
||
def compute_data(self) -> Iterable[str]: | ||
return [ | ||
name | ||
for name in self.static_names | ||
if name != self.attached.name | ||
and is_authorized_boolean( | ||
"collection_view_render", | ||
{"user": self.user}, | ||
{"name": name}, | ||
) | ||
] | ||
|
||
class SerializerFactory(HtmlSerializer["CollectionExplorerCollection"]): | ||
main_template: str = shared.configurable_attribute( | ||
"collection/serialize/collection_explorer/main.html", | ||
) |
Oops, something went wrong.