def _encode_entity(self, encoded: Dict, entity: Entity) -> None: self._encode_schema( encoded, upper_camel_case_to_lower_camel_case( get_entity_type_name(entity.entity_type()))) if 'links' not in encoded: encoded['links'] = [] if not isinstance(entity.id, GeneratedEntityId): encoded['id'] = entity.id canonical = Link(self._generate_url(entity)) canonical.relationship = 'canonical' canonical.media_type = 'application/json' encoded['links'].append(canonical) for locale_configuration in self._app.configuration.locales: if locale_configuration.locale == self._locale: continue translation = Link( self._generate_url(entity, locale=locale_configuration.locale)) translation.relationship = 'alternate' translation.locale = locale_configuration.locale encoded['links'].append(translation) html = Link(self._generate_url(entity, media_type='text/html')) html.relationship = 'alternate' html.media_type = 'text/html' encoded['links'].append(html)
def _load_objref(loader: _Loader, owner: Entity, element: ElementTree.Element): file_handles = _load_handles('objref', element) for file_handle in file_handles: loader.add_association(owner.entity_type(), owner.id, 'files', File, file_handle)
def _load_citationref(loader: _Loader, owner: Entity, element: ElementTree.Element): for citation_handle in _load_handles('citationref', element): loader.add_association(owner.entity_type(), owner.id, 'citations', Citation, citation_handle)
def add_entity(self, entity: Entity) -> None: self._flattened_entities.add_entity(entity) self._added_entity_counts[entity.entity_type()] += 1
def test_entity_type_with_class(self) -> None: self.assertEqual(Entity, Entity.entity_type())