From 94f2f0758a79f797233cfd7e7db241e3eca2e700 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Wed, 8 Feb 2023 23:22:17 +0100 Subject: add a short description to transformers --- fietsboek/templates/edit_form.jinja2 | 2 ++ fietsboek/transformers/__init__.py | 23 +++++++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/fietsboek/templates/edit_form.jinja2 b/fietsboek/templates/edit_form.jinja2 index 67c01c9..491db98 100644 --- a/fietsboek/templates/edit_form.jinja2 +++ b/fietsboek/templates/edit_form.jinja2 @@ -156,6 +156,8 @@
{% set params = track.transformer_params_for(transformer.identifier()) %} + +

{{ _(transformer.description()) }}

diff --git a/fietsboek/transformers/__init__.py b/fietsboek/transformers/__init__.py index b4ed532..1a9517e 100644 --- a/fietsboek/transformers/__init__.py +++ b/fietsboek/transformers/__init__.py @@ -11,6 +11,7 @@ function to load and apply transformers. from abc import ABC, abstractmethod from collections.abc import Mapping +from typing import TypeVar from gpxpy.gpx import GPX from markupsafe import Markup @@ -19,6 +20,8 @@ from pyramid.i18n import TranslationString _ = TranslationString +T = TypeVar("T", bound="Transformer") + class Parameters(BaseModel): """Parameters for a transformer. @@ -54,7 +57,7 @@ class Transformer(ABC): @classmethod @abstractmethod - def identifier(cls) -> str: + def identifier(cls: type[T]) -> str: """Returns a string identifier for this transformer. This identifier is used when serializing/deserializing the filters. @@ -64,7 +67,7 @@ class Transformer(ABC): @classmethod @abstractmethod - def name(cls) -> TranslationString: + def name(cls: type[T]) -> TranslationString: """The human-readable name of this transformer, as a translateable string. :return: The transformer's name. @@ -72,7 +75,15 @@ class Transformer(ABC): @classmethod @abstractmethod - def parameter_model(cls) -> type[Parameters]: + def description(cls: type[T]) -> TranslationString: + """A short description of what this transformer does. + + :return: The transformer's description. + """ + + @classmethod + @abstractmethod + def parameter_model(cls: type[T]) -> type[Parameters]: """Returns the parameter model that this transformer expects. :return: The parameter model class. @@ -114,7 +125,11 @@ class FixNullElevation(Transformer): @classmethod def name(cls) -> TranslationString: - return _("transformers.fix-null-elevation") + return _("transformers.fix-null-elevation.title") + + @classmethod + def description(cls) -> TranslationString: + return _("transformers.fix-null-elevation.description") @classmethod def parameter_model(cls) -> type[Parameters]: -- cgit v1.2.3