|
10 | 10 | import shutil |
11 | 11 | from abc import abstractmethod |
12 | 12 | from dataclasses import dataclass |
| 13 | +from dataclasses import fields |
13 | 14 | from functools import wraps |
14 | 15 | from http import HTTPStatus |
15 | 16 | from inspect import Parameter |
16 | 17 | from inspect import signature |
17 | 18 | from pathlib import Path |
| 19 | +from pprint import pformat |
18 | 20 | from typing import Any |
19 | 21 | from typing import Callable |
20 | 22 | from typing import TYPE_CHECKING |
@@ -504,6 +506,32 @@ def get_documents() -> Sequence[Document]: |
504 | 506 | ] |
505 | 507 |
|
506 | 508 |
|
| 509 | +@dataclass(frozen=True) |
| 510 | +class Options: |
| 511 | + """Fava and Beancount options as strings.""" |
| 512 | + |
| 513 | + fava_options: Mapping[str, str] |
| 514 | + beancount_options: Mapping[str, str] |
| 515 | + |
| 516 | + |
| 517 | +@api_endpoint |
| 518 | +def get_options() -> Options: |
| 519 | + """Get all options, rendered to strings for displaying in the frontend.""" |
| 520 | + g.ledger.changed() |
| 521 | + |
| 522 | + fava_options = g.ledger.fava_options |
| 523 | + pprinted_fava_options = { |
| 524 | + field.name.replace("_", "-"): pformat( |
| 525 | + getattr(fava_options, field.name) |
| 526 | + ) |
| 527 | + for field in fields(fava_options) |
| 528 | + } |
| 529 | + return Options( |
| 530 | + pprinted_fava_options, |
| 531 | + {key: str(value) for key, value in g.ledger.options.items()}, |
| 532 | + ) |
| 533 | + |
| 534 | + |
507 | 535 | @dataclass(frozen=True) |
508 | 536 | class CommodityPairWithPrices: |
509 | 537 | """A pair of commodities and prices for them.""" |
|
0 commit comments