ref: Extract both format variations from format method

This commit is contained in:
Marty Oehme 2025-06-09 12:18:20 +02:00
parent 39ba0f5508
commit 12fd3271fd
Signed by: Marty
GPG key ID: 4E535BC19C61886E

View file

@ -32,23 +32,33 @@ class BBTFormatter(papis.format.Formatter):
default: str | None = None,
) -> str:
if not fmt.startswith("bbt:"):
fallback_formatter = papis.config.getstring("default-formatter", OPTIONS_SECTION)
fallback_formatter = papis.config.getstring(
"default-formatter", OPTIONS_SECTION
)
return self.format_with_fallback(
fallback_formatter, fmt, doc, doc_key, additional, default
)
# NOTE sure would be nice to have a less hacky way of calling another formatter
return self.format_with_bbt(doc)
def format_with_fallback(
self,
fallback_formatter: str,
fmt: str,
doc: papis.document.DocumentLike,
doc_key: str,
additional: dict[str, Any] | None = None,
default: str | None = None,
) -> str:
_saved = papis.format.FORMATTER
papis.format.FORMATTER = None
fallback_formatted: str = papis.format.get_formatter(
fallback_formatter
).format(fmt, doc, doc_key, additional, default)
fallback_formatted: str = papis.format.get_formatter(fallback_formatter).format(
fmt, doc, doc_key, additional, default
)
papis.format.FORMATTER = _saved
return fallback_formatted
formatted = self.use_bbt(doc)
return formatted
def use_bbt(self, doc: papis.document.DocumentLike) -> str:
def format_with_bbt(self, doc: papis.document.DocumentLike) -> str:
author_unfmt = (
doc["author_list"][0]["family"]
if "author_list" in doc