From e6c9a11f4a20e37065ab0cb944567e40cece1aa0 Mon Sep 17 00:00:00 2001 From: Ben Armstrong Date: Sun, 12 Jan 2025 10:51:29 -0400 Subject: [PATCH] Initial version of taxon menu. --- dronefly/core/menus/__init__.py | 1 + dronefly/core/menus/taxon.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 dronefly/core/menus/taxon.py diff --git a/dronefly/core/menus/__init__.py b/dronefly/core/menus/__init__.py index 15527fc..f8c8474 100644 --- a/dronefly/core/menus/__init__.py +++ b/dronefly/core/menus/__init__.py @@ -1,3 +1,4 @@ from .source import * # noqa: F401,F403 from .menu import * # noqa: F401,F403 from .taxon_list import * # noqa: F401,F403 +from .taxon import * # noqa: F401,F403 diff --git a/dronefly/core/menus/taxon.py b/dronefly/core/menus/taxon.py new file mode 100644 index 0000000..e4c89b7 --- /dev/null +++ b/dronefly/core/menus/taxon.py @@ -0,0 +1,31 @@ +from .source import ListPageSource +from ..formatters import TaxonFormatter +from ..formatters.constants import WWW_BASE_URL +from ..query import QueryResponse + + +class TaxonSource(ListPageSource): + def __init__(self, taxon_formatter: TaxonFormatter, with_ancestors: bool = True): + self._taxon_formatter = taxon_formatter + self._url = f"{WWW_BASE_URL}/taxon/{self.query_response.taxon.id}" + self.with_ancestors = with_ancestors + pages = [self.formatter.format(with_ancestors=with_ancestors)] + super().__init__(pages, per_page=1) + + def is_paginating(self): + return False + + @property + def formatter(self) -> TaxonFormatter: + return self._taxon_formatter + + @property + def query_response(self) -> QueryResponse: + return self.formatter.query_response + + def toggle_ancestors(self): + self.with_ancestors = not self.with_ancestors + self.entries[0] = self.format_page() + + def format_page(self): + return self.formatter.format(with_ancestors=self.with_ancestors)