climate_ref.models.mixins
#
Model mixins for shared functionality
CreatedUpdatedMixin
#
Mixin for models that have a created_at and updated_at fields
Source code in packages/climate-ref/src/climate_ref/models/mixins.py
DimensionMixin
#
Mixin that adds controlled vocabulary dimension support to a model
This mixin provides methods and properties for managing CV dimensions on database models. Dimensions are stored as individual indexed columns that are registered at runtime based on the controlled vocabulary.
Classes using this mixin must: - Define _cv_dimensions as a ClassVar[list[str]] = [] - Have a tablename attribute (SQLAlchemy requirement)
Source code in packages/climate-ref/src/climate_ref/models/mixins.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | |
dimensions
property
#
Get the non-null dimensions and their values
Any changes to the resulting dictionary are not reflected in the object
Returns:
| Type | Description |
|---|---|
Collection of dimension names and their values
|
|
build_dimension_column(dimension)
staticmethod
#
Create a column representing a CV dimension
These columns are not automatically generated with alembic revisions. Any changes to this functionality likely require a manual database migration of the existing columns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dimension
|
Dimension
|
Dimension definition to create the column for. Currently only the "name" field is being used. |
required |
Returns:
| Type | Description |
|---|---|
An instance of a sqlalchemy Column
|
This doesn't create the column in the database, but enables the ORM to access it. |
Source code in packages/climate-ref/src/climate_ref/models/mixins.py
register_cv_dimensions(cv)
classmethod
#
Register the dimensions supplied in the controlled vocabulary
This has to be done at run-time to support custom CVs. Any extra columns already in the database, but not in the CV are ignored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cv
|
CV
|
Controlled vocabulary being used by the application. This controlled vocabulary contains the definitions of the dimensions that can be used. |
required |