2017-08-24 12:26:55 +02:00
|
|
|
from typing import (
|
|
|
|
TYPE_CHECKING,
|
|
|
|
Any,
|
|
|
|
Dict,
|
|
|
|
Generator,
|
2018-01-20 13:57:25 +01:00
|
|
|
Iterable,
|
2017-08-24 12:26:55 +02:00
|
|
|
List,
|
|
|
|
Optional,
|
|
|
|
Type,
|
2017-09-04 00:25:45 +02:00
|
|
|
cast,
|
2017-08-24 12:26:55 +02:00
|
|
|
)
|
2017-08-23 20:51:06 +02:00
|
|
|
|
2018-07-09 23:22:26 +02:00
|
|
|
from asgiref.sync import async_to_sync
|
2016-09-17 22:26:23 +02:00
|
|
|
from django.apps import apps
|
2018-07-09 23:22:26 +02:00
|
|
|
from django.conf import settings
|
2017-08-24 12:26:55 +02:00
|
|
|
from django.db.models import Model
|
2017-09-04 00:25:45 +02:00
|
|
|
from mypy_extensions import TypedDict
|
2016-12-17 09:30:20 +01:00
|
|
|
|
2018-07-09 23:22:26 +02:00
|
|
|
from .cache import element_cache
|
|
|
|
from .cache_providers import Cachable
|
|
|
|
|
2016-09-17 22:26:23 +02:00
|
|
|
|
2017-08-24 12:26:55 +02:00
|
|
|
if TYPE_CHECKING:
|
2018-08-22 22:00:08 +02:00
|
|
|
from .access_permissions import BaseAccessPermissions
|
2016-09-17 22:26:23 +02:00
|
|
|
|
2017-09-04 00:25:45 +02:00
|
|
|
|
|
|
|
AutoupdateFormat = TypedDict(
|
|
|
|
'AutoupdateFormat',
|
|
|
|
{
|
|
|
|
'collection': str,
|
|
|
|
'id': int,
|
|
|
|
'action': 'str',
|
|
|
|
'data': Dict[str, Any],
|
|
|
|
},
|
|
|
|
total=False,
|
|
|
|
)
|
|
|
|
|
|
|
|
InnerChannelMessageFormat = TypedDict(
|
|
|
|
'InnerChannelMessageFormat',
|
|
|
|
{
|
|
|
|
'collection_string': str,
|
|
|
|
'id': int,
|
|
|
|
'deleted': bool,
|
|
|
|
'information': Dict[str, Any],
|
|
|
|
'full_data': Optional[Dict[str, Any]],
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
ChannelMessageFormat = TypedDict(
|
|
|
|
'ChannelMessageFormat',
|
|
|
|
{
|
|
|
|
'elements': List[InnerChannelMessageFormat],
|
|
|
|
}
|
|
|
|
)
|
2016-09-18 16:00:31 +02:00
|
|
|
|
|
|
|
|
2017-08-24 12:26:55 +02:00
|
|
|
class CollectionElement:
|
2018-08-08 21:09:22 +02:00
|
|
|
def __init__(self, instance: Model = None, deleted: bool = False, collection_string: str = None,
|
|
|
|
id: int = None, full_data: Dict[str, Any] = None, information: Dict[str, Any] = None) -> None:
|
2016-09-17 22:26:23 +02:00
|
|
|
"""
|
|
|
|
Do not use this. Use the methods from_instance() or from_values().
|
|
|
|
"""
|
2016-09-18 16:00:31 +02:00
|
|
|
self.instance = instance
|
|
|
|
self.deleted = deleted
|
|
|
|
self.full_data = full_data
|
2016-09-30 21:43:22 +02:00
|
|
|
self.information = information or {}
|
2016-09-17 22:26:23 +02:00
|
|
|
if instance is not None:
|
2016-12-17 09:30:20 +01:00
|
|
|
# Collection element is created via instance
|
2016-09-17 22:26:23 +02:00
|
|
|
self.collection_string = instance.get_collection_string()
|
2017-08-22 14:17:20 +02:00
|
|
|
self.id = instance.pk
|
2016-09-17 22:26:23 +02:00
|
|
|
elif collection_string is not None and id is not None:
|
2016-12-17 09:30:20 +01:00
|
|
|
# Collection element is created via values
|
2016-09-17 22:26:23 +02:00
|
|
|
self.collection_string = collection_string
|
2017-08-24 12:26:55 +02:00
|
|
|
self.id = id
|
2016-09-17 22:26:23 +02:00
|
|
|
else:
|
|
|
|
raise RuntimeError(
|
|
|
|
'Invalid state. Use CollectionElement.from_instance() or '
|
|
|
|
'CollectionElement.from_values() but not CollectionElement() '
|
|
|
|
'directly.')
|
2016-09-18 16:00:31 +02:00
|
|
|
|
2018-07-09 23:22:26 +02:00
|
|
|
if not self.deleted:
|
|
|
|
self.get_full_data() # This raises DoesNotExist, if the element does not exist.
|
2016-09-17 22:26:23 +02:00
|
|
|
|
2017-08-24 12:26:55 +02:00
|
|
|
@classmethod
|
2018-07-09 23:22:26 +02:00
|
|
|
def from_instance(
|
|
|
|
cls, instance: Model, deleted: bool = False, information: Dict[str, Any] = None) -> 'CollectionElement':
|
2017-08-24 12:26:55 +02:00
|
|
|
"""
|
|
|
|
Returns a collection element from a database instance.
|
|
|
|
|
|
|
|
This will also update the instance in the cache.
|
|
|
|
|
|
|
|
If deleted is set to True, the element is deleted from the cache.
|
|
|
|
"""
|
|
|
|
return cls(instance=instance, deleted=deleted, information=information)
|
|
|
|
|
|
|
|
@classmethod
|
2018-08-08 21:09:22 +02:00
|
|
|
def from_values(cls, collection_string: str, id: int, deleted: bool = False,
|
|
|
|
full_data: Dict[str, Any] = None, information: Dict[str, Any] = None) -> 'CollectionElement':
|
2017-08-24 12:26:55 +02:00
|
|
|
"""
|
|
|
|
Returns a collection element from a collection_string and an id.
|
|
|
|
|
|
|
|
If deleted is set to True, the element is deleted from the cache.
|
|
|
|
|
|
|
|
With the argument full_data, the content of the CollectionElement can be set.
|
|
|
|
It has to be a dict in the format that is used be access_permission.get_full_data().
|
|
|
|
"""
|
|
|
|
return cls(collection_string=collection_string, id=id, deleted=deleted,
|
|
|
|
full_data=full_data, information=information)
|
|
|
|
|
|
|
|
def __eq__(self, collection_element: 'CollectionElement') -> bool: # type: ignore
|
2016-09-30 21:43:22 +02:00
|
|
|
"""
|
|
|
|
Compares two collection_elements.
|
|
|
|
|
|
|
|
Two collection elements are equal, if they have the same collection_string
|
|
|
|
and id.
|
|
|
|
"""
|
|
|
|
return (self.collection_string == collection_element.collection_string and
|
|
|
|
self.id == collection_element.id)
|
|
|
|
|
2017-09-04 00:25:45 +02:00
|
|
|
def as_autoupdate_for_user(self, user: Optional['CollectionElement']) -> AutoupdateFormat:
|
2016-09-17 22:26:23 +02:00
|
|
|
"""
|
2017-09-04 00:25:45 +02:00
|
|
|
Returns a dict that can be sent through the autoupdate system for a site
|
|
|
|
user.
|
2016-09-17 22:26:23 +02:00
|
|
|
"""
|
|
|
|
if not self.is_deleted():
|
2017-09-04 00:25:45 +02:00
|
|
|
restricted_data = self.get_access_permissions().get_restricted_data([self.get_full_data()], user)
|
|
|
|
data = restricted_data[0] if restricted_data else None
|
2017-04-28 00:50:37 +02:00
|
|
|
else:
|
|
|
|
data = None
|
|
|
|
|
|
|
|
return format_for_autoupdate(
|
|
|
|
collection_string=self.collection_string,
|
|
|
|
id=self.id,
|
|
|
|
action='deleted' if self.is_deleted() else 'changed',
|
|
|
|
data=data)
|
2016-09-17 22:26:23 +02:00
|
|
|
|
2017-09-04 00:25:45 +02:00
|
|
|
def as_autoupdate_for_projector(self) -> AutoupdateFormat:
|
2016-09-17 22:26:23 +02:00
|
|
|
"""
|
|
|
|
Returns a dict that can be sent through the autoupdate system for the
|
|
|
|
projector.
|
2016-09-18 16:00:31 +02:00
|
|
|
"""
|
2017-09-04 00:25:45 +02:00
|
|
|
if not self.is_deleted():
|
|
|
|
restricted_data = self.get_access_permissions().get_projector_data([self.get_full_data()])
|
|
|
|
data = restricted_data[0] if restricted_data else None
|
|
|
|
else:
|
|
|
|
data = None
|
|
|
|
|
|
|
|
return format_for_autoupdate(
|
|
|
|
collection_string=self.collection_string,
|
|
|
|
id=self.id,
|
|
|
|
action='deleted' if self.is_deleted() else 'changed',
|
|
|
|
data=data)
|
2016-09-17 22:26:23 +02:00
|
|
|
|
2017-09-04 00:25:45 +02:00
|
|
|
def as_dict_for_user(self, user: Optional['CollectionElement']) -> Optional[Dict[str, Any]]:
|
2016-09-17 22:26:23 +02:00
|
|
|
"""
|
2016-09-18 16:00:31 +02:00
|
|
|
Returns a dict with the data for a user. Can be used for the rest api.
|
2017-09-04 00:25:45 +02:00
|
|
|
|
|
|
|
Returns None if the user does not has the permission to see the element.
|
2016-09-18 16:00:31 +02:00
|
|
|
"""
|
2017-09-04 00:25:45 +02:00
|
|
|
restricted_data = self.get_access_permissions().get_restricted_data([self.get_full_data()], user)
|
|
|
|
return restricted_data[0] if restricted_data else None
|
2016-09-17 22:26:23 +02:00
|
|
|
|
2017-08-24 12:26:55 +02:00
|
|
|
def get_model(self) -> Type[Model]:
|
2016-09-17 22:26:23 +02:00
|
|
|
"""
|
|
|
|
Returns the django model that is used for this collection.
|
|
|
|
"""
|
|
|
|
return get_model_from_collection_string(self.collection_string)
|
|
|
|
|
2017-08-24 12:26:55 +02:00
|
|
|
def get_access_permissions(self) -> 'BaseAccessPermissions':
|
2016-09-17 22:26:23 +02:00
|
|
|
"""
|
|
|
|
Returns the get_access_permissions object for the this collection element.
|
|
|
|
"""
|
|
|
|
return self.get_model().get_access_permissions()
|
|
|
|
|
2018-07-09 23:22:26 +02:00
|
|
|
def get_element_from_db(self) -> Optional[Dict[str, Any]]:
|
|
|
|
# Hack for django 2.0 and channels 2.1 to stay in the same thread.
|
|
|
|
# This is needed for the tests.
|
|
|
|
try:
|
|
|
|
query = self.get_model().objects.get_full_queryset()
|
|
|
|
except AttributeError:
|
|
|
|
# If the model des not have to method get_full_queryset(), then use
|
|
|
|
# the default queryset from django.
|
|
|
|
query = self.get_model().objects
|
|
|
|
try:
|
|
|
|
return self.get_access_permissions().get_full_data(query.get(pk=self.id))
|
|
|
|
except self.get_model().DoesNotExist:
|
|
|
|
return None
|
|
|
|
|
2017-09-04 00:25:45 +02:00
|
|
|
def get_full_data(self) -> Dict[str, Any]:
|
2016-09-17 22:26:23 +02:00
|
|
|
"""
|
|
|
|
Returns the full_data of this collection_element from with all other
|
|
|
|
dics can be generated.
|
2017-02-12 14:09:53 +01:00
|
|
|
|
|
|
|
Raises a DoesNotExist error on the requested the coresponding model, if
|
|
|
|
the object does neither exist in the cache nor in the database.
|
2016-09-17 22:26:23 +02:00
|
|
|
"""
|
2016-09-18 16:00:31 +02:00
|
|
|
# If the full_data is already loaded, return it
|
|
|
|
# If there is a db_instance, use it to get the full_data
|
2017-09-04 00:25:45 +02:00
|
|
|
# else: use the cache.
|
2016-09-18 16:00:31 +02:00
|
|
|
if self.full_data is None:
|
2017-09-04 00:25:45 +02:00
|
|
|
if self.instance is None:
|
2018-07-09 23:22:26 +02:00
|
|
|
# The type of data has to be set for mypy
|
2018-08-22 22:00:08 +02:00
|
|
|
data: Optional[Dict[str, Any]] = None
|
2018-07-09 23:22:26 +02:00
|
|
|
if getattr(settings, 'SKIP_CACHE', False):
|
|
|
|
# Hack for django 2.0 and channels 2.1 to stay in the same thread.
|
|
|
|
# This is needed for the tests.
|
|
|
|
data = self.get_element_from_db()
|
|
|
|
else:
|
|
|
|
data = async_to_sync(element_cache.get_element_full_data)(self.collection_string, self.id)
|
|
|
|
if data is None:
|
|
|
|
raise self.get_model().DoesNotExist(
|
|
|
|
"Collection {} with id {} does not exist".format(self.collection_string, self.id))
|
|
|
|
self.full_data = data
|
2017-09-04 00:25:45 +02:00
|
|
|
else:
|
|
|
|
self.full_data = self.get_access_permissions().get_full_data(self.instance)
|
2016-09-18 16:00:31 +02:00
|
|
|
return self.full_data
|
2016-09-17 22:26:23 +02:00
|
|
|
|
2017-08-24 12:26:55 +02:00
|
|
|
def is_deleted(self) -> bool:
|
2016-09-17 22:26:23 +02:00
|
|
|
"""
|
|
|
|
Returns Ture if the item is marked as deleted.
|
|
|
|
"""
|
|
|
|
return self.deleted
|
|
|
|
|
2016-10-01 15:26:00 +02:00
|
|
|
|
2018-07-09 23:22:26 +02:00
|
|
|
class Collection(Cachable):
|
2016-09-18 16:00:31 +02:00
|
|
|
"""
|
|
|
|
Represents all elements of one collection.
|
|
|
|
"""
|
|
|
|
|
2018-08-08 21:09:22 +02:00
|
|
|
def __init__(self, collection_string: str, full_data: List[Dict[str, Any]] = None) -> None:
|
2017-05-01 23:12:42 +02:00
|
|
|
"""
|
|
|
|
Initiates a Collection. A collection_string has to be given. If
|
|
|
|
full_data (a list of dictionaries) is not given the method
|
|
|
|
get_full_data() exposes all data by iterating over all
|
|
|
|
CollectionElements.
|
|
|
|
"""
|
2016-09-18 16:00:31 +02:00
|
|
|
self.collection_string = collection_string
|
2017-05-01 23:12:42 +02:00
|
|
|
self.full_data = full_data
|
2016-09-18 16:00:31 +02:00
|
|
|
|
2017-08-24 12:26:55 +02:00
|
|
|
def get_model(self) -> Type[Model]:
|
2016-09-18 16:00:31 +02:00
|
|
|
"""
|
|
|
|
Returns the django model that is used for this collection.
|
|
|
|
"""
|
|
|
|
return get_model_from_collection_string(self.collection_string)
|
|
|
|
|
2017-08-24 12:26:55 +02:00
|
|
|
def get_access_permissions(self) -> 'BaseAccessPermissions':
|
2017-05-01 23:12:42 +02:00
|
|
|
"""
|
|
|
|
Returns the get_access_permissions object for the this collection.
|
|
|
|
"""
|
|
|
|
return self.get_model().get_access_permissions()
|
|
|
|
|
2017-08-24 12:26:55 +02:00
|
|
|
def element_generator(self) -> Generator[CollectionElement, None, None]:
|
2016-09-18 16:00:31 +02:00
|
|
|
"""
|
|
|
|
Generator that yields all collection_elements of this collection.
|
|
|
|
"""
|
2017-09-04 00:25:45 +02:00
|
|
|
for full_data in self.get_full_data():
|
2016-09-18 16:00:31 +02:00
|
|
|
yield CollectionElement.from_values(
|
2017-09-04 00:25:45 +02:00
|
|
|
self.collection_string,
|
|
|
|
full_data['id'],
|
|
|
|
full_data=full_data)
|
2016-09-18 16:00:31 +02:00
|
|
|
|
2018-07-09 23:22:26 +02:00
|
|
|
def get_elements_from_db(self) ->Dict[str, List[Dict[str, Any]]]:
|
|
|
|
# Hack for django 2.0 and channels 2.1 to stay in the same thread.
|
|
|
|
# This is needed for the tests.
|
|
|
|
try:
|
|
|
|
query = self.get_model().objects.get_full_queryset()
|
|
|
|
except AttributeError:
|
|
|
|
# If the model des not have to method get_full_queryset(), then use
|
|
|
|
# the default queryset from django.
|
|
|
|
query = self.get_model().objects
|
|
|
|
return {self.collection_string: [self.get_model().get_access_permissions().get_full_data(instance) for instance in query.all()]}
|
|
|
|
|
2017-08-24 12:26:55 +02:00
|
|
|
def get_full_data(self) -> List[Dict[str, Any]]:
|
2017-05-01 23:12:42 +02:00
|
|
|
"""
|
|
|
|
Returns a list of dictionaries with full_data of all collection
|
|
|
|
elements.
|
|
|
|
"""
|
|
|
|
if self.full_data is None:
|
2018-07-09 23:22:26 +02:00
|
|
|
# The type of all_full_data has to be set for mypy
|
2018-08-22 22:00:08 +02:00
|
|
|
all_full_data: Dict[str, List[Dict[str, Any]]] = {}
|
2018-07-09 23:22:26 +02:00
|
|
|
if getattr(settings, 'SKIP_CACHE', False):
|
|
|
|
# Hack for django 2.0 and channels 2.1 to stay in the same thread.
|
|
|
|
# This is needed for the tests.
|
|
|
|
all_full_data = self.get_elements_from_db()
|
|
|
|
else:
|
|
|
|
all_full_data = async_to_sync(element_cache.get_all_full_data)()
|
|
|
|
self.full_data = all_full_data[self.collection_string]
|
2017-09-04 00:25:45 +02:00
|
|
|
return self.full_data
|
2017-01-14 12:29:42 +01:00
|
|
|
|
2017-09-04 00:25:45 +02:00
|
|
|
def as_list_for_user(self, user: Optional[CollectionElement]) -> List[Dict[str, Any]]:
|
2016-09-18 16:00:31 +02:00
|
|
|
"""
|
|
|
|
Returns a list of dictonaries to send them to a user, for example over
|
|
|
|
the rest api.
|
|
|
|
"""
|
2017-09-04 00:25:45 +02:00
|
|
|
return self.get_access_permissions().get_restricted_data(self.get_full_data(), user)
|
2016-09-18 16:00:31 +02:00
|
|
|
|
2018-07-09 23:22:26 +02:00
|
|
|
def get_collection_string(self) -> str:
|
|
|
|
"""
|
|
|
|
Returns the collection_string.
|
|
|
|
"""
|
|
|
|
return self.collection_string
|
|
|
|
|
|
|
|
def get_elements(self) -> List[Dict[str, Any]]:
|
|
|
|
"""
|
|
|
|
Returns all elements of the Collection as full_data.
|
|
|
|
"""
|
|
|
|
return self.get_full_data()
|
|
|
|
|
|
|
|
def restrict_elements(
|
|
|
|
self,
|
|
|
|
user: Optional['CollectionElement'],
|
|
|
|
elements: List[Dict[str, Any]]) -> List[Dict[str, Any]]:
|
|
|
|
"""
|
|
|
|
Converts the full_data to restricted data.
|
|
|
|
"""
|
|
|
|
return self.get_model().get_access_permissions().get_restricted_data(user, elements)
|
|
|
|
|
2016-09-17 22:26:23 +02:00
|
|
|
|
2018-08-22 22:00:08 +02:00
|
|
|
_models_to_collection_string: Dict[str, Type[Model]] = {}
|
2017-04-25 14:56:49 +02:00
|
|
|
|
|
|
|
|
2017-08-24 12:26:55 +02:00
|
|
|
def get_model_from_collection_string(collection_string: str) -> Type[Model]:
|
2016-09-17 22:26:23 +02:00
|
|
|
"""
|
|
|
|
Returns a model class which belongs to the argument collection_string.
|
|
|
|
"""
|
2017-08-24 12:26:55 +02:00
|
|
|
def model_generator() -> Generator[Type[Model], None, None]:
|
2016-09-17 22:26:23 +02:00
|
|
|
"""
|
|
|
|
Yields all models of all apps.
|
|
|
|
"""
|
|
|
|
for app_config in apps.get_app_configs():
|
|
|
|
for model in app_config.get_models():
|
|
|
|
yield model
|
|
|
|
|
2017-04-25 14:56:49 +02:00
|
|
|
# On the first run, generate the dict. It can not change at runtime.
|
|
|
|
if not _models_to_collection_string:
|
|
|
|
for model in model_generator():
|
|
|
|
try:
|
|
|
|
get_collection_string = model.get_collection_string
|
|
|
|
except AttributeError:
|
|
|
|
# Skip models which do not have the method get_collection_string.
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
_models_to_collection_string[get_collection_string()] = model
|
2017-04-27 15:16:07 +02:00
|
|
|
try:
|
|
|
|
model = _models_to_collection_string[collection_string]
|
|
|
|
except KeyError:
|
|
|
|
raise ValueError('Invalid message. A valid collection_string is missing.')
|
|
|
|
return model
|
2016-09-18 16:00:31 +02:00
|
|
|
|
|
|
|
|
2018-07-09 23:22:26 +02:00
|
|
|
def format_for_autoupdate(
|
|
|
|
collection_string: str, id: int, action: str, data: Dict[str, Any] = None) -> AutoupdateFormat:
|
2016-09-18 16:00:31 +02:00
|
|
|
"""
|
2017-09-04 00:25:45 +02:00
|
|
|
Returns a dict that can be used for autoupdate.
|
2016-09-18 16:00:31 +02:00
|
|
|
"""
|
2017-09-04 00:25:45 +02:00
|
|
|
if data is None:
|
|
|
|
# If the data is None then the action has to be deleted,
|
|
|
|
# even when it says diffrently. This can happen when the object is not
|
|
|
|
# deleted, but the user has no permission to see it.
|
|
|
|
action = 'deleted'
|
2016-09-18 16:00:31 +02:00
|
|
|
|
2017-09-04 00:25:45 +02:00
|
|
|
output = AutoupdateFormat(
|
|
|
|
collection=collection_string,
|
|
|
|
id=id,
|
|
|
|
action=action,
|
|
|
|
)
|
2016-09-18 16:00:31 +02:00
|
|
|
|
2017-09-04 00:25:45 +02:00
|
|
|
if action != 'deleted':
|
|
|
|
data = cast(Dict[str, Any], data) # In this case data can not be None
|
|
|
|
output['data'] = data
|
|
|
|
|
|
|
|
return output
|
2016-09-18 16:00:31 +02:00
|
|
|
|
|
|
|
|
2018-01-20 13:57:25 +01:00
|
|
|
def to_channel_message(elements: Iterable[CollectionElement]) -> ChannelMessageFormat:
|
2016-09-18 16:00:31 +02:00
|
|
|
"""
|
2017-09-04 00:25:45 +02:00
|
|
|
Converts a list of collection elements to a dict, that can be send to the
|
|
|
|
channels system.
|
2016-09-18 16:00:31 +02:00
|
|
|
"""
|
2017-09-04 00:25:45 +02:00
|
|
|
output = []
|
|
|
|
for element in elements:
|
|
|
|
output.append(InnerChannelMessageFormat(
|
|
|
|
collection_string=element.collection_string,
|
|
|
|
id=element.id,
|
|
|
|
deleted=element.is_deleted(),
|
|
|
|
information=element.information,
|
|
|
|
full_data=element.full_data,
|
|
|
|
))
|
|
|
|
return ChannelMessageFormat(elements=output)
|
|
|
|
|
|
|
|
|
|
|
|
def from_channel_message(message: ChannelMessageFormat) -> List[CollectionElement]:
|
2016-09-18 16:00:31 +02:00
|
|
|
"""
|
2017-09-04 00:25:45 +02:00
|
|
|
Converts a list of collection elements back from a dict, that was created
|
|
|
|
via to_channel_message.
|
2016-09-18 16:00:31 +02:00
|
|
|
"""
|
2017-09-04 00:25:45 +02:00
|
|
|
elements = []
|
|
|
|
for value in message['elements']:
|
|
|
|
elements.append(CollectionElement.from_values(**value))
|
|
|
|
return elements
|