Skip to content

Commit 92fdc6b

Browse files
committed
Add voted_on, for the Elections documentation
1 parent cc9f0d3 commit 92fdc6b

File tree

5 files changed

+37
-16
lines changed

5 files changed

+37
-16
lines changed

docs/operations/elections.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ Volby do výboru probíhají asynchronně a zpravidla trvají týden, aby stihli
88
Kdy se volí
99
-----------
1010

11-
+------------------------------------+--------------------+
12-
| |:ballot_box:| Předchozí volba | |board_start| |
13-
+------------------------------------+--------------------+
14-
| |:warning:| Příští volba | |board_end| |
15-
+------------------------------------+--------------------+
11+
+------------------------------------+------------------------+
12+
| |:ballot_box:| Předchozí volba | |board_vote_date| |
13+
+------------------------------------+------------------------+
14+
| |:warning:| Příští volba | |next_board_vote_date| |
15+
+------------------------------------+------------------------+
1616

1717
Příprava
1818
--------

src/pyvec_docs/boards.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,17 @@ def is_treasurer(self) -> bool:
4040

4141
class Board(BaseModel):
4242
start_on: date | None = None
43+
voted_on: date
4344
members: list[BoardMember]
4445

4546
model_config = {"extra": "forbid", "frozen": True}
4647

48+
@classmethod
49+
def make(cls, voted_on=None, start_on=None, **kwargs):
50+
if voted_on is None:
51+
voted_on = start_on
52+
return cls(voted_on=voted_on, start_on=start_on, **kwargs)
53+
4754
@property
4855
def years(self) -> tuple[int, int] | tuple[None, None]:
4956
if self.start_on is None:
@@ -64,7 +71,7 @@ def load_boards(path: Path | str = BOARDS_CONFIG_PATH) -> list[Board]:
6471
"""Load all boards, including inactive ones"""
6572
data = tomllib.loads(Path(path).read_text())
6673
return sorted(
67-
(Board(**board) for board in data["board"]),
74+
(Board.make(**board) for board in data["board"]),
6875
key=attrgetter('sort_key'),
6976
reverse=True,
7077
)

src/pyvec_docs/boards.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@
44
#
55
# "start_on" should ideally be the date from justice.cz. If missing, the board
66
# doesn't officially have power yet.
7+
#
8+
# "voted_on" is the day when we voted for the board. If missing, defaults to
9+
# "start_on" as an approximation.
10+
711

812
[[board]]
13+
voted_on = "2025-05-07"
914

1015
[[board.members]]
1116
name = "Jakub Vysoký"

src/pyvec_docs/ext/board_dates.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,20 @@
44
from sphinx.application import Sphinx
55
from sphinx.config import Config
66

7-
from pyvec_docs.boards import BOARDS_MANDATE_LENGTH, load_current_board
7+
from pyvec_docs.boards import BOARDS_MANDATE_LENGTH, load_boards
88

99

1010
def board_dates(app: Sphinx, config: Config):
11-
board = load_current_board()
12-
assert board.start_on is not None
11+
board = load_boards()[0]
1312

14-
board_start = board.start_on
15-
board_end = board_start + timedelta(days=BOARDS_MANDATE_LENGTH * 365)
13+
last_vote = board.voted_on
14+
next_vote = last_vote + timedelta(days=BOARDS_MANDATE_LENGTH * 365)
1615

1716
existing_epilog = app.config.rst_epilog or ""
1817
app.config.rst_epilog = (
1918
f"{existing_epilog}\n\n"
20-
f".. |board_start| replace:: {board_start:%-d.%-m.%Y}\n"
21-
f".. |board_end| replace:: {board_end:%Y}\n"
19+
f".. |board_vote_date| replace:: {last_vote:%-d.%-m.%Y}\n"
20+
f".. |next_board_vote_date| replace:: {next_vote:%Y}\n"
2221
)
2322

2423

tests/test_scripts_generate_grants.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@
1414
@pytest.fixture
1515
def boards():
1616
return [ # sorted!
17-
Board(
17+
Board.make(
1818
**{
1919
# No start_on; votes don't count
20+
"voted_on": date(2023, 1, 1),
2021
"members": [
2122
{"name": "Bob", "github": "bobby"},
2223
],
2324
}
2425
),
25-
Board(
26+
Board.make(
2627
**{
2728
"start_on": date(2020, 1, 1),
2829
"members": [
@@ -31,9 +32,10 @@ def boards():
3132
],
3233
}
3334
),
34-
Board(
35+
Board.make(
3536
**{
3637
"start_on": date(2019, 1, 1),
38+
"voted_on": date(2018, 12, 1),
3739
"members": [
3840
{"name": "Bob", "github": "bobby"},
3941
],
@@ -46,6 +48,14 @@ def assert_boards_sorted(boards):
4648
assert boards == sorted(boards)
4749

4850

51+
def assert_voted_on_defaults(boards):
52+
assert [b.voted_on for b in boards] == [
53+
date(2023, 1, 1), # explicit
54+
date(2020, 1, 1), # from start_on
55+
date(2018, 12, 1), # explicit
56+
]
57+
58+
4959
def test_to_date():
5060
assert to_date("2020-02-12T13:22:01Z") == date(2020, 2, 12)
5161

0 commit comments

Comments
 (0)