Skip to content

Commit

Permalink
Initial version of taxon menu.
Browse files Browse the repository at this point in the history
  • Loading branch information
synrg committed Jan 12, 2025
1 parent 2e228d6 commit e6c9a11
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions dronefly/core/menus/__init__.py
Original file line number Diff line number Diff line change
@@ -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
31 changes: 31 additions & 0 deletions dronefly/core/menus/taxon.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit e6c9a11

Please sign in to comment.